Merged revisions 78130 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78130 | michael.foord | 2010-02-10 14:25:12 +0000 (Wed, 10 Feb 2010) | 1 line

  Issue 7893 and Issue 7588
........
This commit is contained in:
Michael Foord 2010-02-10 15:51:42 +00:00
parent 99f69ee7a1
commit 34c9462d71
7 changed files with 107 additions and 46 deletions

View file

@ -22,7 +22,7 @@ class _WritelnDecorator(object):
self.write('\n') # text-mode streams translate to \r\n if needed
class _TextTestResult(result.TestResult):
class TextTestResult(result.TestResult):
"""A test result class that can print formatted text results to a stream.
Used by TextTestRunner.
@ -31,27 +31,28 @@ class _TextTestResult(result.TestResult):
separator2 = '-' * 70
def __init__(self, stream, descriptions, verbosity):
super(_TextTestResult, self).__init__()
super(TextTestResult, self).__init__()
self.stream = stream
self.showAll = verbosity > 1
self.dots = verbosity == 1
self.descriptions = descriptions
def getDescription(self, test):
if self.descriptions:
return test.shortDescription() or str(test)
doc_first_line = test.shortDescription()
if self.descriptions and doc_first_line:
return '\n'.join((str(test), doc_first_line))
else:
return str(test)
def startTest(self, test):
super(_TextTestResult, self).startTest(test)
super(TextTestResult, self).startTest(test)
if self.showAll:
self.stream.write(self.getDescription(test))
self.stream.write(" ... ")
self.stream.flush()
def addSuccess(self, test):
super(_TextTestResult, self).addSuccess(test)
super(TextTestResult, self).addSuccess(test)
if self.showAll:
self.stream.writeln("ok")
elif self.dots:
@ -59,7 +60,7 @@ class _TextTestResult(result.TestResult):
self.stream.flush()
def addError(self, test, err):
super(_TextTestResult, self).addError(test, err)
super(TextTestResult, self).addError(test, err)
if self.showAll:
self.stream.writeln("ERROR")
elif self.dots:
@ -67,7 +68,7 @@ class _TextTestResult(result.TestResult):
self.stream.flush()
def addFailure(self, test, err):
super(_TextTestResult, self).addFailure(test, err)
super(TextTestResult, self).addFailure(test, err)
if self.showAll:
self.stream.writeln("FAIL")
elif self.dots:
@ -75,7 +76,7 @@ class _TextTestResult(result.TestResult):
self.stream.flush()
def addSkip(self, test, reason):
super(_TextTestResult, self).addSkip(test, reason)
super(TextTestResult, self).addSkip(test, reason)
if self.showAll:
self.stream.writeln("skipped {0!r}".format(reason))
elif self.dots:
@ -83,7 +84,7 @@ class _TextTestResult(result.TestResult):
self.stream.flush()
def addExpectedFailure(self, test, err):
super(_TextTestResult, self).addExpectedFailure(test, err)
super(TextTestResult, self).addExpectedFailure(test, err)
if self.showAll:
self.stream.writeln("expected failure")
elif self.dots:
@ -91,7 +92,7 @@ class _TextTestResult(result.TestResult):
self.stream.flush()
def addUnexpectedSuccess(self, test):
super(_TextTestResult, self).addUnexpectedSuccess(test)
super(TextTestResult, self).addUnexpectedSuccess(test)
if self.showAll:
self.stream.writeln("unexpected success")
elif self.dots:
@ -118,13 +119,18 @@ class TextTestRunner(object):
It prints out the names of tests as they are run, errors as they
occur, and a summary of the results at the end of the test run.
"""
def __init__(self, stream=sys.stderr, descriptions=1, verbosity=1):
resultclass = TextTestResult
def __init__(self, stream=sys.stderr, descriptions=True, verbosity=1,
resultclass=None):
self.stream = _WritelnDecorator(stream)
self.descriptions = descriptions
self.verbosity = verbosity
if resultclass is not None:
self.resultclass = resultclass
def _makeResult(self):
return _TextTestResult(self.stream, self.descriptions, self.verbosity)
return self.resultclass(self.stream, self.descriptions, self.verbosity)
def run(self, test):
"Run the given test case or test suite."