Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
57bd00a1
Commit
57bd00a1
authored
Dec 24, 2010
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adopt symmetric names for arguments (actual/expected --> first/second).
parent
1397ce18
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
15 deletions
+15
-15
Doc/library/unittest.rst
Doc/library/unittest.rst
+5
-5
Lib/unittest/case.py
Lib/unittest/case.py
+10
-10
No files found.
Doc/library/unittest.rst
View file @
57bd00a1
...
...
@@ -1151,16 +1151,16 @@ Test cases
.. deprecated:: 3.2
.. method:: assertCountEqual(
actual, expecte
d, msg=None)
.. method:: assertCountEqual(
first, secon
d, msg=None)
Test that sequence *
actual* contains the same elements as *expecte
d*,
Test that sequence *
first* contains the same elements as *secon
d*,
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
Duplicate elements are *not* ignored when comparing *
first
* and
*
second*. It verifies whether
each element has the same count in both
sequences. Equivalent to:
``assertEqual(Counter(list(
actual)), Counter(list(expecte
d)))``
``assertEqual(Counter(list(
first)), Counter(list(secon
d)))``
but works with sequences of unhashable objects as well.
.. versionadded:: 3.2
...
...
Lib/unittest/case.py
View file @
57bd00a1
...
...
@@ -1004,20 +1004,20 @@ class TestCase(object):
self
.
fail
(
self
.
_formatMessage
(
msg
,
standardMsg
))
def
assertCountEqual
(
self
,
actual
,
expecte
d
,
msg
=
None
):
"""An unordered sequence
specific comparison. It asserts that
actual and expected have the same element counts.
Equivalent to::
def
assertCountEqual
(
self
,
first
,
secon
d
,
msg
=
None
):
"""An unordered sequence
comparison asserting that the same elements,
regardless of order. If the same element occurs more than once,
it verifies that the elements occur the same number of times.
self.assertEqual(Counter(list(
actual
)),
Counter(list(
expecte
d)))
self.assertEqual(Counter(list(
first
)),
Counter(list(
secon
d)))
Asserts that each element has the same count in both sequences.
Example:
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
(
expecte
d
)
actual_seq
,
expected_seq
=
list
(
first
),
list
(
secon
d
)
try
:
actual
=
collections
.
Counter
(
actual_seq
)
expected
=
collections
.
Counter
(
expected_seq
)
...
...
@@ -1031,7 +1031,7 @@ class TestCase(object):
if
differences
:
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
)
standardMsg
=
self
.
_truncateMessage
(
standardMsg
,
diffMsg
)
msg
=
self
.
_formatMessage
(
msg
,
standardMsg
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment