Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abd91d5

Browse files
author
Michael Foord
committed
Issue 7832. Document changes to unittest.TestCase.assertSameElements and assertItemsEqual
1 parent 91c9da3 commit abd91d5

4 files changed

Lines changed: 32 additions & 13 deletions

File tree

Doc/library/unittest.rst

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ Test cases
785785
will be included in the error message. This method is used by default
786786
when comparing strings with :meth:`assertEqual`.
787787

788-
If specified *msg* will be used as the error message on failure.
788+
If specified, *msg* will be used as the error message on failure.
789789

790790
.. versionadded:: 3.1
791791

@@ -806,7 +806,7 @@ Test cases
806806
Tests that *first* is or is not in *second* with an explanatory error
807807
message as appropriate.
808808

809-
If specified *msg* will be used as the error message on failure.
809+
If specified, *msg* will be used as the error message on failure.
810810

811811
.. versionadded:: 3.1
812812

@@ -819,12 +819,31 @@ Test cases
819819

820820
Duplicate elements are ignored when comparing *actual* and *expected*.
821821
It is the equivalent of ``assertEqual(set(expected), set(actual))``
822-
but it works with sequences of unhashable objects as well.
822+
but it works with sequences of unhashable objects as well. Because
823+
duplicates are ignored, this method has been deprecated in favour of
824+
:meth:`assertItemsEqual`.
823825

824-
If specified *msg* will be used as the error message on failure.
826+
If specified, *msg* will be used as the error message on failure.
825827

826828
.. versionadded:: 3.1
827829

830+
.. deprecated:: 3.2
831+
832+
.. method:: assertItemsEqual(actual, expected, msg=None)
833+
834+
Test that sequence *expected* contains the same elements as *actual*,
835+
regardless of their order. When they don't, an error message listing the
836+
differences between the sequences will be generated.
837+
838+
Duplicate elements are *not* ignored when comparing *actual* and
839+
*expected*. It verifies if each element has the same count in both
840+
sequences. It is the equivalent of ``assertEqual(sorted(expected),
841+
sorted(actual))`` but it works with sequences of unhashable objects as
842+
well.
843+
844+
If specified, *msg* will be used as the error message on failure.
845+
846+
.. versionadded:: 3.2
828847

829848
.. method:: assertSetEqual(set1, set2, msg=None)
830849

@@ -835,7 +854,7 @@ Test cases
835854
Fails if either of *set1* or *set2* does not have a :meth:`set.difference`
836855
method.
837856

838-
If specified *msg* will be used as the error message on failure.
857+
If specified, *msg* will be used as the error message on failure.
839858

840859
.. versionadded:: 3.1
841860

@@ -847,7 +866,7 @@ Test cases
847866
method will be used by default to compare dictionaries in
848867
calls to :meth:`assertEqual`.
849868

850-
If specified *msg* will be used as the error message on failure.
869+
If specified, *msg* will be used as the error message on failure.
851870

852871
.. versionadded:: 3.1
853872

@@ -858,7 +877,7 @@ Test cases
858877
superset of those in *expected*. If not, an error message listing
859878
the missing keys and mismatched values is generated.
860879

861-
If specified *msg* will be used as the error message on failure.
880+
If specified, *msg* will be used as the error message on failure.
862881

863882
.. versionadded:: 3.1
864883

@@ -872,7 +891,7 @@ Test cases
872891
These methods are used by default when comparing lists or tuples with
873892
:meth:`assertEqual`.
874893

875-
If specified *msg* will be used as the error message on failure.
894+
If specified, *msg* will be used as the error message on failure.
876895

877896
.. versionadded:: 3.1
878897

@@ -884,7 +903,7 @@ Test cases
884903
be raised. If the sequences are different an error message is
885904
constructed that shows the difference between the two.
886905

887-
If specified *msg* will be used as the error message on failure.
906+
If specified, *msg* will be used as the error message on failure.
888907

889908
This method is used to implement :meth:`assertListEqual` and
890909
:meth:`assertTupleEqual`.
@@ -1225,7 +1244,7 @@ Loading and running tests
12251244

12261245
:class:`TestLoader` objects have the following methods:
12271246

1228-
1247+
a
12291248
.. method:: loadTestsFromTestCase(testCaseClass)
12301249

12311250
Return a suite of all tests cases contained in the :class:`TestCase`\ -derived

Doc/whatsnew/2.7.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ GvR worked on merging them into Python's version of :mod:`unittest`.
960960
* :meth:`assertIn` and :meth:`assertNotIn` tests whether
961961
*first* is or is not in *second*.
962962

963-
* :meth:`assertSameElements` tests whether two provided sequences
963+
* :meth:`assertItemsEqual` tests whether two provided sequences
964964
contain the same elements.
965965

966966
* :meth:`assertSetEqual` compares whether two sets are equal, and

Lib/test/test_cgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_strict(self):
131131
if isinstance(expect, dict):
132132
# test dict interface
133133
self.assertEqual(len(expect), len(fs))
134-
self.assertEqual(norm(expect.keys()), norm(fs.keys()))
134+
self.assertItemsEqual(expect.keys(), fs.keys())
135135
##self.assertEqual(norm(expect.values()), norm(fs.values()))
136136
##self.assertEqual(norm(expect.items()), norm(fs.items()))
137137
self.assertEqual(fs.getvalue("nonexistent field", "default"), "default")

Tools/scripts/reindent-rst.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3
1+
#!/usr/bin/env python
22

33
# Make a reST file compliant to our pre-commit hook.
44
# Currently just remove trailing whitespace.

0 commit comments

Comments
 (0)