Skip to content

Commit a6f885b

Browse files
committed
More coverage
1 parent 5b23ec1 commit a6f885b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/cattrs/v/_fluent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def customize(
217217
detailed_validation = converter.detailed_validation
218218
for field in fields:
219219
if field.attr.name in seen:
220-
raise Exception(f"Duplicate customization for field {field.attr.name}")
220+
raise TypeError(f"Duplicate customization for field {field.attr.name}")
221221
if field.attr is not getattr(f(cl), field.attr.name):
222222
raise TypeError(f"Customizing {cl}, but {field} is from a different class")
223223
seen.add(field.attr.name)

tests/v/test_fluent.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,27 @@ def test_multiple_field_validators(c: Converter) -> None:
189189
instance.a = 6
190190
instance.b = "a"
191191
assert instance == c.structure(c.unstructure(instance), Model)
192+
193+
194+
def test_multiple_fields_error(c: Converter):
195+
"""Customizing the same field twice is a runtime error."""
196+
197+
fs = f(Model)
198+
199+
with raises(TypeError):
200+
customize(
201+
c, Model, V(fs.a).ensure(greater_than(5)), V(fs.a).ensure(greater_than(5))
202+
)
203+
204+
205+
def test_different_classes_error(c: Converter):
206+
"""Customizing the field of a different class is a runtime error."""
207+
208+
@define
209+
class AnotherModel:
210+
a: int
211+
212+
fs = f(Model)
213+
214+
with raises(TypeError):
215+
customize(c, AnotherModel, V(fs.a).ensure(greater_than(5)))

0 commit comments

Comments
 (0)