Skip to content

Commit 26a3898

Browse files
committed
-
1 parent b7d1eff commit 26a3898

File tree

2 files changed

+61
-20
lines changed

2 files changed

+61
-20
lines changed

source_py3/python_toolbox/cute_testing.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
'''This module defines tools for testing.'''
55

6+
import nose
7+
68
from python_toolbox.third_party import unittest2
79

810
from python_toolbox import cute_inspect
@@ -11,6 +13,7 @@
1113
from python_toolbox import logic_tools
1214

1315

16+
1417
class Failure(CuteException, AssertionError):
1518
'''A test has failed.'''
1619

@@ -134,4 +137,8 @@ def assert_polite_wrapper(wrapper, wrapped=None, same_signature=True):
134137
assert (getattr(wrapper, attribute, None) or _MissingAttribute) == \
135138
(getattr(wrapped, attribute, None) or _MissingAttribute)
136139
assert wrapper.__wrapped__ == wrapped
137-
140+
141+
142+
class TestCase(nose.case.Test):
143+
pass
144+

source_py3/test_python_toolbox/test_nifty_collections/test_tallying.py

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import collections
99
import decimal as decimal_module
1010

11+
import nose
12+
1113
from python_toolbox import cute_iter_tools
1214
from python_toolbox import sequence_tools
1315
from python_toolbox import cute_testing
@@ -20,6 +22,38 @@
2022
infinity = float('inf')
2123
infinities = (infinity, -infinity)
2224

25+
class BaseTallyTestCase(cute_testing.TestCase):
26+
pass
27+
28+
class BaseMutableTallyTestCase(BaseTallyTestCase):
29+
is_frozen = False
30+
31+
class BaseFrozenTallyTestCase(BaseTallyTestCase):
32+
is_frozen = True
33+
34+
class BaseOrderedTallyTestCase(BaseTallyTestCase):
35+
is_ordered = True
36+
37+
class BaseUnorderedTallyTestCase(BaseTallyTestCase):
38+
is_ordered = False
39+
40+
41+
class TallyTestCase(BaseMutableTallyTestCase, BaseUnorderedTallyTestCase):
42+
tally_type = Tally
43+
44+
class OrderedTallyTestCase(BaseMutableTallyTestCase,
45+
BaseOrderedTallyTestCase):
46+
tally_type = OrderedTally
47+
48+
class FrozenTallyTestCase(BaseFrozenTallyTestCase, BaseUnorderedTallyTestCase):
49+
tally_type = FrozenTally
50+
51+
class OrderedTallyTestCase(BaseFrozenTallyTestCase,
52+
BaseOrderedTallyTestCase):
53+
tally_type = FrozenOrderedTally
54+
55+
56+
2357
_check_functions = []
2458
def _test_on(arguments):
2559
def decorator(check_function):
@@ -159,32 +193,32 @@ def _check_comparison(tally_type):
159193

160194
@_test_on(Tally, OrderedTally, FrozenTally, FrozenOrderedTally)
161195
def _check_ignores_zero(tally_type):
162-
frozen_tally_0 = tally_type({'a': 0,})
163-
frozen_tally_1 = tally_type()
164-
assert frozen_tally_0 == frozen_tally_1
196+
tally_0 = tally_type({'a': 0,})
197+
tally_1 = tally_type()
198+
assert tally_0 == tally_1
165199

166-
assert hash(frozen_tally_0) == hash(frozen_tally_1)
167-
assert {frozen_tally_0, frozen_tally_1} == {frozen_tally_0} == \
168-
{frozen_tally_1}
200+
if tally_type.is_frozen:
201+
assert hash(tally_0) == hash(tally_1)
202+
assert {tally_0, tally_1} == {tally_0} == {tally_1}
169203

170-
frozen_tally_2 = tally_type(
204+
tally_2 = tally_type(
171205
{'a': 0.0, 'b': 2, 'c': decimal_module.Decimal('0.0'),})
172-
frozen_tally_3 = tally_type('bb')
206+
tally_3 = tally_type('bb')
173207

174-
assert hash(frozen_tally_2) == hash(frozen_tally_3)
175-
assert {frozen_tally_2, frozen_tally_3} == {frozen_tally_2} == \
176-
{frozen_tally_3}
208+
if tally_type.is_frozen:
209+
assert hash(tally_2) == hash(tally_3)
210+
assert {tally_2, tally_3} == {tally_2} == {tally_3}
177211

178212

179213
@_test_on(Tally, OrderedTally, FrozenTally, FrozenOrderedTally)
180214
def _check_mutating(tally_type):
181-
frozen_tally = tally_type('abracadabra')
215+
tally = tally_type('abracadabra')
182216
with cute_testing.RaiseAssertor(TypeError):
183-
frozen_tally['a'] += 1
217+
tally['a'] += 1
184218
with cute_testing.RaiseAssertor(TypeError):
185-
frozen_tally['a'] -= 1
219+
tally['a'] -= 1
186220
with cute_testing.RaiseAssertor(TypeError):
187-
frozen_tally['a'] = 7
221+
tally['a'] = 7
188222

189223

190224

@@ -217,10 +251,10 @@ def _check_only_positive_ints_or_zero(tally_type):
217251

218252
@_test_on(Tally, OrderedTally, FrozenTally, FrozenOrderedTally)
219253
def _check_ordered():
220-
frozen_tally_0 = FrozenTally('ababb')
221-
frozen_tally_1 = FrozenTally('bbbaa')
222-
assert frozen_tally_0 == frozen_tally_1
223-
assert hash(frozen_tally_0) == hash(frozen_tally_1)
254+
tally_0 = FrozenTally('ababb')
255+
tally_1 = FrozenTally('bbbaa')
256+
assert tally_0 == tally_1
257+
assert hash(tally_0) == hash(tally_1)
224258

225259
frozen_ordered_tally_0 = FrozenOrderedTally('ababb')
226260
frozen_ordered_tally_1 = FrozenOrderedTally('bbbaa')

0 commit comments

Comments
 (0)