13
13
# along with this program; if not, write to the Free Software
14
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
"""Tests for the test framework
16
"""Tests for the test framework."""
68
67
self.failUnlessExists(filename)
71
class TestSkippedTest(TestCase):
72
"""Try running a test which is skipped, make sure it's reported properly."""
74
def test_skipped_test(self):
75
# skipping_test must be hidden in here so it's not run as a real test
77
raise TestSkipped('test intentionally skipped')
78
runner = TextTestRunner(stream=self._log_file, keep_output=True)
79
test = unittest.FunctionTestCase(skipping_test)
80
old_root = TestCaseInTempDir.TEST_ROOT
82
TestCaseInTempDir.TEST_ROOT = None
83
result = runner.run(test)
85
TestCaseInTempDir.TEST_ROOT = old_root
86
self.assertTrue(result.wasSuccessful())
89
70
class TestTransportProviderAdapter(TestCase):
90
71
"""A group of tests that test the transport implementation adaption core.
465
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
468
465
def test_accepts_and_uses_pb_parameter(self):
469
466
test = TestRunner('dummy_test')
470
467
mypb = MockProgress()
471
468
self.assertEqual([], mypb.calls)
472
runner = TextTestRunner(stream=self._log_file, pb=mypb, keep_output=True)
473
result = runner.run(test)
469
runner = TextTestRunner(stream=self._log_file, pb=mypb)
470
result = self.run_test_runner(runner, test)
474
471
self.assertEqual(1, result.testsRun)
475
472
self.assertEqual(('update', 'Running tests', 0, 1), mypb.calls[0])
476
473
self.assertEqual(('update', '...dummy_test', 0, None), mypb.calls[1])
479
476
self.assertEqual(('clear',), mypb.calls[4])
480
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)
483
529
class TestExtraAssertions(TestCase):
484
530
"""Tests for new test assertions in bzrlib test suite"""