summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2013-10-04 23:51:02 (GMT)
committerRaymond Hettinger <python@rcn.com>2013-10-04 23:51:02 (GMT)
commitcb1d96f782f48b5ad1bc39a1024845492a4a123b (patch)
tree398b5d760459656e6a0ca06afce715ab963b06ec /Lib/test
parent5b22dd87aa39087f07987f788a0bbd2464e2a8b5 (diff)
downloadcpython-cb1d96f782f48b5ad1bc39a1024845492a4a123b.zip
cpython-cb1d96f782f48b5ad1bc39a1024845492a4a123b.tar.gz
cpython-cb1d96f782f48b5ad1bc39a1024845492a4a123b.tar.bz2
Issue #18594: Make the C code more closely match the pure python code.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_collections.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index af27d22..ff52755 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -818,6 +818,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):
@@ -1022,6 +1040,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