Ticket #2675: 2675-r1.patch
| File 2675-r1.patch, 9.5 KB (added by djfroofy, 2 years ago) |
|---|
-
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 … … 128 128 'Path to use as working directory for tests.'], 129 129 ['reporter', None, 'verbose', 130 130 'The reporter to use for this test run. See --help-reporters for ' 131 'more info.']] 131 'more info.'], 132 ['timeout', 't', util.DEFAULT_TIMEOUT_DURATION, 133 'The default timeout in seconds. You can use the value 0 for no ' 134 'timeout but this may cause your tests to hang.', float]] 132 135 133 136 zsh_actions = {"tbformat":"(plain emacs cgitb)", 134 137 "reporter":_zshReporterAction} … … 338 341 print 'Running tests shuffled with seed %d\n' % config['random'] 339 342 if not config['until-failure']: 340 343 loader.suiteFactory = runner.DestructiveTestSuite 344 if config['timeout']: 345 loader.suiteFactory.defaultTimeout = config['timeout'] 341 346 return loader 342 347 343 348 -
twisted/trial/test/test_script.py
480 480 self.assertDeprecationWarning(self.config.opt_extra, 481 481 self.flushWarnings([self.test_xDeprecation])) 482 482 483 484 class DefaultTimeoutTests(unittest.TestCase): 485 """ 486 Test for C{--timeout} argument. 487 """ 488 489 def test_defaultTimeoutSetOnSuiteFactory(self): 490 """ 491 Test C{--timeout} argument results in defaultTimeout being set 492 on the loaded C{suiteFactory}. 493 """ 494 options = trial.Options() 495 options.parseOptions(["--timeout", "20"]) 496 loader = trial._getLoader(options) 497 self.assertEquals(loader.suiteFactory.defaultTimeout, 20) 498 -
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: -
twisted/trial/test/test_runner.py
490 490 self.assertEqual(['runcall'], debugger._calls) 491 491 492 492 493 def test_defaultTimeout(self): 494 self.parseOptions(['--timeout', '25', 'twisted.trial.test.sample']) 495 my_runner = self.getRunner() 496 suite = trial._getSuite(self.config) 497 tests = [] 498 # gather references to any unittest.TestCase in the suite 499 for destrsuite in suite._tests[0]._tests: 500 tests.extend([ t for t in destrsuite._tests 501 if isinstance(t, unittest.TestCase) ]) 502 first_test = tests[0] 503 first_test.timeout = 1 504 second_test = tests[1] 505 second_test.timeout = 'orange' 506 tests = tests[2:] 507 result = my_runner.run(suite) 508 self.assertEquals(first_test.timeout, 1) 509 self.assertEquals(second_test.timeout, 'orange') 510 for test in tests: 511 self.assertEquals(test.timeout, 25) 512 self.flushWarnings() 493 513 494 514 class RemoveSafelyTests(unittest.TestCase): 495 515 """ -
twisted/trial/test/test_deferred.py
60 60 61 61 62 62 class TestNeverFire(unittest.TestCase): 63 def setUp(self):64 self._oldTimeout = util.DEFAULT_TIMEOUT_DURATION65 util.DEFAULT_TIMEOUT_DURATION = 0.166 63 67 def tearDown(self):68 util.DEFAULT_TIMEOUT_DURATION = self._oldTimeout69 70 64 def _loadSuite(self, klass): 71 65 loader = runner.TestLoader() 72 66 r = reporter.TestResult() 73 67 s = loader.loadClass(klass) 68 s.defaultTimeout = 0.1 74 69 return r, s 75 70 76 71 def test_setUp(self): … … 85 80 self.failUnless(result.errors[0][1].check(defer.TimeoutError)) 86 81 87 82 83 88 84 class TestTester(unittest.TestCase): 89 85 def getTest(self, name): 90 86 raise NotImplementedError("must override me") -
twisted/trial/runner.py
149 149 if result.shouldStop: 150 150 break 151 151 test = self._tests.pop(0) 152 self.suggestTimeout(test) 152 153 test(result) 153 154 return result 154 155 -
twisted/trial/unittest.py
699 699 result.addExpectedFailure(self, f, todo) 700 700 else: 701 701 result.addError(self, f) 702 onTimeout = utils.suppressWarnings(703 onTimeout, util.suppress(category=DeprecationWarning))704 702 method = getattr(self, methodName) 705 703 d = defer.maybeDeferred(utils.runWithWarningsSuppressed, 706 704 self.getSuppress(), method) 707 call = reactor.callLater(timeout, onTimeout, d) 708 d.addBoth(lambda x : call.active() and call.cancel() or x) 705 # If a timeout is not explicitly given we let the test hang 706 if timeout is not None: 707 onTimeout = utils.suppressWarnings( 708 onTimeout, util.suppress(category=DeprecationWarning)) 709 call = reactor.callLater(timeout, onTimeout, d) 710 d.addBoth(lambda x : call.active() and call.cancel() or x) 709 711 return d 710 712 711 713 def shortDescription(self): … … 1154 1156 """ 1155 1157 Returns the timeout value set on this test. Checks on the instance 1156 1158 first, then the class, then the module, then packages. As soon as it 1157 finds something with a C{timeout} attribute, returns that. Returns 1158 L{util.DEFAULT_TIMEOUT_DURATION} if it cannot find anything. See 1159 L{TestCase} docstring for more details. 1159 finds something with a C{timeout} attribute, returns that. If it 1160 cannot find any value for timeout, then C{None} is returned which may 1161 result in a test hang. A default timeout may be set on via the 1162 L{suggestTimeout} method. See L{TestCase} docstring for more details. 1160 1163 """ 1161 timeout = util.acquireAttribute(self._parents, 'timeout', 1162 util.DEFAULT_TIMEOUT_DURATION) 1164 timeout = util.acquireAttribute(self._parents, 'timeout', None) 1165 if timeout is None: 1166 return 1163 1167 try: 1164 1168 return float(timeout) 1165 1169 except (ValueError, TypeError): … … 1169 1173 # both do this. 1170 1174 warnings.warn("'timeout' attribute needs to be a number.", 1171 1175 category=DeprecationWarning) 1172 return util.DEFAULT_TIMEOUT_DURATION1173 1176 1177 def suggestTimeout(self, timeout): 1178 """ 1179 Suggest the timeout for this L{TestCase}. If C{timeout} is C{None} 1180 this method is a noop. Also, if the current C{TestCase} already 1181 supplies a non-C{None} timeout value, this method is a noop. Otherwise 1182 the given C{timeout} will be set on this instance. 1183 """ 1184 if timeout is None: 1185 return 1186 test_timeout = util.acquireAttribute(self._parents, 'timeout', None) 1187 if test_timeout is None: 1188 self.timeout = timeout 1189 1174 1190 def getSuppress(self): 1175 1191 """ 1176 1192 Returns any warning suppressions set for this test. Checks on the … … 1373 1389 class TestSuite(pyunit.TestSuite): 1374 1390 """ 1375 1391 Extend the standard library's C{TestSuite} with support for the visitor 1376 pattern and a consistently overrideable C{run} method. 1392 pattern and a consistently overrideable C{run} method. This also supplies 1393 C{defaultTimeout} which can be applied to instances of 1394 L{twisted.trial.unittest.TestCase}. 1377 1395 """ 1378 1396 1379 1397 visit = suiteVisit 1398 defaultTimeout = None 1380 1399 1381 1400 def __call__(self, result): 1382 1401 return self.run(result) … … 1391 1410 for test in self._tests: 1392 1411 if result.shouldStop: 1393 1412 break 1413 if self.defaultTimeout: 1414 self.suggestTimeout(test) 1394 1415 test(result) 1395 1416 return result 1396 1417 1418 def suggestTimeout(self, test): 1419 if isinstance(test, TestCase): 1420 test.suggestTimeout(self.defaultTimeout) 1397 1421 1398 1422 1423 1399 1424 class TestDecorator(components.proxyForInterface(itrial.ITestCase, 1400 1425 "_originalTest")): 1401 1426 """
