Skip to content

Commit e5e3795

Browse files
authored
Merge pull request #9 from deanagan/master
Fixed some boolean functions not returning check_obj and added unit tests
2 parents 612c048 + 4f4e11c commit e5e3795

File tree

2 files changed

+146
-8
lines changed

2 files changed

+146
-8
lines changed

fluentcheck/assertions/booleans.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,27 @@ def is_falsy(check_obj):
3434

3535

3636
def is_not_truthy(check_obj):
37-
check_obj.is_falsy()
37+
return check_obj.is_falsy()
3838

3939

4040
def is_not_falsy(check_obj):
41-
check_obj.is_truthy()
41+
return check_obj.is_truthy()
4242

4343

4444
def is_true(check_obj):
45-
check_obj.is_boolean()
46-
check_obj.is_truthy()
45+
return check_obj.is_truthy().is_boolean()
4746

4847

4948
def is_false(check_obj):
50-
check_obj.is_boolean()
51-
check_obj.is_falsy()
49+
return check_obj.is_falsy().is_boolean()
5250

5351

5452
def is_not_true(check_obj):
55-
check_obj.is_false()
53+
return check_obj.is_false()
5654

5755

5856
def is_not_false(check_obj):
59-
check_obj.is_true()
57+
return check_obj.is_true()
6058

6159

6260
def has_same_truth_of(check_obj, value):

fluentcheck/tests/test_booleans.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import unittest
2+
from fluentcheck.check import Check, CheckError
3+
4+
5+
class BooleanObject:
6+
def __init__(self, is_true):
7+
self.is_true = is_true
8+
def __bool__(self):
9+
return self.is_true
10+
11+
12+
class BooleanByLengthObject:
13+
14+
def __init__(self, items = None):
15+
self.items = [] if items is None else items
16+
def __len__(self):
17+
return len(self.items)
18+
19+
20+
class TestBooleansAssertions(unittest.TestCase):
21+
22+
def setUp(self):
23+
self.falsy_values = ([], (), {}, set(), "", '',
24+
range(0), 0, 0.0, 0j, None, False,
25+
BooleanObject(False), BooleanByLengthObject())
26+
self.truthy_values = ([1,], ('a',), {1:'one'}, set([1,1,]), "1", '2',
27+
range(1), 1, 1.0, 1j, not None, True,
28+
BooleanObject(True), BooleanByLengthObject([1,2]))
29+
30+
def test_is_boolean(self):
31+
res = Check(1 == 2).is_boolean()
32+
self.assertIsInstance(res, Check)
33+
try:
34+
Check(1).is_boolean()
35+
self.fail()
36+
except CheckError:
37+
pass
38+
39+
def test_is_not_boolean(self):
40+
res = Check(1).is_not_boolean()
41+
self.assertIsInstance(res, Check)
42+
try:
43+
Check(1 == 2).is_not_boolean()
44+
self.fail()
45+
except CheckError:
46+
pass
47+
48+
def test_is_true(self):
49+
res = Check(1 == 1).is_true()
50+
self.assertIsInstance(res, Check)
51+
try:
52+
Check(1 == 2).is_true()
53+
self.fail()
54+
except CheckError:
55+
pass
56+
57+
def test_is_not_true(self):
58+
res = Check(1 == 2).is_not_true()
59+
self.assertIsInstance(res, Check)
60+
try:
61+
Check(1 == 1).is_not_true()
62+
self.fail()
63+
except CheckError:
64+
pass
65+
66+
def test_is_false(self):
67+
res = Check(1 == 2).is_false()
68+
self.assertIsInstance(res, Check)
69+
try:
70+
Check(1 == 1).is_false()
71+
self.fail()
72+
except CheckError:
73+
pass
74+
75+
def test_is_not_false(self):
76+
res = Check(1 == 1).is_not_false()
77+
self.assertIsInstance(res, Check)
78+
try:
79+
Check(1 == 2).is_not_false()
80+
self.fail()
81+
except CheckError:
82+
pass
83+
84+
def test_is_falsy(self):
85+
for item in self.falsy_values:
86+
res = Check(item).is_falsy()
87+
self.assertIsInstance(res, Check)
88+
try:
89+
Check(not item).is_falsy()
90+
self.fail()
91+
except CheckError:
92+
pass
93+
94+
def test_is_not_falsy(self):
95+
for item in self.falsy_values:
96+
res = Check(not item).is_not_falsy()
97+
self.assertIsInstance(res, Check)
98+
try:
99+
Check(item).is_not_falsy()
100+
self.fail()
101+
except CheckError:
102+
pass
103+
104+
def test_is_truthy(self):
105+
for item in self.truthy_values:
106+
res = Check(item).is_truthy()
107+
self.assertIsInstance(res, Check)
108+
try:
109+
Check(not item).is_truthy()
110+
self.fail()
111+
except CheckError:
112+
pass
113+
114+
def test_is_not_truthy(self):
115+
for item in self.truthy_values:
116+
res = Check(not item).is_not_truthy()
117+
self.assertIsInstance(res, Check)
118+
try:
119+
Check(item).is_not_truthy()
120+
self.fail()
121+
except CheckError:
122+
pass
123+
124+
def test_has_same_truth_of(self):
125+
res = Check(BooleanObject(True)).has_same_truth_of(BooleanByLengthObject([1,2]))
126+
self.assertIsInstance(res, Check)
127+
try:
128+
Check(BooleanObject(False)).has_same_truth_of(BooleanByLengthObject([1,2]))
129+
self.fail()
130+
except CheckError:
131+
pass
132+
133+
def test_has_opposite_truth_of(self):
134+
res = Check(BooleanObject(False)).has_opposite_truth_of(BooleanByLengthObject([1,]))
135+
self.assertIsInstance(res, Check)
136+
try:
137+
Check(BooleanObject(False)).has_opposite_truth_of(BooleanByLengthObject())
138+
self.fail()
139+
except CheckError:
140+
pass

0 commit comments

Comments
 (0)