this can be done without a custom dict (also fixes #12544)
This commit is contained in:
parent
84f1b1718d
commit
34b2b263db
|
@ -202,27 +202,6 @@ class _AssertWarnsContext(_AssertRaisesBaseContext):
|
||||||
.format(exc_name))
|
.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):
|
class TestCase(object):
|
||||||
"""A class whose instances are single test cases.
|
"""A class whose instances are single test cases.
|
||||||
|
|
||||||
|
@ -294,7 +273,7 @@ class TestCase(object):
|
||||||
# Map types to custom assertEqual functions that will compare
|
# Map types to custom assertEqual functions that will compare
|
||||||
# instances of said type in more detail to generate a more useful
|
# instances of said type in more detail to generate a more useful
|
||||||
# error message.
|
# error message.
|
||||||
self._type_equality_funcs = _TypeEqualityDict(self)
|
self._type_equality_funcs = {}
|
||||||
self.addTypeEqualityFunc(dict, 'assertDictEqual')
|
self.addTypeEqualityFunc(dict, 'assertDictEqual')
|
||||||
self.addTypeEqualityFunc(list, 'assertListEqual')
|
self.addTypeEqualityFunc(list, 'assertListEqual')
|
||||||
self.addTypeEqualityFunc(tuple, 'assertTupleEqual')
|
self.addTypeEqualityFunc(tuple, 'assertTupleEqual')
|
||||||
|
@ -628,6 +607,8 @@ class TestCase(object):
|
||||||
if type(first) is type(second):
|
if type(first) is type(second):
|
||||||
asserter = self._type_equality_funcs.get(type(first))
|
asserter = self._type_equality_funcs.get(type(first))
|
||||||
if asserter is not None:
|
if asserter is not None:
|
||||||
|
if isinstance(asserter, str):
|
||||||
|
asserter = getattr(self, asserter)
|
||||||
return asserter
|
return asserter
|
||||||
|
|
||||||
return self._baseAssertEqual
|
return self._baseAssertEqual
|
||||||
|
|
Loading…
Reference in New Issue