From 8a0d27e87ad3493ddf694df7a2e2e608ff40f2bc Mon Sep 17 00:00:00 2001 From: iron3oxide Date: Tue, 12 Apr 2022 15:56:09 +0200 Subject: [PATCH] test(tests for _InValidator): Add tests for call with "verbose_value_error=True" This should sufficiently test the verbose signature. --- tests/test_validators.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/test_validators.py b/tests/test_validators.py index 3bec62b03..2132a43ca 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -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 ( @@ -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 (