=== modified file 'twisted/scripts/trial.py'
|
|
|
|
| 13 | 13 | from twisted import plugin |
| 14 | 14 | from twisted.python.util import spewer |
| 15 | 15 | from twisted.python.compat import set |
| 16 | | from twisted.trial import runner, itrial, reporter |
| | 16 | from twisted.trial import runner, itrial, reporter, util |
| 17 | 17 | |
| 18 | 18 | |
| 19 | 19 | # Yea, this is stupid. Leave it for for command-line compatibility for a |
| … |
… |
|
| 124 | 124 | 'Path to use as working directory for tests.'], |
| 125 | 125 | ['reporter', None, 'verbose', |
| 126 | 126 | 'The reporter to use for this test run. See --help-reporters for ' |
| 127 | | 'more info.']] |
| | 127 | 'more info.'], |
| | 128 | ['timeout', 't', util.DEFAULT_TIMEOUT_DURATION, |
| | 129 | 'The default timeout in seconds. You can use the value 0 for no ' |
| | 130 | 'timeout but this may cause your tests to hang.', float]] |
| 128 | 131 | |
| 129 | 132 | zsh_actions = {"tbformat":"(plain emacs cgitb)", |
| 130 | 133 | "reporter":_zshReporterAction} |
| … |
… |
|
| 302 | 305 | print 'Running tests shuffled with seed %d\n' % config['random'] |
| 303 | 306 | if not config['until-failure']: |
| 304 | 307 | loader.suiteFactory = runner.DestructiveTestSuite |
| | 308 | if config['timeout']: |
| | 309 | loader.suiteFactory.defaultTimeout = config['timeout'] |
| 305 | 310 | return loader |
| 306 | 311 | |
| 307 | 312 | |
=== modified file 'twisted/trial/runner.py'
|
|
|
|
| 135 | 135 | if result.shouldStop: |
| 136 | 136 | break |
| 137 | 137 | test = self._tests.pop(0) |
| | 138 | self.suggestTimeout(test) |
| 138 | 139 | test(result) |
| 139 | 140 | return result |
| 140 | 141 | |
=== modified file 'twisted/trial/test/test_deferred.py'
|
|
|
|
| 85 | 85 | self.failUnless(result.errors[0][1].check(defer.TimeoutError)) |
| 86 | 86 | |
| 87 | 87 | |
| | 88 | test_setUp.skip = ("I don't think this test is relevant as an " |
| | 89 | "outcome of #2675. No?") |
| | 90 | |
| 88 | 91 | class TestTester(unittest.TestCase): |
| 89 | 92 | def getTest(self, name): |
| 90 | 93 | raise NotImplementedError("must override me") |
=== modified file 'twisted/trial/test/test_runner.py'
|
|
|
|
| 487 | 487 | self.assertEqual(['runcall'], debugger._calls) |
| 488 | 488 | |
| 489 | 489 | |
| | 490 | def test_defaultTimeout(self): |
| | 491 | self.parseOptions(['--timeout', '25', 'twisted.trial.test.sample']) |
| | 492 | my_runner = self.getRunner() |
| | 493 | suite = trial._getSuite(self.config) |
| | 494 | tests = [] |
| | 495 | # gather references to any unittest.TestCase in the suite |
| | 496 | for destrsuite in suite._tests[0]._tests: |
| | 497 | tests.extend([ t for t in destrsuite._tests |
| | 498 | if isinstance(t, unittest.TestCase) ]) |
| | 499 | first_test = tests[0] |
| | 500 | first_test.timeout = 1 |
| | 501 | second_test = tests[1] |
| | 502 | second_test.timeout = 'orange' |
| | 503 | tests = tests[2:] |
| | 504 | result = my_runner.run(suite) |
| | 505 | self.assertEquals(first_test.timeout, 1) |
| | 506 | self.assertEquals(second_test.timeout, 'orange') |
| | 507 | for test in tests: |
| | 508 | self.assertEquals(test.timeout, 25) |
| | 509 | self.flushWarnings() |
| 490 | 510 | |
| 491 | 511 | class RemoveSafelyTests(unittest.TestCase): |
| 492 | 512 | """ |
=== modified file 'twisted/trial/test/test_script.py'
|
|
|
|
| 414 | 414 | options = trial.Options() |
| 415 | 415 | options.parseOptions(["--coverage"]) |
| 416 | 416 | self.assertEquals(sys.gettrace(), options.tracer.globaltrace) |
| | 417 | |
| | 418 | |
| | 419 | class DefaultTimeoutTests(unittest.TestCase): |
| | 420 | """ |
| | 421 | Test for C{--timeout} argument. |
| | 422 | """ |
| | 423 | |
| | 424 | def test_defaultTimeoutSetOnSuiteFactory(self): |
| | 425 | """ |
| | 426 | Test C{--timeout} argument results in defaultTimeout being set |
| | 427 | on the loaded C{suiteFactory}. |
| | 428 | """ |
| | 429 | options = trial.Options() |
| | 430 | options.parseOptions(["--timeout", "20"]) |
| | 431 | loader = trial._getLoader(options) |
| | 432 | self.assertEquals(loader.suiteFactory.defaultTimeout, 20) |
| | 433 | |
=== modified file 'twisted/trial/test/test_warning.py'
|
|
|
|
| 176 | 176 | originalWarnings = warnings.filters[:] |
| 177 | 177 | try: |
| 178 | 178 | warnings.simplefilter('error') |
| | 179 | case.suggestTimeout(0.1) |
| 179 | 180 | case.run(result) |
| 180 | 181 | self.assertEqual(len(result.errors), 1) |
| 181 | 182 | self.assertIdentical(result.errors[0][0], case) |
| … |
… |
|
| 200 | 201 | originalWarnings = warnings.filters[:] |
| 201 | 202 | try: |
| 202 | 203 | warnings.simplefilter('error') |
| | 204 | case.suggestTimeout(0.1) |
| 203 | 205 | case.run(result) |
| 204 | 206 | self.assertEqual(result.errors, []) |
| 205 | 207 | finally: |
=== modified file 'twisted/trial/unittest.py'
|
|
|
|
| 726 | 726 | result.addExpectedFailure(self, f, todo) |
| 727 | 727 | else: |
| 728 | 728 | result.addError(self, f) |
| 729 | | onTimeout = utils.suppressWarnings( |
| 730 | | onTimeout, util.suppress(category=DeprecationWarning)) |
| 731 | 729 | method = getattr(self, methodName) |
| 732 | 730 | d = defer.maybeDeferred(utils.runWithWarningsSuppressed, |
| 733 | 731 | self.getSuppress(), method) |
| 734 | | call = reactor.callLater(timeout, onTimeout, d) |
| 735 | | d.addBoth(lambda x : call.active() and call.cancel() or x) |
| | 732 | # If a timeout is not explicitly given we let the test hang |
| | 733 | if timeout is not None: |
| | 734 | onTimeout = utils.suppressWarnings( |
| | 735 | onTimeout, util.suppress(category=DeprecationWarning)) |
| | 736 | call = reactor.callLater(timeout, onTimeout, d) |
| | 737 | d.addBoth(lambda x : call.active() and call.cancel() or x) |
| 736 | 738 | return d |
| 737 | 739 | |
| 738 | 740 | def shortDescription(self): |
| … |
… |
|
| 1150 | 1152 | """ |
| 1151 | 1153 | Returns the timeout value set on this test. Checks on the instance |
| 1152 | 1154 | first, then the class, then the module, then packages. As soon as it |
| 1153 | | finds something with a C{timeout} attribute, returns that. Returns |
| 1154 | | L{util.DEFAULT_TIMEOUT_DURATION} if it cannot find anything. See |
| 1155 | | L{TestCase} docstring for more details. |
| | 1155 | finds something with a C{timeout} attribute, returns that. If it |
| | 1156 | cannot find any value for timeout, then C{None} is returned which may |
| | 1157 | result in a test hang. A default timeout may be set on via the |
| | 1158 | L{suggestTimeout} method. See L{TestCase} docstring for more details. |
| 1156 | 1159 | """ |
| 1157 | | timeout = util.acquireAttribute(self._parents, 'timeout', |
| 1158 | | util.DEFAULT_TIMEOUT_DURATION) |
| | 1160 | timeout = util.acquireAttribute(self._parents, 'timeout', None) |
| 1159 | 1161 | try: |
| 1160 | 1162 | return float(timeout) |
| 1161 | 1163 | except (ValueError, TypeError): |
| … |
… |
|
| 1165 | 1167 | # both do this. |
| 1166 | 1168 | warnings.warn("'timeout' attribute needs to be a number.", |
| 1167 | 1169 | category=DeprecationWarning) |
| 1168 | | return util.DEFAULT_TIMEOUT_DURATION |
| | 1170 | |
| | 1171 | def suggestTimeout(self, timeout): |
| | 1172 | """ |
| | 1173 | Suggest the timeout for this L{TestCase}. If C{timeout} is C{None} |
| | 1174 | this method is a noop. Also, if the current C{TestCase} already |
| | 1175 | supplies a non-C{None} timeout value, this method is a noop. Otherwise |
| | 1176 | the given C{timeout} will be set on this instance. |
| | 1177 | """ |
| | 1178 | if timeout is None: |
| | 1179 | return |
| | 1180 | test_timeout = util.acquireAttribute(self._parents, 'timeout', None) |
| | 1181 | if test_timeout is None: |
| | 1182 | self.timeout = timeout |
| 1169 | 1183 | |
| 1170 | 1184 | def getSuppress(self): |
| 1171 | 1185 | """ |
| … |
… |
|
| 1369 | 1383 | class TestSuite(pyunit.TestSuite): |
| 1370 | 1384 | """ |
| 1371 | 1385 | Extend the standard library's C{TestSuite} with support for the visitor |
| 1372 | | pattern and a consistently overrideable C{run} method. |
| | 1386 | pattern and a consistently overrideable C{run} method. This also supplies |
| | 1387 | C{defaultTimeout} which can be applied to instances of |
| | 1388 | L{twisted.trial.unittest.TestCase}. |
| 1373 | 1389 | """ |
| 1374 | 1390 | |
| 1375 | 1391 | visit = suiteVisit |
| | 1392 | defaultTimeout = None |
| 1376 | 1393 | |
| 1377 | 1394 | def __call__(self, result): |
| 1378 | 1395 | return self.run(result) |
| … |
… |
|
| 1387 | 1404 | for test in self._tests: |
| 1388 | 1405 | if result.shouldStop: |
| 1389 | 1406 | break |
| | 1407 | self.suggestTimeout(test) |
| 1390 | 1408 | test(result) |
| 1391 | 1409 | return result |
| 1392 | 1410 | |
| | 1411 | def suggestTimeout(self, test): |
| | 1412 | if isinstance(test, TestCase): |
| | 1413 | test.suggestTimeout(self.defaultTimeout) |
| | 1414 | |
| 1393 | 1415 | |
| 1394 | 1416 | |
| 1395 | 1417 | class TestDecorator(components.proxyForInterface(itrial.ITestCase, |