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
fe6349c9
Commit
fe6349c9
authored
Feb 08, 2010
by
Michael Foord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make assertMultiLineEqual the default for comparing unicode strings.
parent
0c4783a3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
6 deletions
+14
-6
Doc/library/unittest.rst
Doc/library/unittest.rst
+10
-4
Lib/test/test_unittest.py
Lib/test/test_unittest.py
+3
-2
Lib/unittest/case.py
Lib/unittest/case.py
+1
-0
No files found.
Doc/library/unittest.rst
View file @
fe6349c9
...
@@ -695,7 +695,7 @@ Test cases
...
@@ -695,7 +695,7 @@ Test cases
*second*.
*second*.
In addition, if *first* and *second* are the exact same type and one of
In addition, if *first* and *second* are the exact same type and one of
list, tuple, dict, set,
or frozenset
or any type that a subclass
list, tuple, dict, set,
frozenset or unicode
or any type that a subclass
registers :meth:`addTypeEqualityFunc` the type specific equality function
registers :meth:`addTypeEqualityFunc` the type specific equality function
will be called in order to generate a more useful default error message.
will be called in order to generate a more useful default error message.
...
@@ -777,7 +777,8 @@ Test cases
...
@@ -777,7 +777,8 @@ Test cases
Test that the multiline string *first* is equal to the string *second*.
Test that the multiline string *first* is equal to the string *second*.
When not equal a diff of the two strings highlighting the differences
When not equal a diff of the two strings highlighting the differences
will be included in the error message.
will be included in the error message. This method is used by default
when comparing Unicode strings with :meth:`assertEqual`.
If specified *msg* will be used as the error message on failure.
If specified *msg* will be used as the error message on failure.
...
@@ -823,7 +824,8 @@ Test cases
...
@@ -823,7 +824,8 @@ Test cases
.. method:: assertSetEqual(set1, set2, msg=None)
.. method:: assertSetEqual(set1, set2, msg=None)
Tests that two sets are equal. If not, an error message is constructed
Tests that two sets are equal. If not, an error message is constructed
that lists the differences between the sets.
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 *set1* or *set2* does not have a :meth:`set.difference`
method.
method.
...
@@ -836,7 +838,9 @@ Test cases
...
@@ -836,7 +838,9 @@ Test cases
.. method:: assertDictEqual(expected, actual, msg=None)
.. method:: assertDictEqual(expected, actual, msg=None)
Test that two dictionaries are equal. If not, an error message is
Test that two dictionaries are equal. If not, an error message is
constructed that shows the differences in the dictionaries.
constructed that shows the differences in the dictionaries. This
method will be used by default to compare dictionaries in
calls to :meth:`assertEqual`.
If specified *msg* will be used as the error message on failure.
If specified *msg* will be used as the error message on failure.
...
@@ -860,6 +864,8 @@ Test cases
...
@@ -860,6 +864,8 @@ Test cases
Tests that two lists or tuples are equal. If not an error message is
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
constructed that shows only the differences between the two. An error
is also raised if either of the parameters are of the wrong type.
is also raised if either of the parameters are of the wrong type.
These methods are used by default when comparing lists or tuples with
:meth:`assertEqual`.
If specified *msg* will be used as the error message on failure.
If specified *msg* will be used as the error message on failure.
...
...
Lib/test/test_unittest.py
View file @
fe6349c9
...
@@ -2810,8 +2810,9 @@ test case
...
@@ -2810,8 +2810,9 @@ test case
self
.
assertMultiLineEqual
(
type_changer
(
sample_text
),
self
.
assertMultiLineEqual
(
type_changer
(
sample_text
),
type_changer
(
revised_sample_text
))
type_changer
(
revised_sample_text
))
except
self
.
failureException
,
e
:
except
self
.
failureException
,
e
:
# no fair testing ourself with ourself, use assertEqual..
# assertMultiLineEqual is hooked up as the default for
self
.
assertEqual
(
sample_text_error
,
str
(
e
).
encode
(
'utf8'
))
# unicode strings - so we can't use it for this check
self
.
assertTrue
(
sample_text_error
==
str
(
e
).
encode
(
'utf8'
))
def
testAssertIsNone
(
self
):
def
testAssertIsNone
(
self
):
self
.
assertIsNone
(
None
)
self
.
assertIsNone
(
None
)
...
...
Lib/unittest/case.py
View file @
fe6349c9
...
@@ -176,6 +176,7 @@ class TestCase(object):
...
@@ -176,6 +176,7 @@ class TestCase(object):
self
.
addTypeEqualityFunc
(
tuple
,
self
.
assertTupleEqual
)
self
.
addTypeEqualityFunc
(
tuple
,
self
.
assertTupleEqual
)
self
.
addTypeEqualityFunc
(
set
,
self
.
assertSetEqual
)
self
.
addTypeEqualityFunc
(
set
,
self
.
assertSetEqual
)
self
.
addTypeEqualityFunc
(
frozenset
,
self
.
assertSetEqual
)
self
.
addTypeEqualityFunc
(
frozenset
,
self
.
assertSetEqual
)
self
.
addTypeEqualityFunc
(
unicode
,
self
.
assertMultiLineEqual
)
def
addTypeEqualityFunc
(
self
,
typeobj
,
function
):
def
addTypeEqualityFunc
(
self
,
typeobj
,
function
):
"""Add a type specific assertEqual style function to compare a type.
"""Add a type specific assertEqual style function to compare a type.
...
...
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