[Python-checkins] cpython (2.7): this can be done without a custom dict (also fixes #12544)

benjamin.peterson python-checkins at python.org
Wed Jul 13 02:19:06 CEST 2011


http://hg.python.org/cpython/rev/02a591131360
changeset:   71300:02a591131360
branch:      2.7
user:        Benjamin Peterson <benjamin at python.org>
date:        Tue Jul 12 19:21:42 2011 -0500
summary:
  this can be done without a custom dict (also fixes #12544)

files:
  Lib/unittest/case.py |  25 +++----------------------
  1 files changed, 3 insertions(+), 22 deletions(-)


diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -129,27 +129,6 @@
         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 @@
         # 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 @@
         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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list