diff options
author | Adrien Di Mascio <adim@logilab.fr> | 2006-05-12 12:08:14 +0200 |
---|---|---|
committer | Adrien Di Mascio <adim@logilab.fr> | 2006-05-12 12:08:14 +0200 |
commit | eadb484b37099fdf68d7fb6022c54bebd0a2b114 (patch) | |
tree | f7c39913e315d254449c78382837400a38a957c9 /test | |
parent | a074e3077f46b7ab88ea7c591a7280669f39bfc5 (diff) | |
download | logilab-common-eadb484b37099fdf68d7fb6022c54bebd0a2b114.tar.gz |
frozenset (basic) implementation in compat.py
Diffstat (limited to 'test')
-rw-r--r-- | test/unittest_compat.py | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/test/unittest_compat.py b/test/unittest_compat.py index 3f18da1..6a8e0f5 100644 --- a/test/unittest_compat.py +++ b/test/unittest_compat.py @@ -60,7 +60,7 @@ class CompatTCMixIn: class Py23CompatTC(CompatTCMixIn, unittest.TestCase): BUILTINS = ('enumerate', 'sum') MODNAMES = { - 'sets' : ('Set',), + 'sets' : ('Set', 'ImmutableSet'), 'itertools' : ('izip', 'chain'), } @@ -87,9 +87,34 @@ class Py23CompatTC(CompatTCMixIn, unittest.TestCase): self.assertEquals(len(s), 3) self.assertRaises(KeyError, s.remove, 'd') + def test_basic_set(self): + from logilab.common.compat import set + s = set('abc') + self.assertEquals(len(s), 3) + s.remove('a') + self.assertEquals(len(s), 2) + s.add('a') + self.assertEquals(len(s), 3) + s.add('a') + self.assertEquals(len(s), 3) + self.assertRaises(KeyError, s.remove, 'd') + self.assertRaises(TypeError, dict, [(s, 'foo')]) + + + def test_frozenset(self): + from logilab.common.compat import frozenset + s = frozenset('abc') + self.assertEquals(len(s), 3) + self.assertRaises(AttributeError, getattr, s, 'remove') + self.assertRaises(AttributeError, getattr, s, 'add') + d = {s : 'foo'} # frozenset should be hashable + d[s] = 'bar' + self.assertEquals(len(d), 1) + self.assertEquals(d[s], 'bar') + class Py24CompatTC(CompatTCMixIn, unittest.TestCase): - BUILTINS = ('reversed', 'sorted', 'set',) + BUILTINS = ('reversed', 'sorted', 'set', 'frozenset',) def test_sorted(self): from logilab.common.compat import sorted @@ -115,6 +140,7 @@ class Py24CompatTC(CompatTCMixIn, unittest.TestCase): self.assertEquals(s1 | s2, set(range(6))) + if __name__ == '__main__': unittest.main() |