summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-12-23 21:54:02 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-12-23 21:54:02 (GMT)
commitd65a901aed0867c66fd4951e5144f5b5315b5de0 (patch)
tree9b821957955c0152745e447944ae6d129e14cadd
parent4a62e89728a9394af43a6b791140d90ee4b45c11 (diff)
downloadcpython-d65a901aed0867c66fd4951e5144f5b5315b5de0.zip
cpython-d65a901aed0867c66fd4951e5144f5b5315b5de0.tar.gz
cpython-d65a901aed0867c66fd4951e5144f5b5315b5de0.tar.bz2
Fix buglet. If the input was an iterator, the fallback would occur after
part of the iterator had been consumed. Also, fix argument names which did not match the docs and were a bit misleading.
-rw-r--r--Lib/unittest/case.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 15c7eee..68e53a5 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -1003,27 +1003,26 @@ class TestCase(object):
self.fail(self._formatMessage(msg, standardMsg))
- def assertCountEqual(self, actual_seq, expected_seq, msg=None):
+ def assertCountEqual(self, actual, expected, msg=None):
"""An unordered sequence specific comparison. It asserts that
actual_seq and expected_seq have the same element counts.
Equivalent to::
- self.assertEqual(Counter(iter(actual_seq)),
- Counter(iter(expected_seq)))
+ self.assertEqual(Counter(actual_seq),
+ Counter(expected_seq))
Asserts that each element has the same count in both sequences.
Example:
- [0, 1, 1] and [1, 0, 1] compare equal.
- [0, 0, 1] and [0, 1] compare unequal.
"""
+ actual_seq, expected_seq = list(actual), list(expected)
try:
- actual = collections.Counter(iter(actual_seq))
- expected = collections.Counter(iter(expected_seq))
+ actual = collections.Counter(actual_seq)
+ expected = collections.Counter(expected_seq)
except TypeError:
# Unsortable items (example: set(), complex(), ...)
- actual = list(actual_seq)
- expected = list(expected_seq)
- missing, unexpected = unorderable_list_difference(expected, actual)
+ missing, unexpected = unorderable_list_difference(expected_seq, actual_seq)
else:
if actual == expected:
return