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
34b2b263
Commit
34b2b263
authored
Jul 12, 2011
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
this can be done without a custom dict (also fixes #12544)
parent
84f1b171
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
22 deletions
+3
-22
Lib/unittest/case.py
Lib/unittest/case.py
+3
-22
No files found.
Lib/unittest/case.py
View file @
34b2b263
...
...
@@ -202,27 +202,6 @@ class _AssertWarnsContext(_AssertRaisesBaseContext):
.
format
(
exc_name
))
class
_TypeEqualityDict
(
object
):
def
__init__
(
self
,
testcase
):
self
.
testcase
=
testcase
self
.
_store
=
{}
def
__setitem__
(
self
,
key
,
value
):
self
.
_store
[
key
]
=
value
def
__getitem__
(
self
,
key
):
value
=
self
.
_store
[
key
]
if
isinstance
(
value
,
str
):
return
getattr
(
self
.
testcase
,
value
)
return
value
def
get
(
self
,
key
,
default
=
None
):
if
key
in
self
.
_store
:
return
self
[
key
]
return
default
class
TestCase
(
object
):
"""A class whose instances are single test cases.
...
...
@@ -294,7 +273,7 @@ class TestCase(object):
# Map types to custom assertEqual functions that will compare
# instances of said type in more detail to generate a more useful
# error message.
self
.
_type_equality_funcs
=
_TypeEqualityDict
(
self
)
self
.
_type_equality_funcs
=
{}
self
.
addTypeEqualityFunc
(
dict
,
'assertDictEqual'
)
self
.
addTypeEqualityFunc
(
list
,
'assertListEqual'
)
self
.
addTypeEqualityFunc
(
tuple
,
'assertTupleEqual'
)
...
...
@@ -628,6 +607,8 @@ class TestCase(object):
if
type
(
first
)
is
type
(
second
):
asserter
=
self
.
_type_equality_funcs
.
get
(
type
(
first
))
if
asserter
is
not
None
:
if
isinstance
(
asserter
,
str
):
asserter
=
getattr
(
self
,
asserter
)
return
asserter
return
self
.
_baseAssertEqual
...
...
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