From: Steve Purcell Date: Fri, 9 Aug 2002 09:46:23 +0000 (+0000) Subject: Fix to ensure consistent 'repr' and 'str' results between Python X-Git-Tag: v2.3c1~4592 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dc391a67e39df5f23d62d50b4cdb74728c24684e;p=python Fix to ensure consistent 'repr' and 'str' results between Python versions, since 'repr(new_style_class) != repr(classic_class)'. Suggested by Jeremy Hylton. --- diff --git a/Lib/unittest.py b/Lib/unittest.py index ae751af10e..2714a5884f 100644 --- a/Lib/unittest.py +++ b/Lib/unittest.py @@ -46,7 +46,7 @@ SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. __author__ = "Steve Purcell" __email__ = "stephen_purcell at yahoo dot com" -__version__ = "#Revision: 1.45 $"[11:-2] +__version__ = "#Revision: 1.46 $"[11:-2] import time import sys @@ -62,6 +62,9 @@ import types # All classes defined herein are 'new-style' classes, allowing use of 'super()' __metaclass__ = type +def _strclass(cls): + return "%s.%s" % (cls.__module__, cls.__name__) + class TestResult: """Holder for test result information. @@ -116,7 +119,7 @@ class TestResult: def __repr__(self): return "<%s run=%i errors=%i failures=%i>" % \ - (self.__class__, self.testsRun, len(self.errors), + (_strclass(self.__class__), self.testsRun, len(self.errors), len(self.failures)) @@ -186,14 +189,14 @@ class TestCase: return doc and string.strip(string.split(doc, "\n")[0]) or None def id(self): - return "%s.%s" % (self.__class__, self.__testMethodName) + return "%s.%s" % (_strclass(self.__class__), self.__testMethodName) def __str__(self): return "%s (%s)" % (self.__testMethodName, self.__class__) def __repr__(self): return "<%s testMethod=%s>" % \ - (self.__class__, self.__testMethodName) + (_strclass(self.__class__), self.__testMethodName) def run(self, result=None): return self(result) @@ -321,7 +324,7 @@ class TestSuite: self.addTests(tests) def __repr__(self): - return "<%s tests=%s>" % (self.__class__, self._tests) + return "<%s tests=%s>" % (_strclass(self.__class__), self._tests) __str__ = __repr__ @@ -385,10 +388,10 @@ class FunctionTestCase(TestCase): return self.__testFunc.__name__ def __str__(self): - return "%s (%s)" % (self.__class__, self.__testFunc.__name__) + return "%s (%s)" % (_strclass(self.__class__), self.__testFunc.__name__) def __repr__(self): - return "<%s testFunc=%s>" % (self.__class__, self.__testFunc) + return "<%s testFunc=%s>" % (_strclass(self.__class__), self.__testFunc) def shortDescription(self): if self.__description is not None: return self.__description