summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_collections.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2009-01-13 01:05:03 (GMT)
committerRaymond Hettinger <python@rcn.com>2009-01-13 01:05:03 (GMT)
commitaaa6e630f8440c7a29621863df35fb4c427e5968 (patch)
treee045d175b38bcd478e36de41af3075cfbb6d42e6 /Lib/test/test_collections.py
parenta40d57366432cd65915b92fe3e6bfe1d5ad63be0 (diff)
downloadcpython-aaa6e630f8440c7a29621863df35fb4c427e5968.zip
cpython-aaa6e630f8440c7a29621863df35fb4c427e5968.tar.gz
cpython-aaa6e630f8440c7a29621863df35fb4c427e5968.tar.bz2
Simplify Counter() API. Replace items keyword argument
with a mapping. Makes Counter() idempotent, makes update() API the same as Counter.__init__(), makes a more readable repr, makes the API more dict-like, and allows Steven Bethard's update() example to work.
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r--Lib/test/test_collections.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 00882e2..80ee2c5 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -370,8 +370,7 @@ class TestCounter(unittest.TestCase):
self.assertEqual(c.get('b', 10), 2)
self.assertEqual(c.get('z', 10), 10)
self.assertEqual(c, dict(a=3, b=2, c=1))
- self.assertEqual(repr(c),
- "Counter(items=[('a', 3), ('b', 2), ('c', 1)])")
+ self.assertEqual(repr(c), "Counter({'a': 3, 'b': 2, 'c': 1})")
self.assertEqual(c.most_common(), [('a', 3), ('b', 2), ('c', 1)])
for i in range(5):
self.assertEqual(c.most_common(i),
@@ -396,8 +395,8 @@ class TestCounter(unittest.TestCase):
self.assertRaises(NotImplementedError, Counter.fromkeys, 'abc')
self.assertRaises(TypeError, hash, c)
c.update(dict(a=5, b=3, c=1))
- c.update(Counter(items=[('a', 50), ('b', 30)]))
- c.__init__(items=[('a', 500), ('b', 300)])
+ c.update(Counter('a' * 50 + 'b' * 30))
+ c.__init__('a' * 500 + 'b' * 300)
c.__init__('cdc')
self.assertEqual(c, dict(a=555, b=333, c=3, d=1))
self.assertEqual(c.setdefault('d', 5), 1)
@@ -425,6 +424,7 @@ class TestCounter(unittest.TestCase):
cPickle.loads(cPickle.dumps(words, -1)),
eval(repr(words)),
update_test,
+ Counter(words),
]):
msg = (i, dup, words)
self.assert_(dup is not words)