385
372
self.assertEqual(url, t.clone('..').base)
375
class MockProgress(_BaseProgressBar):
376
"""Progress-bar standin that records calls.
378
Useful for testing pb using code.
382
_BaseProgressBar.__init__(self)
386
self.calls.append(('tick',))
388
def update(self, msg=None, current=None, total=None):
389
self.calls.append(('update', msg, current, total))
392
self.calls.append(('clear',))
395
class TestResult(TestCase):
397
def test_progress_bar_style_quiet(self):
398
# test using a progress bar.
399
dummy_test = TestResult('test_progress_bar_style_quiet')
400
dummy_error = (Exception, None, [])
401
mypb = MockProgress()
402
mypb.update('Running tests', 0, 4)
403
last_calls = mypb.calls[:]
404
result = bzrlib.tests._MyResult(self._log_file,
408
self.assertEqual(last_calls, mypb.calls)
411
result.startTest(dummy_test)
412
# starting a test prints the test name
413
self.assertEqual(last_calls + [('update', '...tyle_quiet', 0, None)], mypb.calls)
414
last_calls = mypb.calls[:]
415
result.addError(dummy_test, dummy_error)
416
self.assertEqual(last_calls + [('update', 'ERROR ', 1, None)], mypb.calls)
417
last_calls = mypb.calls[:]
420
result.startTest(dummy_test)
421
self.assertEqual(last_calls + [('update', '...tyle_quiet', 1, None)], mypb.calls)
422
last_calls = mypb.calls[:]
423
result.addFailure(dummy_test, dummy_error)
424
self.assertEqual(last_calls + [('update', 'FAIL ', 2, None)], mypb.calls)
425
last_calls = mypb.calls[:]
428
result.startTest(dummy_test)
429
self.assertEqual(last_calls + [('update', '...tyle_quiet', 2, None)], mypb.calls)
430
last_calls = mypb.calls[:]
431
result.addSuccess(dummy_test)
432
self.assertEqual(last_calls + [('update', 'OK ', 3, None)], mypb.calls)
433
last_calls = mypb.calls[:]
436
result.startTest(dummy_test)
437
self.assertEqual(last_calls + [('update', '...tyle_quiet', 3, None)], mypb.calls)
438
last_calls = mypb.calls[:]
439
result.addSkipped(dummy_test, dummy_error)
440
self.assertEqual(last_calls + [('update', 'SKIP ', 4, None)], mypb.calls)
441
last_calls = mypb.calls[:]
444
class TestRunner(TestCase):
446
def dummy_test(self):
449
def run_test_runner(self, testrunner, test):
450
"""Run suite in testrunner, saving global state and restoring it.
452
This current saves and restores:
453
TestCaseInTempDir.TEST_ROOT
455
There should be no tests in this file that use bzrlib.tests.TextTestRunner
456
without using this convenience method, because of our use of global state.
458
old_root = TestCaseInTempDir.TEST_ROOT
460
TestCaseInTempDir.TEST_ROOT = None
461
return testrunner.run(test)
463
TestCaseInTempDir.TEST_ROOT = old_root
465
def test_accepts_and_uses_pb_parameter(self):
466
test = TestRunner('dummy_test')
467
mypb = MockProgress()
468
self.assertEqual([], mypb.calls)
469
runner = TextTestRunner(stream=self._log_file, pb=mypb)
470
result = self.run_test_runner(runner, test)
471
self.assertEqual(1, result.testsRun)
472
self.assertEqual(('update', 'Running tests', 0, 1), mypb.calls[0])
473
self.assertEqual(('update', '...dummy_test', 0, None), mypb.calls[1])
474
self.assertEqual(('update', 'OK ', 1, None), mypb.calls[2])
475
self.assertEqual(('update', 'Cleaning up', 0, 1), mypb.calls[3])
476
self.assertEqual(('clear',), mypb.calls[4])
477
self.assertEqual(5, len(mypb.calls))
479
def test_skipped_test(self):
480
# run a test that is skipped, and check the suite as a whole still
482
# skipping_test must be hidden in here so it's not run as a real test
484
raise TestSkipped('test intentionally skipped')
485
runner = TextTestRunner(stream=self._log_file, keep_output=True)
486
test = unittest.FunctionTestCase(skipping_test)
487
result = self.run_test_runner(runner, test)
488
self.assertTrue(result.wasSuccessful())
491
class TestTestCase(TestCase):
492
"""Tests that test the core bzrlib TestCase."""
494
def inner_test(self):
495
# the inner child test
498
def outer_child(self):
499
# the outer child test
501
self.inner_test = TestTestCase("inner_child")
502
result = bzrlib.tests._MyResult(self._log_file,
505
self.inner_test.run(result)
508
def test_trace_nesting(self):
509
# this tests that each test case nests its trace facility correctly.
510
# we do this by running a test case manually. That test case (A)
511
# should setup a new log, log content to it, setup a child case (B),
512
# which should log independently, then case (A) should log a trailer
514
# we do two nested children so that we can verify the state of the
515
# logs after the outer child finishes is correct, which a bad clean
516
# up routine in tearDown might trigger a fault in our test with only
517
# one child, we should instead see the bad result inside our test with
519
# the outer child test
520
original_trace = bzrlib.trace._trace_file
521
outer_test = TestTestCase("outer_child")
522
result = bzrlib.tests._MyResult(self._log_file,
525
outer_test.run(result)
526
self.assertEqual(original_trace, bzrlib.trace._trace_file)
388
529
class TestExtraAssertions(TestCase):
389
530
"""Tests for new test assertions in bzrlib test suite"""