summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_collections.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-01-03 02:12:02 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-01-03 02:12:02 (GMT)
commit426e052a4f60f94f3d97c95ce8477b967a975b3b (patch)
tree5e9fa2c4be45ccb06af560cb8b197e16702c87e5 /Lib/test/test_collections.py
parent23eaa70057ce40672c91375f1319c9a9f19790b5 (diff)
downloadcpython-426e052a4f60f94f3d97c95ce8477b967a975b3b.zip
cpython-426e052a4f60f94f3d97c95ce8477b967a975b3b.tar.gz
cpython-426e052a4f60f94f3d97c95ce8477b967a975b3b.tar.bz2
Make C helper function more closely match the pure python version, and add tests.
Diffstat (limited to 'Lib/test/test_collections.py')
-rw-r--r--Lib/test/test_collections.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index deda1cd..d785fcb 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -3,7 +3,7 @@
import unittest, doctest, operator
import inspect
from test import support
-from collections import namedtuple, Counter, OrderedDict
+from collections import namedtuple, Counter, OrderedDict, _count_elements
from test import mapping_tests
import pickle, copy
from random import randrange, shuffle
@@ -775,6 +775,19 @@ class TestCounter(unittest.TestCase):
c.subtract('aaaabbcce')
self.assertEqual(c, Counter(a=-1, b=0, c=-1, d=1, e=-1))
+ def test_helper_function(self):
+ # two paths, one for real dicts and one for other mappings
+ elems = list('abracadabra')
+
+ d = dict()
+ _count_elements(d, elems)
+ self.assertEqual(d, {'a': 5, 'r': 2, 'b': 2, 'c': 1, 'd': 1})
+
+ m = OrderedDict()
+ _count_elements(m, elems)
+ self.assertEqual(m,
+ OrderedDict([('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 1)]))
+
class TestOrderedDict(unittest.TestCase):
def test_init(self):