Skip to content

Commit b7d1eff

Browse files
committed
-
1 parent 24a0adb commit b7d1eff

File tree

1 file changed

+45
-35
lines changed

1 file changed

+45
-35
lines changed

source_py3/test_python_toolbox/test_nifty_collections/test_tallying.py

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@ def _check_common(tally_type):
108108
assert tally_type({'a': 0, 'b': 1,}) == \
109109
tally_type({'c': 0, 'b': 1,})
110110

111+
111112
@_test_on(Tally, OrderedTally, FrozenTally, FrozenOrderedTally)
112-
def _check_comparison(frozen_tally_type):
113-
tally_0 = frozen_tally_type('c')
114-
tally_1 = frozen_tally_type('abc')
115-
tally_2 = frozen_tally_type('aabc')
116-
tally_3 = frozen_tally_type('abbc')
117-
tally_4 = frozen_tally_type('aabbcc')
113+
def _check_comparison(tally_type):
114+
tally_0 = tally_type('c')
115+
tally_1 = tally_type('abc')
116+
tally_2 = tally_type('aabc')
117+
tally_3 = tally_type('abbc')
118+
tally_4 = tally_type('aabbcc')
119+
not_a_tally = {}
118120

119121
hierarchy = (
120122
(tally_4, {tally_3, tally_2, tally_1, tally_0}),
@@ -125,7 +127,7 @@ def _check_comparison(frozen_tally_type):
125127
)
126128

127129
for item, smaller_items in hierarchy:
128-
if not isinstance(item, frozen_tally_type):
130+
if not isinstance(item, tally_type):
129131
continue
130132
for smaller_item in smaller_items:
131133
assert not item <= smaller_item
@@ -137,29 +139,46 @@ def _check_comparison(frozen_tally_type):
137139
item not in smaller_item]
138140
for not_smaller_item in not_smaller_items:
139141
assert not item < smaller_item
142+
143+
with cute_testing.RaiseAssertor(TypeError):
144+
item <= not_a_tally
145+
with cute_testing.RaiseAssertor(TypeError):
146+
item < not_a_tally
147+
with cute_testing.RaiseAssertor(TypeError):
148+
item > not_a_tally
149+
with cute_testing.RaiseAssertor(TypeError):
150+
item >= not_a_tally
151+
with cute_testing.RaiseAssertor(TypeError):
152+
not_a_tally <= item
153+
with cute_testing.RaiseAssertor(TypeError):
154+
not_a_tally < item
155+
with cute_testing.RaiseAssertor(TypeError):
156+
not_a_tally > item
157+
with cute_testing.RaiseAssertor(TypeError):
158+
not_a_tally >= item
140159

141160
@_test_on(Tally, OrderedTally, FrozenTally, FrozenOrderedTally)
142-
def _check_ignores_zero(frozen_tally_type):
143-
frozen_tally_0 = frozen_tally_type({'a': 0,})
144-
frozen_tally_1 = frozen_tally_type()
161+
def _check_ignores_zero(tally_type):
162+
frozen_tally_0 = tally_type({'a': 0,})
163+
frozen_tally_1 = tally_type()
145164
assert frozen_tally_0 == frozen_tally_1
146165

147166
assert hash(frozen_tally_0) == hash(frozen_tally_1)
148167
assert {frozen_tally_0, frozen_tally_1} == {frozen_tally_0} == \
149168
{frozen_tally_1}
150169

151-
frozen_tally_2 = frozen_tally_type(
170+
frozen_tally_2 = tally_type(
152171
{'a': 0.0, 'b': 2, 'c': decimal_module.Decimal('0.0'),})
153-
frozen_tally_3 = frozen_tally_type('bb')
172+
frozen_tally_3 = tally_type('bb')
154173

155174
assert hash(frozen_tally_2) == hash(frozen_tally_3)
156175
assert {frozen_tally_2, frozen_tally_3} == {frozen_tally_2} == \
157176
{frozen_tally_3}
158177

159178

160179
@_test_on(Tally, OrderedTally, FrozenTally, FrozenOrderedTally)
161-
def _check_immutable(frozen_tally_type):
162-
frozen_tally = frozen_tally_type('abracadabra')
180+
def _check_mutating(tally_type):
181+
frozen_tally = tally_type('abracadabra')
163182
with cute_testing.RaiseAssertor(TypeError):
164183
frozen_tally['a'] += 1
165184
with cute_testing.RaiseAssertor(TypeError):
@@ -168,40 +187,31 @@ def _check_immutable(frozen_tally_type):
168187
frozen_tally['a'] = 7
169188

170189

171-
@_test_on(Tally, OrderedTally, FrozenTally, FrozenOrderedTally)
172-
def _check_immutable(frozen_tally_type):
173-
frozen_tally = frozen_tally_type('abracadabra')
174-
with cute_testing.RaiseAssertor(TypeError):
175-
frozen_tally['a'] += 1
176-
with cute_testing.RaiseAssertor(TypeError):
177-
frozen_tally['a'] -= 1
178-
with cute_testing.RaiseAssertor(TypeError):
179-
frozen_tally['a'] = 7
180190

181191
@_test_on(Tally, OrderedTally, FrozenTally, FrozenOrderedTally)
182-
def _check_only_positive_ints_or_zero(frozen_tally_type):
183-
assert frozen_tally_type(
192+
def _check_only_positive_ints_or_zero(tally_type):
193+
assert tally_type(
184194
OrderedDict([('a', 0), ('b', 0.0), ('c', 1), ('d', 2.0),
185195
('e', decimal_module.Decimal('3.0'))])) == \
186-
frozen_tally_type('cddeee')
196+
tally_type('cddeee')
187197
with cute_testing.RaiseAssertor(TypeError):
188-
frozen_tally_type({'a': 1.1,})
198+
tally_type({'a': 1.1,})
189199
with cute_testing.RaiseAssertor(TypeError):
190-
frozen_tally_type({'a': -2,})
200+
tally_type({'a': -2,})
191201
with cute_testing.RaiseAssertor(TypeError):
192-
frozen_tally_type({'a': -3,})
202+
tally_type({'a': -3,})
193203
with cute_testing.RaiseAssertor(TypeError):
194-
frozen_tally_type({'a': decimal_module.Decimal('-3'),})
204+
tally_type({'a': decimal_module.Decimal('-3'),})
195205
with cute_testing.RaiseAssertor(TypeError):
196-
frozen_tally_type({'a': infinity,})
206+
tally_type({'a': infinity,})
197207
with cute_testing.RaiseAssertor(TypeError):
198-
frozen_tally_type({'a': -infinity,})
208+
tally_type({'a': -infinity,})
199209
with cute_testing.RaiseAssertor(TypeError):
200-
frozen_tally_type({'a': 'whatever',})
210+
tally_type({'a': 'whatever',})
201211
with cute_testing.RaiseAssertor(TypeError):
202-
frozen_tally_type({'a': b'whateva',})
212+
tally_type({'a': b'whateva',})
203213
with cute_testing.RaiseAssertor(TypeError):
204-
frozen_tally_type({'a': ('still', 'nope'),})
214+
tally_type({'a': ('still', 'nope'),})
205215

206216

207217

0 commit comments

Comments
 (0)