Commit bfaa8391 authored by Gabriel Monnerat's avatar Gabriel Monnerat

Revert "Fix script to run unit tests follow changes from erp5.git"

This reverts commit da0b08a7.
parent da0b08a7
...@@ -91,14 +91,28 @@ def expectedFailure(func): ...@@ -91,14 +91,28 @@ def expectedFailure(func):
wrapper.__doc__ = func.__doc__ wrapper.__doc__ = func.__doc__
return wrapper return wrapper
try:
BaseException
except NameError:
# BACK: python < 2.5
BaseException = Exception
class TestCase(unittest.TestCase): class TestCase(unittest.TestCase):
"""We redefine here the run() method, and add a skipTest() method. """We redefine here the run() method, and add a skipTest() method.
We also provide forward-compatible ._testMethodName and ._testMethodDoc
properties smooth over differences between Python 2.4 and 2.5+.
""" """
failureException = AssertionError failureException = AssertionError
if sys.version_info < (2, 5):
# BACK: in Python 2.5, __testMethodName becomes _testMethodName.
# Same for __testMethodDoc
_testMethodName = property(lambda self: self.__testMethodName)
_testMethodDoc = property(lambda self: self.__testMethodDoc)
def run(self, result=None): def run(self, result=None):
orig_result = result
if result is None: if result is None:
result = self.defaultTestResult() result = self.defaultTestResult()
# BACK: Not necessary for Python < 2.7: # BACK: Not necessary for Python < 2.7:
...@@ -176,12 +190,12 @@ class TestCase(unittest.TestCase): ...@@ -176,12 +190,12 @@ class TestCase(unittest.TestCase):
"""Skip this test.""" """Skip this test."""
raise SkipTest(reason) raise SkipTest(reason)
if not hasattr(unittest.TestResult, 'addSkip'): # BBB: Python < 2.7 def defaultTestResult(self):
return TestResult()
unittest.TestResult._orig_init__ = unittest.TestResult.__init__.im_func
class TestResult(unittest.TestResult):
def __init__(self): def __init__(self):
self._orig_init__() super(TestResult, self).__init__()
self.skipped = [] self.skipped = []
self.expectedFailures = [] self.expectedFailures = []
self.unexpectedSuccesses = [] self.unexpectedSuccesses = []
...@@ -189,6 +203,26 @@ if not hasattr(unittest.TestResult, 'addSkip'): # BBB: Python < 2.7 ...@@ -189,6 +203,26 @@ if not hasattr(unittest.TestResult, 'addSkip'): # BBB: Python < 2.7
def addSkip(self, test, reason): def addSkip(self, test, reason):
"""Called when a test is skipped.""" """Called when a test is skipped."""
self.skipped.append((test, reason)) self.skipped.append((test, reason))
def addExpectedFailure(self, test, err):
"""Called when an expected failure/error occured."""
self.expectedFailures.append(
(test, self._exc_info_to_string(err, test)))
def addUnexpectedSuccess(self, test):
"""Called when a test was expected to fail, but succeed."""
self.unexpectedSuccesses.append(test)
class _TextTestResult(unittest._TextTestResult, TestResult):
def __init__(self, stream, descriptions, verbosity):
# BACK: nice diamond!
# unittest.TestResult.__init__ is called twice here
unittest._TextTestResult.__init__(self, stream, descriptions, verbosity)
TestResult.__init__(self)
def addSkip(self, test, reason):
super(_TextTestResult, self).addSkip(test, reason)
if self.showAll: if self.showAll:
self.stream.writeln("skipped %s" % repr(reason)) self.stream.writeln("skipped %s" % repr(reason))
elif self.dots: elif self.dots:
...@@ -196,9 +230,7 @@ if not hasattr(unittest.TestResult, 'addSkip'): # BBB: Python < 2.7 ...@@ -196,9 +230,7 @@ if not hasattr(unittest.TestResult, 'addSkip'): # BBB: Python < 2.7
self.stream.flush() self.stream.flush()
def addExpectedFailure(self, test, err): def addExpectedFailure(self, test, err):
"""Called when an expected failure/error occured.""" super(_TextTestResult, self).addExpectedFailure(test, err)
self.expectedFailures.append(
(test, self._exc_info_to_string(err, test)))
if self.showAll: if self.showAll:
self.stream.writeln("expected failure") self.stream.writeln("expected failure")
elif self.dots: elif self.dots:
...@@ -206,32 +238,13 @@ if not hasattr(unittest.TestResult, 'addSkip'): # BBB: Python < 2.7 ...@@ -206,32 +238,13 @@ if not hasattr(unittest.TestResult, 'addSkip'): # BBB: Python < 2.7
self.stream.flush() self.stream.flush()
def addUnexpectedSuccess(self, test): def addUnexpectedSuccess(self, test):
"""Called when a test was expected to fail, but succeed.""" super(_TextTestResult, self).addUnexpectedSuccess(test)
self.unexpectedSuccesses.append(test)
if self.showAll: if self.showAll:
self.stream.writeln("unexpected success") self.stream.writeln("unexpected success")
elif self.dots: elif self.dots:
self.stream.write("u") self.stream.write("u")
self.stream.flush() self.stream.flush()
for f in __init__, addSkip, addExpectedFailure, addUnexpectedSuccess:
setattr(unittest.TestResult, f.__name__, f)
def getDescription(self, 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)
unittest._TextTestResult.getDescription = getDescription
class _TextTestResult(unittest._TextTestResult):
def wasSuccessful(self):
"Tells whether or not this result was a success"
return not (self.failures or self.errors or self.unexpectedSuccesses)
def printErrors(self): def printErrors(self):
if self.dots or self.showAll: if self.dots or self.showAll:
self.stream.writeln() self.stream.writeln()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment