Adopt symmetric names for arguments (actual/expected --> first/second).

This commit is contained in:
Raymond Hettinger 2010-12-24 21:51:48 +00:00
parent 1397ce1821
commit 57bd00a15b
2 changed files with 15 additions and 15 deletions

View File

@ -1151,16 +1151,16 @@ Test cases
.. deprecated:: 3.2 .. deprecated:: 3.2
.. method:: assertCountEqual(actual, expected, msg=None) .. method:: assertCountEqual(first, second, msg=None)
Test that sequence *actual* contains the same elements as *expected*, Test that sequence *first* contains the same elements as *second*,
regardless of their order. When they don't, an error message listing the regardless of their order. When they don't, an error message listing the
differences between the sequences will be generated. differences between the sequences will be generated.
Duplicate elements are *not* ignored when comparing *actual* and Duplicate elements are *not* ignored when comparing *first* and
*expected*. It verifies if each element has the same count in both *second*. It verifies whether each element has the same count in both
sequences. Equivalent to: sequences. Equivalent to:
``assertEqual(Counter(list(actual)), Counter(list(expected)))`` ``assertEqual(Counter(list(first)), Counter(list(second)))``
but works with sequences of unhashable objects as well. but works with sequences of unhashable objects as well.
.. versionadded:: 3.2 .. versionadded:: 3.2

View File

@ -1004,20 +1004,20 @@ class TestCase(object):
self.fail(self._formatMessage(msg, standardMsg)) self.fail(self._formatMessage(msg, standardMsg))
def assertCountEqual(self, actual, expected, msg=None): def assertCountEqual(self, first, second, msg=None):
"""An unordered sequence specific comparison. It asserts that """An unordered sequence comparison asserting that the same elements,
actual and expected have the same element counts. regardless of order. If the same element occurs more than once,
Equivalent to:: it verifies that the elements occur the same number of times.
self.assertEqual(Counter(list(actual)), self.assertEqual(Counter(list(first)),
Counter(list(expected))) Counter(list(second)))
Asserts that each element has the same count in both sequences. Example:
Example:
- [0, 1, 1] and [1, 0, 1] compare equal. - [0, 1, 1] and [1, 0, 1] compare equal.
- [0, 0, 1] and [0, 1] compare unequal. - [0, 0, 1] and [0, 1] compare unequal.
""" """
actual_seq, expected_seq = list(actual), list(expected) actual_seq, expected_seq = list(first), list(second)
try: try:
actual = collections.Counter(actual_seq) actual = collections.Counter(actual_seq)
expected = collections.Counter(expected_seq) expected = collections.Counter(expected_seq)
@ -1031,7 +1031,7 @@ class TestCase(object):
if differences: if differences:
standardMsg = 'Element counts were not equal:\n' standardMsg = 'Element counts were not equal:\n'
lines = ['Got %d, expected %d: %r' % diff for diff in differences] lines = ['First has %d, Second has %d: %r' % diff for diff in differences]
diffMsg = '\n'.join(lines) diffMsg = '\n'.join(lines)
standardMsg = self._truncateMessage(standardMsg, diffMsg) standardMsg = self._truncateMessage(standardMsg, diffMsg)
msg = self._formatMessage(msg, standardMsg) msg = self._formatMessage(msg, standardMsg)