def test_validate_values_error( val: str, constraint: ListConstraints, expected: Exception ): with pytest.raises(expected): constraint.validate(val)
TupleConstraints, StrConstraints, IntContraints, ConstraintValueError, ) @dataclasses.dataclass class Foo: bar: str = "bar" @pytest.mark.parametrize( argnames=("val", "constraint", "expected"), argvalues=[ ([], ListConstraints(), []), ([1], ListConstraints(min_items=1), [1]), ([1, 2], ListConstraints(max_items=2), [1, 2]), ([1, 2, 2], ListConstraints(unique=True), [1, 2]), ([Foo(), Foo(), 2], ListConstraints(unique=True), [Foo(), 2]), (collections.deque(), DequeConstraints(), collections.deque()), ({1, 2}, SetContraints(max_items=2), {1, 2}), (frozenset([1, 2]), FrozenSetConstraints(), frozenset([1, 2])), ], ) def test_validate_values(val: str, constraint: ListConstraints, expected: list): assert constraint.validate(val) == expected @pytest.mark.parametrize( argnames=("val", "constraint", "expected"),