diff options
author | Raymond Hettinger <python@rcn.com> | 2013-10-04 23:52:39 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2013-10-04 23:52:39 (GMT) |
commit | 07573d7b2418dd3a043c8fc95f40517fa4543048 (patch) | |
tree | 049d77259a79df33d154deddf43ab9cb59bae219 /Lib/test/test_collections.py | |
parent | 3ad327ec3ad1887a9e5ab738ba12b5f78751a791 (diff) | |
parent | cb1d96f782f48b5ad1bc39a1024845492a4a123b (diff) | |
download | cpython-07573d7b2418dd3a043c8fc95f40517fa4543048.zip cpython-07573d7b2418dd3a043c8fc95f40517fa4543048.tar.gz cpython-07573d7b2418dd3a043c8fc95f40517fa4543048.tar.bz2 |
merge
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r-- | Lib/test/test_collections.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py index 6c733ee..ade6ee7 100644 --- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -852,6 +852,24 @@ class TestCollectionABCs(ABCTestCase): ### Counter ################################################################################ +class CounterSubclassWithSetItem(Counter): + # Test a counter subclass that overrides __setitem__ + def __init__(self, *args, **kwds): + self.called = False + Counter.__init__(self, *args, **kwds) + def __setitem__(self, key, value): + self.called = True + Counter.__setitem__(self, key, value) + +class CounterSubclassWithGet(Counter): + # Test a counter subclass that overrides get() + def __init__(self, *args, **kwds): + self.called = False + Counter.__init__(self, *args, **kwds) + def get(self, key, default): + self.called = True + return Counter.get(self, key, default) + class TestCounter(unittest.TestCase): def test_basics(self): @@ -1059,6 +1077,12 @@ class TestCounter(unittest.TestCase): self.assertEqual(m, OrderedDict([('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 1)])) + # test fidelity to the pure python version + c = CounterSubclassWithSetItem('abracadabra') + self.assertTrue(c.called) + c = CounterSubclassWithGet('abracadabra') + self.assertTrue(c.called) + ################################################################################ ### OrderedDict |