summaryrefslogtreecommitdiffstats
path: root/Lib/unittest.py
diff options
context:
space:
mode:
authorSteve Purcell <steve@pythonconsulting.com>2002-08-09 09:46:23 (GMT)
committerSteve Purcell <steve@pythonconsulting.com>2002-08-09 09:46:23 (GMT)
commitdc391a67e39df5f23d62d50b4cdb74728c24684e (patch)
tree4d835d4a23ad0de5b58ba37cfb9bbd14c0f5b674 /Lib/unittest.py
parenta70ab8cd4f6f4475b42cee5419ac6018d1ca7a01 (diff)
downloadcpython-dc391a67e39df5f23d62d50b4cdb74728c24684e.zip
cpython-dc391a67e39df5f23d62d50b4cdb74728c24684e.tar.gz
cpython-dc391a67e39df5f23d62d50b4cdb74728c24684e.tar.bz2
Fix to ensure consistent 'repr' and 'str' results between Python
versions, since 'repr(new_style_class) != repr(classic_class)'. Suggested by Jeremy Hylton.
Diffstat (limited to 'Lib/unittest.py')
-rw-r--r--Lib/unittest.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/Lib/unittest.py b/Lib/unittest.py
index ae751af..2714a58 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