##// END OF EJS Templates
run-tests: merge MercurialTest into Test...
Gregory Szorc -
r21488:feb8ad2d default
parent child Browse files
Show More
@@ -327,7 +327,7 b' def killdaemons(pidfile):'
327 return killmod.killdaemons(pidfile, tryhard=False, remove=True,
327 return killmod.killdaemons(pidfile, tryhard=False, remove=True,
328 logfn=vlog)
328 logfn=vlog)
329
329
330 class Test(object):
330 class Test(unittest.TestCase):
331 """Encapsulates a single, runnable test.
331 """Encapsulates a single, runnable test.
332
332
333 Test instances can be run multiple times via run(). However, multiple
333 Test instances can be run multiple times via run(). However, multiple
@@ -386,6 +386,9 b' class Test(object):'
386 def __str__(self):
386 def __str__(self):
387 return self.name
387 return self.name
388
388
389 def shortDescription(self):
390 return self.name
391
389 def setUp(self):
392 def setUp(self):
390 """Tasks to perform before run()."""
393 """Tasks to perform before run()."""
391 self._finished = False
394 self._finished = False
@@ -403,7 +406,53 b' class Test(object):'
403 if os.path.exists(self._errpath):
406 if os.path.exists(self._errpath):
404 os.remove(self._errpath)
407 os.remove(self._errpath)
405
408
406 def run(self):
409 def run(self, result):
410 result.startTest(self)
411 try:
412 try:
413 self.setUp()
414 except (KeyboardInterrupt, SystemExit):
415 raise
416 except Exception:
417 result.addError(self, sys.exc_info())
418 return
419
420 success = False
421 try:
422 self.runTest()
423 except KeyboardInterrupt:
424 raise
425 except SkipTest, e:
426 result.addSkip(self, str(e))
427 except IgnoreTest, e:
428 result.addIgnore(self, str(e))
429 except WarnTest, e:
430 result.addWarn(self, str(e))
431 except self.failureException, e:
432 # This differs from unittest in that we don't capture
433 # the stack trace. This is for historical reasons and
434 # this decision could be revisted in the future,
435 # especially for PythonTest instances.
436 result.addFailure(self, str(e))
437 except Exception:
438 result.addError(self, sys.exc_info())
439 else:
440 success = True
441
442 try:
443 self.tearDown()
444 except (KeyboardInterrupt, SystemExit):
445 raise
446 except Exception:
447 result.addError(self, sys.exc_info())
448 success = False
449
450 if success:
451 result.addSuccess(self)
452 finally:
453 result.stopTest(self)
454
455 def runTest(self):
407 """Run this test instance.
456 """Run this test instance.
408
457
409 This will return a tuple describing the result of the test.
458 This will return a tuple describing the result of the test.
@@ -1382,72 +1431,7 b' class TestRunner(object):'
1382 refpath = os.path.join(self.testdir, test + out)
1431 refpath = os.path.join(self.testdir, test + out)
1383 break
1432 break
1384
1433
1385 t = testcls(self, test, count, refpath)
1434 return testcls(self, test, count, refpath)
1386
1387 class MercurialTest(unittest.TestCase):
1388 def __init__(self, name, *args, **kwargs):
1389 super(MercurialTest, self).__init__(*args, **kwargs)
1390 self.name = name
1391
1392 def shortDescription(self):
1393 return self.name
1394
1395 # Need to stash away the TestResult since we do custom things
1396 # with it.
1397 def run(self, result):
1398 result.startTest(self)
1399 try:
1400 try:
1401 t.setUp()
1402 except (KeyboardInterrupt, SystemExit):
1403 raise
1404 except Exception:
1405 result.addError(self, sys.exc_info())
1406 return
1407
1408 success = False
1409 try:
1410 self.runTest()
1411 except KeyboardInterrupt:
1412 raise
1413 except SkipTest, e:
1414 result.addSkip(self, str(e))
1415 except IgnoreTest, e:
1416 result.addIgnore(self, str(e))
1417 except WarnTest, e:
1418 result.addWarn(self, str(e))
1419 except self.failureException, e:
1420 # This differs from unittest in that we don't capture
1421 # the stack trace. This is for historical reasons and
1422 # this decision could be revisted in the future,
1423 # especially for PythonTest instances.
1424 result.addFailure(self, str(e))
1425 except Exception:
1426 result.addError(self, sys.exc_info())
1427 else:
1428 success = True
1429
1430 try:
1431 t.tearDown()
1432 except (KeyboardInterrupt, SystemExit):
1433 raise
1434 except Exception:
1435 result.addError(self, sys.exc_info())
1436 success = False
1437
1438 if success:
1439 result.addSuccess(self)
1440 finally:
1441 result.stopTest(self)
1442
1443 def runTest(self):
1444 t.run()
1445
1446 # We need this proxy until tearDown() is implemented.
1447 def cleanup(self):
1448 return t.cleanup()
1449
1450 return MercurialTest(test)
1451
1435
1452 def _cleanup(self):
1436 def _cleanup(self):
1453 """Clean up state from this test invocation."""
1437 """Clean up state from this test invocation."""
General Comments 0
You need to be logged in to leave comments. Login now