diff options
author | Benjamin Peterson <benjamin@python.org> | 2011-07-13 00:21:42 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2011-07-13 00:21:42 (GMT) |
commit | 83c14fe1ee862b405eea5d7e6ac2cc93db4b8bd1 (patch) | |
tree | bd34c8b88f3b5876b101cde51e82992bfc5e45ab /Lib | |
parent | 1616645a0032b45c935ec6bdbb1d46b3febf0827 (diff) | |
download | cpython-83c14fe1ee862b405eea5d7e6ac2cc93db4b8bd1.zip cpython-83c14fe1ee862b405eea5d7e6ac2cc93db4b8bd1.tar.gz cpython-83c14fe1ee862b405eea5d7e6ac2cc93db4b8bd1.tar.bz2 |
this can be done without a custom dict (also fixes #12544)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/unittest/case.py | 25 |
1 files changed, 3 insertions, 22 deletions
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py index ca545f9..4b3839e 100644 --- a/Lib/unittest/case.py +++ b/Lib/unittest/case.py @@ -129,27 +129,6 @@ class _AssertRaisesContext(object): return True -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, basestring): - 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. @@ -216,7 +195,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') @@ -511,6 +490,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, basestring): + asserter = getattr(self, asserter) return asserter return self._baseAssertEqual |