Skip to content

Commit 9d2ba6f

Browse files
committed
Supporting Python 2.6
1 parent b846cf3 commit 9d2ba6f

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

source_py2/test_python_toolbox/test_nifty_collections/test_bagging.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,21 @@ class BaseBagTestCase(cute_testing.TestCase):
3030
__metaclass__ = abc.ABCMeta
3131
__test__ = False
3232
def test_common(self):
33+
try:
34+
from collections import Counter
35+
except ImportError:
36+
# Python 2.6
37+
from python_toolbox.third_party.collections import Counter
3338
bag = self.bag_type('abracadabra')
3439
if not issubclass(self.bag_type, nifty_collections.Ordered):
35-
assert bag == collections.Counter('abracadabra') == \
36-
collections.Counter(bag) == \
37-
self.bag_type(collections.Counter('abracadabra'))
40+
assert bag == Counter('abracadabra') == Counter(bag) == \
41+
self.bag_type(Counter('abracadabra'))
3842

3943
assert len(bag) == 5
4044
assert set(bag) == set(bag.keys()) == set('abracadabra')
41-
assert set(bag.values()) == {1, 2, 5}
45+
assert set(bag.values()) == set((1, 2, 5))
4246
assert set(bag.items()) == \
43-
{('a', 5), ('r', 2), ('b', 2), ('c', 1), ('d', 1)}
47+
set((('a', 5), ('r', 2), ('b', 2), ('c', 1), ('d', 1)))
4448
assert bag['a'] == 5
4549
assert bag['missing value'] == 0
4650
assert len(bag) == 5
@@ -52,8 +56,8 @@ def test_common(self):
5256
assert bag != 7
5357

5458
assert set(bag.most_common()) == set(bag.most_common(len(bag))) == \
55-
set(collections.Counter(bag).most_common()) == \
56-
set(collections.Counter(bag.elements).most_common())
59+
set(Counter(bag).most_common()) == \
60+
set(Counter(bag.elements).most_common())
5761

5862
assert bag.most_common(1) == (('a', 5),)
5963
assert set(bag.most_common(3)) == set((('a', 5), ('b', 2), ('r', 2)))
@@ -224,15 +228,15 @@ def test_ignores_zero(self):
224228

225229
if issubclass(self.bag_type, collections.Hashable):
226230
assert hash(bag_0) == hash(bag_1)
227-
assert {bag_0, bag_1} == {bag_0} == {bag_1}
231+
assert set((bag_0, bag_1)) == set((bag_0,)) == set((bag_0,))
228232

229233
bag_2 = \
230234
self.bag_type({'a': 0.0, 'b': 2, 'c': decimal_module.Decimal('0.0'),})
231235
bag_3 = self.bag_type('bb')
232236

233237
if issubclass(self.bag_type, collections.Hashable):
234238
assert hash(bag_2) == hash(bag_3)
235-
assert {bag_2, bag_3} == {bag_2} == {bag_3}
239+
assert set((bag_2, bag_3)) == set((bag_2,)) == set((bag_3,))
236240

237241
def test_copy(self):
238242
class O: pass
@@ -433,7 +437,7 @@ def test_hash(self):
433437
assert not isinstance(bag, collections.Hashable)
434438
assert not issubclass(self.bag_type, collections.Hashable)
435439
with cute_testing.RaiseAssertor(TypeError):
436-
{bag}
440+
set((bag,))
437441
with cute_testing.RaiseAssertor(TypeError):
438442
{bag: None,}
439443
with cute_testing.RaiseAssertor(TypeError):
@@ -563,7 +567,7 @@ def test_mutating(self):
563567
other_key, other_value = bag.popitem()
564568
assert other_key in 'abracadabra'
565569
assert bag == self.bag_type([c for c in 'abracadabra'
566-
if c not in {key, other_key}])
570+
if c not in set((key, other_key))])
567571
assert bag is bag_reference
568572
if isinstance(bag, nifty_collections.Ordered):
569573
assert key == 'd'
@@ -616,7 +620,7 @@ def test_hash(self):
616620
bag = self.bag_type('abracadabra')
617621
assert isinstance(bag, collections.Hashable)
618622
assert issubclass(self.bag_type, collections.Hashable)
619-
assert {bag, bag} == {bag}
623+
assert set((bag, bag)) == set((bag,))
620624
assert {bag: bag} == {bag: bag}
621625
assert isinstance(hash(bag), int)
622626

source_py2/test_python_toolbox/test_nifty_collections/test_frozen_dict.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ def test():
1919
assert len(frozen_dict) == 3
2020
assert set(frozen_dict) == set(frozen_dict.keys()) == set('123')
2121
assert set(frozen_dict.values()) == set('abc')
22-
assert set(frozen_dict.items()) == {('1', 'a'), ('2', 'b'), ('3', 'c'),}
22+
assert set(frozen_dict.items()) == set((('1', 'a'), ('2', 'b'),
23+
('3', 'c'),))
2324
assert frozen_dict['1'] == 'a'
2425
with cute_testing.RaiseAssertor(exception_type=LookupError):
2526
frozen_dict['missing value']
26-
assert {frozen_dict, frozen_dict} == {frozen_dict}
27+
assert set((frozen_dict, frozen_dict)) == set((frozen_dict,))
2728
assert {frozen_dict: frozen_dict} == {frozen_dict: frozen_dict}
2829
assert isinstance(hash(frozen_dict), int)
2930

0 commit comments

Comments
 (0)