summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test
diff options
context:
space:
mode:
authorMichael Foord <michael@python.org>2011-03-17 00:34:53 (GMT)
committerMichael Foord <michael@python.org>2011-03-17 00:34:53 (GMT)
commit4c9e91a092f55a669b83255ce18bad0c7daa0b31 (patch)
tree0c66cd3df186449f57d1e2802f2d1e85f1ac0bad /Lib/unittest/test
parent2ab5994dbe8934564f1ac0b3be1e6d98235e6773 (diff)
downloadcpython-4c9e91a092f55a669b83255ce18bad0c7daa0b31.zip
cpython-4c9e91a092f55a669b83255ce18bad0c7daa0b31.tar.gz
cpython-4c9e91a092f55a669b83255ce18bad0c7daa0b31.tar.bz2
Issue #10242: backport of more fixes to unittest.TestCase.assertItemsEqual
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r--Lib/unittest/test/test_assertions.py6
-rw-r--r--Lib/unittest/test/test_case.py40
2 files changed, 26 insertions, 20 deletions
diff --git a/Lib/unittest/test/test_assertions.py b/Lib/unittest/test/test_assertions.py
index e85ca91..e1ba614 100644
--- a/Lib/unittest/test/test_assertions.py
+++ b/Lib/unittest/test/test_assertions.py
@@ -228,12 +228,6 @@ class TestLongMessage(unittest.TestCase):
"^Missing: 'key'$",
"^Missing: 'key' : oops$"])
- def testAssertItemsEqual(self):
- self.assertMessages('assertItemsEqual', ([], [None]),
- [r"\[None\]$", "^oops$",
- r"\[None\]$",
- r"\[None\] : oops$"])
-
def testAssertMultiLineEqual(self):
self.assertMessages('assertMultiLineEqual', ("", "foo"),
[r"\+ foo$", "^oops$",
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py
index 250e905..06eeda1 100644
--- a/Lib/unittest/test/test_case.py
+++ b/Lib/unittest/test/test_case.py
@@ -686,20 +686,19 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
# Test that sequences of unhashable objects can be tested for sameness:
self.assertItemsEqual([[1, 2], [3, 4], 0], [False, [3, 4], [1, 2]])
- with test_support.check_warnings(quiet=True) as w:
- # hashable types, but not orderable
- self.assertRaises(self.failureException, self.assertItemsEqual,
- [], [divmod, 'x', 1, 5j, 2j, frozenset()])
- # comparing dicts raises a py3k warning
- self.assertItemsEqual([{'a': 1}, {'b': 2}], [{'b': 2}, {'a': 1}])
- # comparing heterogenous non-hashable sequences raises a py3k warning
- self.assertItemsEqual([1, 'x', divmod, []], [divmod, [], 'x', 1])
- self.assertRaises(self.failureException, self.assertItemsEqual,
- [], [divmod, [], 'x', 1, 5j, 2j, set()])
- # fail the test if warnings are not silenced
- if w.warnings:
- self.fail('assertItemsEqual raised a warning: ' +
- str(w.warnings[0]))
+ # Test that iterator of unhashable objects can be tested for sameness:
+ self.assertItemsEqual(iter([1, 2, [], 3, 4]),
+ iter([1, 2, [], 3, 4]))
+
+ # hashable types, but not orderable
+ self.assertRaises(self.failureException, self.assertItemsEqual,
+ [], [divmod, 'x', 1, 5j, 2j, frozenset()])
+ # comparing dicts
+ self.assertItemsEqual([{'a': 1}, {'b': 2}], [{'b': 2}, {'a': 1}])
+ # comparing heterogenous non-hashable sequences
+ self.assertItemsEqual([1, 'x', divmod, []], [divmod, [], 'x', 1])
+ self.assertRaises(self.failureException, self.assertItemsEqual,
+ [], [divmod, [], 'x', 1, 5j, 2j, set()])
self.assertRaises(self.failureException, self.assertItemsEqual,
[[1]], [[2]])
@@ -717,6 +716,19 @@ class Test_TestCase(unittest.TestCase, TestEquality, TestHashing):
b = a[::-1]
self.assertItemsEqual(a, b)
+ # test utility functions supporting assertItemsEqual()
+
+ diffs = set(unittest.util._count_diff_all_purpose('aaabccd', 'abbbcce'))
+ expected = {(3,1,'a'), (1,3,'b'), (1,0,'d'), (0,1,'e')}
+ self.assertEqual(diffs, expected)
+
+ diffs = unittest.util._count_diff_all_purpose([[]], [])
+ self.assertEqual(diffs, [(1, 0, [])])
+
+ diffs = set(unittest.util._count_diff_hashable('aaabccd', 'abbbcce'))
+ expected = {(3,1,'a'), (1,3,'b'), (1,0,'d'), (0,1,'e')}
+ self.assertEqual(diffs, expected)
+
def testAssertSetEqual(self):
set1 = set()
set2 = set()