Skip to content

Commit

Permalink
✅ fix tests for validator
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Jan 31, 2025
1 parent d8247fd commit b5d1ab9
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tests/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def test_validator_before(cls, v: Any) -> Any:
v = str(v)
return v

assert TestModel(foo=1, bar="test").foo == 1
assert TestModel(foo=1, bar=123).bar == "123"
assert type_validate_python(TestModel, {"foo": 1, "bar": "test"}).foo == 1
assert type_validate_python(TestModel, {"foo": 1, "bar": 123}).bar == "123"

with pytest.raises(ValidationError):
TestModel(foo=0, bar="test")
Expand Down Expand Up @@ -95,9 +95,11 @@ def test_validator_before(cls, data: Any) -> Any:
return data

@model_validator(mode="after")
def test_validator_after(self):
if self.bar == "test":
@classmethod
def test_validator_after(cls, data: Any) -> Any:
if data.bar == "test":
raise ValueError("bar should not be test")
return data

assert type_validate_python(TestModel, {"bar": "aaa"}).foo == 1

Expand Down

0 comments on commit b5d1ab9

Please sign in to comment.