summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Doc/library/unittest.rst75
-rw-r--r--Lib/unittest/case.py26
-rw-r--r--Misc/NEWS3
3 files changed, 54 insertions, 50 deletions
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst
index c011be8..9d0d90a 100644
--- a/Doc/library/unittest.rst
+++ b/Doc/library/unittest.rst
@@ -848,12 +848,12 @@ Test cases
accept a *msg* argument that, if specified, is used as the error message on
failure (see also :data:`longMessage`).
- .. method:: assertEqual(first, second, msg=None)
+ .. method:: assertEqual(actual, expected, msg=None)
- Test that *first* and *second* are equal. If the values do not compare
- equal, the test will fail.
+ Test that *actual* and *expected* are equal. If the values do not
+ compare equal, the test will fail.
- In addition, if *first* and *second* are the exact same type and one of
+ In addition, if *actual* and *expected* are the exact same type and one of
list, tuple, dict, set, frozenset or str or any type that a subclass
registers with :meth:`addTypeEqualityFunc` the type specific equality
function will be called in order to generate a more useful default
@@ -868,10 +868,10 @@ Test cases
function for comparing strings.
- .. method:: assertNotEqual(first, second, msg=None)
+ .. method:: assertNotEqual(actual, expected, msg=None)
- Test that *first* and *second* are not equal. If the values do compare
- equal, the test will fail.
+ Test that *actual* and *expected* are not equal. If the values do
+ compare equal, the test will fail.
.. method:: assertTrue(expr, msg=None)
assertFalse(expr, msg=None)
@@ -885,10 +885,11 @@ Test cases
provide a better error message in case of failure.
- .. method:: assertIs(first, second, msg=None)
- assertIsNot(first, second, msg=None)
+ .. method:: assertIs(actual, expected, msg=None)
+ assertIsNot(actual, expected, msg=None)
- Test that *first* and *second* evaluate (or don't evaluate) to the same object.
+ Test that *actual* and *expected* evaluate (or don't evaluate) to the
+ same object.
.. versionadded:: 3.1
@@ -1086,17 +1087,17 @@ Test cases
+---------------------------------------+--------------------------------+--------------+
- .. method:: assertAlmostEqual(first, second, places=7, msg=None, delta=None)
- assertNotAlmostEqual(first, second, places=7, msg=None, delta=None)
+ .. method:: assertAlmostEqual(actual, expected, places=7, msg=None, delta=None)
+ assertNotAlmostEqual(actual, expected, places=7, msg=None, delta=None)
- Test that *first* and *second* are approximately (or not approximately)
+ Test that *actual* and *expected* are approximately (or not approximately)
equal by computing the difference, rounding to the given number of
decimal *places* (default 7), and comparing to zero. Note that these
methods round the values to the given number of *decimal places* (i.e.
like the :func:`round` function) and not *significant digits*.
If *delta* is supplied instead of *places* then the difference
- between *first* and *second* must be less (or more) than *delta*.
+ between *actual* and *expected* must be less (or more) than *delta*.
Supplying both *delta* and *places* raises a ``TypeError``.
@@ -1106,12 +1107,12 @@ Test cases
if the objects compare equal. Added the *delta* keyword argument.
- .. method:: assertGreater(first, second, msg=None)
- assertGreaterEqual(first, second, msg=None)
- assertLess(first, second, msg=None)
- assertLessEqual(first, second, msg=None)
+ .. method:: assertGreater(actual, expected, msg=None)
+ assertGreaterEqual(actual, expected, msg=None)
+ assertLess(actual, expected, msg=None)
+ assertLessEqual(actual, expected, msg=None)
- Test that *first* is respectively >, >=, < or <= than *second* depending
+ Test that *actual* is respectively >, >=, < or <= than *expected* depending
on the method name. If not, the test will fail::
>>> self.assertGreaterEqual(3, 4)
@@ -1138,37 +1139,37 @@ Test cases
:meth:`.assertNotRegex`.
- .. method:: assertDictContainsSubset(expected, actual, msg=None)
+ .. method:: assertDictContainsSubset(subset, dictionary, msg=None)
- Tests whether the key/value pairs in dictionary *actual* are a
- superset of those in *expected*. If not, an error message listing
- the missing keys and mismatched values is generated.
+ Tests whether the key/value pairs in *dictionary* are a superset of
+ those in *subset*. If not, an error message listing the missing keys
+ and mismatched values is generated.
.. versionadded:: 3.1
- .. method:: assertCountEqual(expected, actual, msg=None)
+ .. method:: assertCountEqual(actual, expected, msg=None)
- Test that sequence *expected* contains the same elements as *actual*,
+ Test that sequence *actual* contains the same elements as *expected*,
regardless of their order. When they don't, an error message listing the
differences between the sequences will be generated.
Duplicate elements are *not* ignored when comparing *actual* and
*expected*. It verifies if each element has the same count in both
sequences. Equivalent to:
- ``assertEqual(Counter(iter(expected)), Counter(iter(actual)))``
+ ``assertEqual(Counter(iter(actual)), Counter(iter(expected)))``
but works with sequences of unhashable objects as well.
.. versionadded:: 3.2
.. method:: assertSameElements(actual, expected, msg=None)
- Test that sequence *expected* contains the same elements as *actual*,
+ Test that sequence *actual* contains the same elements as *expected*,
regardless of their order. When they don't, an error message listing
the differences between the sequences will be generated.
Duplicate elements are ignored when comparing *actual* and *expected*.
- It is the equivalent of ``assertEqual(set(expected), set(actual))``
+ It is the equivalent of ``assertEqual(set(actual), set(expected))``
but it works with sequences of unhashable objects as well. Because
duplicates are ignored, this method has been deprecated in favour of
:meth:`assertCountEqual`.
@@ -1225,9 +1226,9 @@ Test cases
- .. method:: assertMultiLineEqual(first, second, msg=None)
+ .. method:: assertMultiLineEqual(actual, expected, msg=None)
- Test that the multiline string *first* is equal to the string *second*.
+ Test that the multiline string *actual* is equal to the string *expected*.
When not equal a diff of the two strings highlighting the differences
will be included in the error message. This method is used by default
when comparing strings with :meth:`assertEqual`.
@@ -1235,10 +1236,10 @@ Test cases
.. versionadded:: 3.1
- .. method:: assertSequenceEqual(seq1, seq2, msg=None, seq_type=None)
+ .. method:: assertSequenceEqual(actual, expected, msg=None, seq_type=None)
Tests that two sequences are equal. If a *seq_type* is supplied, both
- *seq1* and *seq2* must be instances of *seq_type* or a failure will
+ *actual* and *expected* must be instances of *seq_type* or a failure will
be raised. If the sequences are different an error message is
constructed that shows the difference between the two.
@@ -1249,8 +1250,8 @@ Test cases
.. versionadded:: 3.1
- .. method:: assertListEqual(list1, list2, msg=None)
- assertTupleEqual(tuple1, tuple2, msg=None)
+ .. method:: assertListEqual(actual, expected, msg=None)
+ assertTupleEqual(actual, expected, msg=None)
Tests that two lists or tuples are equal. If not an error message is
constructed that shows only the differences between the two. An error
@@ -1261,19 +1262,19 @@ Test cases
.. versionadded:: 3.1
- .. method:: assertSetEqual(set1, set2, msg=None)
+ .. method:: assertSetEqual(actual, expected, msg=None)
Tests that two sets are equal. If not, an error message is constructed
that lists the differences between the sets. This method is used by
default when comparing sets or frozensets with :meth:`assertEqual`.
- Fails if either of *set1* or *set2* does not have a :meth:`set.difference`
+ Fails if either of *actual* or *expected* does not have a :meth:`set.difference`
method.
.. versionadded:: 3.1
- .. method:: assertDictEqual(expected, actual, msg=None)
+ .. method:: assertDictEqual(actual, expected, msg=None)
Test that two dictionaries are equal. If not, an error message is
constructed that shows the differences in the dictionaries. This
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index d6e80e8..177a2fe 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -904,17 +904,17 @@ class TestCase(object):
standardMsg = self._truncateMessage(standardMsg, diff)
self.fail(self._formatMessage(msg, standardMsg))
- def assertDictContainsSubset(self, expected, actual, msg=None):
- """Checks whether actual is a superset of expected."""
+ def assertDictContainsSubset(self, subset, dictionary, msg=None):
+ """Checks whether dictionary is a superset of subset."""
missing = []
mismatched = []
- for key, value in expected.items():
- if key not in actual:
+ for key, value in subset.items():
+ if key not in dictionary:
missing.append(key)
- elif value != actual[key]:
+ elif value != dictionary[key]:
mismatched.append('%s, expected: %s, actual: %s' %
(safe_repr(key), safe_repr(value),
- safe_repr(actual[key])))
+ safe_repr(dictionary[key])))
if not (missing or mismatched):
return
@@ -973,13 +973,13 @@ class TestCase(object):
self.fail(self._formatMessage(msg, standardMsg))
- def assertCountEqual(self, expected_seq, actual_seq, msg=None):
+ def assertCountEqual(self, actual_seq, expected_seq, msg=None):
"""An unordered sequence specific comparison. It asserts that
- expected_seq and actual_seq have the same element counts.
+ actual_seq and expected_seq have the same element counts.
Equivalent to::
- self.assertEqual(Counter(iter(expected_seq)),
- Counter(iter(actual_seq)))
+ self.assertEqual(Counter(iter(actual_seq)),
+ Counter(iter(expected_seq)))
Asserts that each element has the same count in both sequences.
Example:
@@ -987,15 +987,15 @@ class TestCase(object):
- [0, 0, 1] and [0, 1] compare unequal.
"""
try:
- expected = collections.Counter(iter(expected_seq))
actual = collections.Counter(iter(actual_seq))
+ expected = collections.Counter(iter(expected_seq))
except TypeError:
# Unsortable items (example: set(), complex(), ...)
- expected = list(expected_seq)
actual = list(actual_seq)
+ expected = list(expected_seq)
missing, unexpected = unorderable_list_difference(expected, actual)
else:
- if expected == actual:
+ if actual == expected:
return
missing = list(expected - actual)
unexpected = list(actual - expected)
diff --git a/Misc/NEWS b/Misc/NEWS
index 9428d1b..f4741fb 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -23,6 +23,9 @@ Core and Builtins
Library
-------
+- Issue #10573: use actual/expected consistently in unittest methods.
+ The order of the args of assertCountEqual is also changed.
+
- Issue #9286: email.utils.parseaddr no longer concatenates blank-separated
words in the local part of email addresses, thereby preserving the input.