def testTracebackReporting(self): self.suite.addMethod(common.FailfulTests.testTracebackReporting) self.suite.run() lines = self.reporter.out.split('\n') while 1: if not lines: raise FailTest, "DOUBLE_SEPARATOR not found in lines" if lines[0] != DOUBLE_SEPARATOR: lines.pop(0) else: return expect = [ DOUBLE_SEPARATOR, '[ERROR]: testTracebackReporting (twisted.trial.test.test_reporter.FailfulTests)', None, None, re.compile(r'.*twisted/trial/test/test_reporter\.py.*testTracebackReporting'), re.compile(r'.*1/0'), re.compile(r'.*ZeroDivisionError.*'), SEPARATOR, re.compile(r'Ran 1 tests in [0-9.]*s'), r'FAILED (errors=1)' ] common.stringComparison(expect, lines)
def testFormatErroredMethod(self): self.suite.addTestClass(erroneous.TestFailureInSetUp) self.suite.run() expect = [re.compile('.*'), re.compile('.*'), reporter.DOUBLE_SEPARATOR, '[ERROR]: twisted.trial.test.erroneous.TestFailureInSetUp.testMethod'] expect.extend(expectFailureInSetUp) common.stringComparison(expect, self.suite.reporter.out.splitlines())
def testImportError(self): self.failIfImportErrors = False # Add a module that fails to import modname = 'twisted.trial.test.importErrors' if modname in sys.modules: # Previous tests might leave this hanging around in Python < 2.4. del sys.modules[modname] self.suite.addModule(modname) self.suite.run() output = self.reporter.out.split('\n') expect = [reporter.DOUBLE_SEPARATOR, 'IMPORT ERROR:'] common.stringComparison(expect, output)
def testDoctestError(self): if sys.version_info[0:2] < (2, 3): raise unittest.SkipTest, 'doctest support only works in Python 2.3 or later' from twisted.trial.test import trialdoctest1 self.suite.addDoctest(trialdoctest1.Counter.unexpectedException) self.suite.run() output = self.suite.reporter.out.splitlines() expect = [re.compile('.*'), reporter.DOUBLE_SEPARATOR, re.compile(r'\[ERROR\]: .*/' + re.escape(os.path.join('twisted', 'trial', 'test', 'trialdoctest1.py'))), 'docstring', '---------', '--> >>> 1/0', 'Traceback (most recent call last):', None, None, re.compile('.*File.*doctest unexpectedException.*line 1.*in.*'), re.compile('.*1/0'), 'ZeroDivisionError: integer division or modulo by zero'] common.stringComparison(expect, output)
def testFormatFailedMethod(self): self.suite.addMethod(common.FailfulTests.testFailure) self.suite.run() common.stringComparison(expectTestFailure, self.suite.reporter.out.splitlines())