Skip to content

Commit

Permalink
test(tests for _InValidator): Add tests for call with "verbose_value_…
Browse files Browse the repository at this point in the history
…error=True"

This should sufficiently test the verbose signature.
  • Loading branch information
iron3oxide committed Apr 12, 2022
1 parent 32cc097 commit 8a0d27e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,19 @@ def test_fail(self):
"""
v = in_([1, 2, 3])
a = simple_attr("test")
with pytest.raises(ValueError) as e:
v(None, a, None)
assert (
"'test' must be in [1, 2, 3] (got None)",
) == e.value.args

def test_fail_verbose(self):
"""
Raise verbose ValueError if the value is outside our options
and verbose_value_error is set to True.
"""
v = in_([1, 2, 3], verbose_value_error=True)
a = simple_attr("test")
with pytest.raises(ValueError) as e:
v(None, a, None)
assert (
Expand All @@ -485,6 +498,20 @@ def test_fail_with_string(self):
"""
v = in_("abc")
a = simple_attr("test")
with pytest.raises(ValueError) as e:
v(None, a, None)
assert (
"'test' must be in 'abc' (got None)",
) == e.value.args

def test_fail_with_string_verbose(self):
"""
Raise verbose ValueError if the value is outside our options when
the options are specified as a string, verbose_value_error is set
to True and the value is not a string.
"""
v = in_("abc", verbose_value_error=True)
a = simple_attr("test")
with pytest.raises(ValueError) as e:
v(None, a, None)
assert (
Expand Down

0 comments on commit 8a0d27e

Please sign in to comment.