mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Fix to ensure consistent 'repr' and 'str' results between Python
versions, since 'repr(new_style_class) != repr(classic_class)'. Suggested by Jeremy Hylton.
This commit is contained in:
parent
a70ab8cd4f
commit
dc391a67e3
1 changed files with 10 additions and 7 deletions
|
@ -46,7 +46,7 @@ SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
||||||
|
|
||||||
__author__ = "Steve Purcell"
|
__author__ = "Steve Purcell"
|
||||||
__email__ = "stephen_purcell at yahoo dot com"
|
__email__ = "stephen_purcell at yahoo dot com"
|
||||||
__version__ = "#Revision: 1.45 $"[11:-2]
|
__version__ = "#Revision: 1.46 $"[11:-2]
|
||||||
|
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
@ -62,6 +62,9 @@ import types
|
||||||
# All classes defined herein are 'new-style' classes, allowing use of 'super()'
|
# All classes defined herein are 'new-style' classes, allowing use of 'super()'
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
|
def _strclass(cls):
|
||||||
|
return "%s.%s" % (cls.__module__, cls.__name__)
|
||||||
|
|
||||||
class TestResult:
|
class TestResult:
|
||||||
"""Holder for test result information.
|
"""Holder for test result information.
|
||||||
|
|
||||||
|
@ -116,7 +119,7 @@ class TestResult:
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s run=%i errors=%i failures=%i>" % \
|
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))
|
len(self.failures))
|
||||||
|
|
||||||
|
|
||||||
|
@ -186,14 +189,14 @@ class TestCase:
|
||||||
return doc and string.strip(string.split(doc, "\n")[0]) or None
|
return doc and string.strip(string.split(doc, "\n")[0]) or None
|
||||||
|
|
||||||
def id(self):
|
def id(self):
|
||||||
return "%s.%s" % (self.__class__, self.__testMethodName)
|
return "%s.%s" % (_strclass(self.__class__), self.__testMethodName)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s (%s)" % (self.__testMethodName, self.__class__)
|
return "%s (%s)" % (self.__testMethodName, self.__class__)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s testMethod=%s>" % \
|
return "<%s testMethod=%s>" % \
|
||||||
(self.__class__, self.__testMethodName)
|
(_strclass(self.__class__), self.__testMethodName)
|
||||||
|
|
||||||
def run(self, result=None):
|
def run(self, result=None):
|
||||||
return self(result)
|
return self(result)
|
||||||
|
@ -321,7 +324,7 @@ class TestSuite:
|
||||||
self.addTests(tests)
|
self.addTests(tests)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s tests=%s>" % (self.__class__, self._tests)
|
return "<%s tests=%s>" % (_strclass(self.__class__), self._tests)
|
||||||
|
|
||||||
__str__ = __repr__
|
__str__ = __repr__
|
||||||
|
|
||||||
|
@ -385,10 +388,10 @@ class FunctionTestCase(TestCase):
|
||||||
return self.__testFunc.__name__
|
return self.__testFunc.__name__
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s (%s)" % (self.__class__, self.__testFunc.__name__)
|
return "%s (%s)" % (_strclass(self.__class__), self.__testFunc.__name__)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s testFunc=%s>" % (self.__class__, self.__testFunc)
|
return "<%s testFunc=%s>" % (_strclass(self.__class__), self.__testFunc)
|
||||||
|
|
||||||
def shortDescription(self):
|
def shortDescription(self):
|
||||||
if self.__description is not None: return self.__description
|
if self.__description is not None: return self.__description
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue