Skip to content

Commit a7b86a1

Browse files
author
Rebecca Turner
committed
Add to_bool tests
1 parent a85ab29 commit a7b86a1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test_converters.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,28 @@ class C(object):
134134

135135
c = C()
136136
assert True is c.a1 is c.a2
137+
138+
139+
class TestToBool(object):
140+
def test_unhashable(self):
141+
"""
142+
Fails if value is unhashable.
143+
"""
144+
with pytest.raises(ValueError, match="Cannot convert value to bool"):
145+
to_bool([])
146+
147+
def test_truthy(self):
148+
"""
149+
Fails if truthy values are incorrectly converted.
150+
"""
151+
assert to_bool("t")
152+
assert to_bool("yes")
153+
assert to_bool("on")
154+
155+
def test_falsy(self):
156+
"""
157+
Fails if falsy values are incorrectly converted.
158+
"""
159+
assert not to_bool("f")
160+
assert not to_bool("no")
161+
assert not to_bool("off")

0 commit comments

Comments
 (0)