| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 | import pytestfrom pydantic import ValidationErrorfrom pydantic import validatorfrom clean_python import BadRequestfrom clean_python import ValueObjectclass Color(ValueObject):    name: str    @validator("name")    def name_not_empty(cls, v):        assert v != ""        return v@pytest.fixturedef color():    return Color(name="green")def test_validator():    with pytest.raises(ValidationError) as e:        Color(name="")    assert e.type is ValidationError  # not BadRequestdef test_create_err():    with pytest.raises(BadRequest):        Color.create(name="")def test_update(color):    updated = color.update(name="red")    assert color.name == "green"    assert updated.name == "red"def test_update_validates(color):    with pytest.raises(BadRequest):        color.update(name="")def test_run_validation(color):    assert color.run_validation() == colordef test_run_validation_err():    color = Color.construct(name="")    with pytest.raises(BadRequest):        color.run_validation()def test_hashable(color):    assert len({color, color}) == 1def test_eq(color):    assert color == colordef test_neq(color):    assert color != Color(name="red")
 |