From 89bcbd875c7e8aeb3e423fbd5d426991c954af56 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Fri, 6 Aug 2021 09:45:06 -0400 Subject: [PATCH] Add to_bool tests --- tests/test_converters.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_converters.py b/tests/test_converters.py index e6e5a3e95..c1a6122ce 100644 --- a/tests/test_converters.py +++ b/tests/test_converters.py @@ -134,3 +134,29 @@ class C(object): c = C() assert True is c.a1 is c.a2 + +class TestToBool(object): + def test_unhashable(self): + """ + Fails if value is unhashable. + """ + with pytest.raises(ValueError, match="Cannot convert value to bool"): + to_bool([]) + + + def test_truthy(self): + """ + Fails if truthy values are incorrectly converted. + """ + assert to_bool("t") + assert to_bool("yes") + assert to_bool("on") + + def test_falsy(self): + """ + Fails if falsy values are incorrectly converted. + """ + assert not to_bool("f") + assert not to_bool("no") + assert not to_bool("off") +