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
9d668dac
Commit
9d668dac
authored
Dec 24, 2010
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Put diff output in useful order (when the elements were first seen).
parent
f9542174
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
11 deletions
+13
-11
Lib/unittest/case.py
Lib/unittest/case.py
+3
-6
Lib/unittest/util.py
Lib/unittest/util.py
+10
-5
No files found.
Lib/unittest/case.py
View file @
9d668dac
...
...
@@ -1023,18 +1023,15 @@ class TestCase(object):
expected
=
collections
.
Counter
(
expected_seq
)
except
TypeError
:
# Handle case with unhashable elements
differences
=
_count_diff_all_purpose
(
expected_seq
,
actual
_seq
)
differences
=
_count_diff_all_purpose
(
actual_seq
,
expected
_seq
)
else
:
if
actual
==
expected
:
return
differences
=
_count_diff_hashable
(
expected_seq
,
actual
_seq
)
differences
=
_count_diff_hashable
(
actual_seq
,
expected
_seq
)
if
differences
:
standardMsg
=
'Element counts were not equal:
\
n
'
lines
=
[]
for
act
,
exp
,
elem
in
differences
:
line
=
'Expected %d, got %d: %r'
%
(
exp
,
act
,
elem
)
lines
.
append
(
line
)
lines
=
[
'Got %d, expected %d: %r'
%
diff
for
diff
in
differences
]
diffMsg
=
'
\
n
'
.
join
(
lines
)
standardMsg
=
self
.
_truncateMessage
(
standardMsg
,
diffMsg
)
msg
=
self
.
_formatMessage
(
msg
,
standardMsg
)
...
...
Lib/unittest/util.py
View file @
9d668dac
"""Various utility functions."""
from
collections
import
namedtuple
,
Counter
from
collections
import
namedtuple
,
OrderedDict
__unittest
=
True
...
...
@@ -116,15 +116,20 @@ def _count_diff_all_purpose(actual, expected):
result
.
append
(
diff
)
return
result
def
ordered_count
(
iterable
):
'Return dict of element counts, in the order they were first seen'
c
=
OrderedDict
()
for
elem
in
iterable
:
c
[
elem
]
=
c
.
get
(
elem
,
0
)
+
1
return
c
def
_count_diff_hashable
(
actual
,
expected
):
'Returns list of (cnt_act, cnt_exp, elem) triples where the counts differ'
# elements must be hashable
s
,
t
=
Counter
(
actual
),
Counter
(
expected
)
if
s
==
t
:
return
[]
s
,
t
=
ordered_count
(
actual
),
ordered_count
(
expected
)
result
=
[]
for
elem
,
cnt_s
in
s
.
items
():
cnt_t
=
t
[
elem
]
cnt_t
=
t
.
get
(
elem
,
0
)
if
cnt_s
!=
cnt_t
:
diff
=
_Mismatch
(
cnt_s
,
cnt_t
,
elem
)
result
.
append
(
diff
)
...
...
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