summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-07-13 00:21:42 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-07-13 00:21:42 (GMT)
commit34b2b263db8dce3c980ec2a5061da4b7cc3c9106 (patch)
treee52b23ded0ce40a48cb0fd1b3d35189a9178196a /Lib/unittest
parent84f1b1718da7fcbb8b8d255c166ef1ec0e03cd21 (diff)
downloadcpython-34b2b263db8dce3c980ec2a5061da4b7cc3c9106.zip
cpython-34b2b263db8dce3c980ec2a5061da4b7cc3c9106.tar.gz
cpython-34b2b263db8dce3c980ec2a5061da4b7cc3c9106.tar.bz2
this can be done without a custom dict (also fixes #12544)
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/case.py25
1 files changed, 3 insertions, 22 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index 3f2f37d..3133907 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -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