Skip to content

Commit 8a0d27e

Browse files
author
iron3oxide
committed
test(tests for _InValidator): Add tests for call with "verbose_value_error=True"
This should sufficiently test the verbose signature.
1 parent 32cc097 commit 8a0d27e

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

tests/test_validators.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,19 @@ def test_fail(self):
469469
"""
470470
v = in_([1, 2, 3])
471471
a = simple_attr("test")
472+
with pytest.raises(ValueError) as e:
473+
v(None, a, None)
474+
assert (
475+
"'test' must be in [1, 2, 3] (got None)",
476+
) == e.value.args
477+
478+
def test_fail_verbose(self):
479+
"""
480+
Raise verbose ValueError if the value is outside our options
481+
and verbose_value_error is set to True.
482+
"""
483+
v = in_([1, 2, 3], verbose_value_error=True)
484+
a = simple_attr("test")
472485
with pytest.raises(ValueError) as e:
473486
v(None, a, None)
474487
assert (
@@ -485,6 +498,20 @@ def test_fail_with_string(self):
485498
"""
486499
v = in_("abc")
487500
a = simple_attr("test")
501+
with pytest.raises(ValueError) as e:
502+
v(None, a, None)
503+
assert (
504+
"'test' must be in 'abc' (got None)",
505+
) == e.value.args
506+
507+
def test_fail_with_string_verbose(self):
508+
"""
509+
Raise verbose ValueError if the value is outside our options when
510+
the options are specified as a string, verbose_value_error is set
511+
to True and the value is not a string.
512+
"""
513+
v = in_("abc", verbose_value_error=True)
514+
a = simple_attr("test")
488515
with pytest.raises(ValueError) as e:
489516
v(None, a, None)
490517
assert (

0 commit comments

Comments
 (0)