~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-07-01 15:54:56 UTC
  • mfrom: (4498.2.1 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090701155456-4qodruyp94l2p4ag
(vila)(trivial) Fix test_selftest.py imports

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests for the test framework."""
18
18
 
19
 
import cStringIO
 
19
from cStringIO import StringIO
20
20
import os
21
 
from StringIO import StringIO
22
21
import sys
23
22
import time
24
23
import unittest
33
32
    lockdir,
34
33
    memorytree,
35
34
    osutils,
 
35
    progress,
36
36
    remote,
37
37
    repository,
38
38
    symbol_versioning,
39
39
    tests,
40
40
    workingtree,
41
41
    )
42
 
from bzrlib.progress import _BaseProgressBar
43
42
from bzrlib.repofmt import (
44
43
    pack_repo,
45
44
    weaverepo,
50
49
    deprecated_method,
51
50
    )
52
51
from bzrlib.tests import (
53
 
                          ChrootedTestCase,
54
 
                          ExtendedTestResult,
55
 
                          Feature,
56
 
                          KnownFailure,
57
 
                          TestCase,
58
 
                          TestCaseInTempDir,
59
 
                          TestCaseWithMemoryTransport,
60
 
                          TestCaseWithTransport,
61
 
                          TestNotApplicable,
62
 
                          TestSkipped,
63
 
                          TestSuite,
64
 
                          TestUtil,
65
 
                          TextTestRunner,
66
 
                          UnavailableFeature,
67
 
                          condition_id_re,
68
 
                          condition_isinstance,
69
 
                          exclude_tests_by_condition,
70
 
                          exclude_tests_by_re,
71
 
                          filter_suite_by_condition,
72
 
                          filter_suite_by_re,
73
 
                          iter_suite_tests,
74
 
                          preserve_input,
75
 
                          randomize_suite,
76
 
                          run_suite,
77
 
                          split_suite_by_condition,
78
 
                          split_suite_by_re,
79
 
                          test_lsprof,
80
 
                          test_suite,
81
 
                          )
82
 
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
83
 
from bzrlib.tests.TestUtil import _load_module_by_name
 
52
    test_lsprof,
 
53
    test_sftp_transport,
 
54
    TestUtil,
 
55
    )
84
56
from bzrlib.trace import note
85
57
from bzrlib.transport.memory import MemoryServer, MemoryTransport
86
58
from bzrlib.version import _get_bzr_source_tree
88
60
 
89
61
def _test_ids(test_suite):
90
62
    """Get the ids for the tests in a test suite."""
91
 
    return [t.id() for t in iter_suite_tests(test_suite)]
92
 
 
93
 
 
94
 
class SelftestTests(TestCase):
 
63
    return [t.id() for t in tests.iter_suite_tests(test_suite)]
 
64
 
 
65
 
 
66
class SelftestTests(tests.TestCase):
95
67
 
96
68
    def test_import_tests(self):
97
 
        mod = _load_module_by_name('bzrlib.tests.test_selftest')
 
69
        mod = TestUtil._load_module_by_name('bzrlib.tests.test_selftest')
98
70
        self.assertEqual(mod.SelftestTests, SelftestTests)
99
71
 
100
72
    def test_import_test_failure(self):
101
73
        self.assertRaises(ImportError,
102
 
                          _load_module_by_name,
 
74
                          TestUtil._load_module_by_name,
103
75
                          'bzrlib.no-name-yet')
104
76
 
105
 
class MetaTestLog(TestCase):
 
77
class MetaTestLog(tests.TestCase):
106
78
 
107
79
    def test_logging(self):
108
80
        """Test logs are captured when a test fails."""
112
84
                              'a test message\n')
113
85
 
114
86
 
115
 
class TestUnicodeFilename(TestCase):
 
87
class TestUnicodeFilename(tests.TestCase):
116
88
 
117
89
    def test_probe_passes(self):
118
90
        """UnicodeFilename._probe passes."""
121
93
        tests.UnicodeFilename._probe()
122
94
 
123
95
 
124
 
class TestTreeShape(TestCaseInTempDir):
 
96
class TestTreeShape(tests.TestCaseInTempDir):
125
97
 
126
98
    def test_unicode_paths(self):
127
99
        self.requireFeature(tests.UnicodeFilename)
131
103
        self.failUnlessExists(filename)
132
104
 
133
105
 
134
 
class TestTransportScenarios(TestCase):
 
106
class TestTransportScenarios(tests.TestCase):
135
107
    """A group of tests that test the transport implementation adaption core.
136
108
 
137
109
    This is a meta test that the tests are applied to all available
190
162
                                   bzrlib.transport.Server))
191
163
 
192
164
 
193
 
class TestBranchScenarios(TestCase):
 
165
class TestBranchScenarios(tests.TestCase):
194
166
 
195
167
    def test_scenarios(self):
196
168
        # check that constructor parameters are passed through to the adapted
215
187
            scenarios)
216
188
 
217
189
 
218
 
class TestBzrDirScenarios(TestCase):
 
190
class TestBzrDirScenarios(tests.TestCase):
219
191
 
220
192
    def test_scenarios(self):
221
193
        # check that constructor parameters are passed through to the adapted
240
212
            scenarios)
241
213
 
242
214
 
243
 
class TestRepositoryScenarios(TestCase):
 
215
class TestRepositoryScenarios(tests.TestCase):
244
216
 
245
217
    def test_formats_to_scenarios(self):
246
218
        from bzrlib.tests.per_repository import formats_to_scenarios
280
252
            vfs_scenarios)
281
253
 
282
254
 
283
 
class TestTestScenarioApplication(TestCase):
 
255
class TestTestScenarioApplication(tests.TestCase):
284
256
    """Tests for the test adaption facilities."""
285
257
 
286
258
    def test_apply_scenario(self):
316
288
            adapted_test2.id())
317
289
 
318
290
 
319
 
class TestInterRepositoryScenarios(TestCase):
 
291
class TestInterRepositoryScenarios(tests.TestCase):
320
292
 
321
293
    def test_scenarios(self):
322
294
        # check that constructor parameters are passed through to the adapted
343
315
            scenarios)
344
316
 
345
317
 
346
 
class TestWorkingTreeScenarios(TestCase):
 
318
class TestWorkingTreeScenarios(tests.TestCase):
347
319
 
348
320
    def test_scenarios(self):
349
321
        # check that constructor parameters are passed through to the adapted
369
341
            scenarios)
370
342
 
371
343
 
372
 
class TestTreeScenarios(TestCase):
 
344
class TestTreeScenarios(tests.TestCase):
373
345
 
374
346
    def test_scenarios(self):
375
347
        # the tree implementation scenario generator is meant to setup one
448
420
        self.assertEqual(expected_scenarios, scenarios)
449
421
 
450
422
 
451
 
class TestInterTreeScenarios(TestCase):
 
423
class TestInterTreeScenarios(tests.TestCase):
452
424
    """A group of tests that test the InterTreeTestAdapter."""
453
425
 
454
426
    def test_scenarios(self):
504
476
        self.assertEqual(scenarios, expected_scenarios)
505
477
 
506
478
 
507
 
class TestTestCaseInTempDir(TestCaseInTempDir):
 
479
class TestTestCaseInTempDir(tests.TestCaseInTempDir):
508
480
 
509
481
    def test_home_is_not_working(self):
510
482
        self.assertNotEqual(self.test_dir, self.test_home_dir)
526
498
            os.lstat("foo"), os.lstat("bar"))
527
499
 
528
500
 
529
 
class TestTestCaseWithMemoryTransport(TestCaseWithMemoryTransport):
 
501
class TestTestCaseWithMemoryTransport(tests.TestCaseWithMemoryTransport):
530
502
 
531
503
    def test_home_is_non_existant_dir_under_root(self):
532
504
        """The test_home_dir for TestCaseWithMemoryTransport is missing.
622
594
        self.assertRaises(AssertionError, self._check_safety_net)
623
595
 
624
596
    def test_dangling_locks_cause_failures(self):
625
 
        class TestDanglingLock(TestCaseWithMemoryTransport):
 
597
        class TestDanglingLock(tests.TestCaseWithMemoryTransport):
626
598
            def test_function(self):
627
599
                t = self.get_transport('.')
628
600
                l = lockdir.LockDir(t, 'lock')
633
605
        self.assertEqual(1, len(result.errors))
634
606
 
635
607
 
636
 
class TestTestCaseWithTransport(TestCaseWithTransport):
 
608
class TestTestCaseWithTransport(tests.TestCaseWithTransport):
637
609
    """Tests for the convenience functions TestCaseWithTransport introduces."""
638
610
 
639
611
    def test_get_readonly_url_none(self):
690
662
        self.assertEqual((1, rev_id), a_branch.last_revision_info())
691
663
 
692
664
 
693
 
class TestTestCaseTransports(TestCaseWithTransport):
 
665
class TestTestCaseTransports(tests.TestCaseWithTransport):
694
666
 
695
667
    def setUp(self):
696
668
        super(TestTestCaseTransports, self).setUp()
705
677
        self.failIfExists('subdir')
706
678
 
707
679
 
708
 
class TestChrootedTest(ChrootedTestCase):
 
680
class TestChrootedTest(tests.ChrootedTestCase):
709
681
 
710
682
    def test_root_is_root(self):
711
683
        from bzrlib.transport import get_transport
714
686
        self.assertEqual(url, t.clone('..').base)
715
687
 
716
688
 
717
 
class MockProgress(_BaseProgressBar):
 
689
class MockProgress(progress._BaseProgressBar):
718
690
    """Progress-bar standin that records calls.
719
691
 
720
692
    Useful for testing pb using code.
721
693
    """
722
694
 
723
695
    def __init__(self):
724
 
        _BaseProgressBar.__init__(self)
 
696
        progress._BaseProgressBar.__init__(self)
725
697
        self.calls = []
726
698
 
727
699
    def tick(self):
737
709
        self.calls.append(('note', msg, args))
738
710
 
739
711
 
740
 
class TestTestResult(TestCase):
 
712
class TestTestResult(tests.TestCase):
741
713
 
742
714
    def check_timing(self, test_case, expected_re):
743
715
        result = bzrlib.tests.TextTestResult(self._log_file,
749
721
        self.assertContainsRe(timed_string, expected_re)
750
722
 
751
723
    def test_test_reporting(self):
752
 
        class ShortDelayTestCase(TestCase):
 
724
        class ShortDelayTestCase(tests.TestCase):
753
725
            def test_short_delay(self):
754
726
                time.sleep(0.003)
755
727
            def test_short_benchmark(self):
848
820
 
849
821
    def test_known_failure(self):
850
822
        """A KnownFailure being raised should trigger several result actions."""
851
 
        class InstrumentedTestResult(ExtendedTestResult):
 
823
        class InstrumentedTestResult(tests.ExtendedTestResult):
852
824
            def done(self): pass
853
825
            def startTests(self): pass
854
826
            def report_test_start(self, test): pass
856
828
                self._call = test, err
857
829
        result = InstrumentedTestResult(None, None, None, None)
858
830
        def test_function():
859
 
            raise KnownFailure('failed!')
 
831
            raise tests.KnownFailure('failed!')
860
832
        test = unittest.FunctionTestCase(test_function)
861
833
        test.run(result)
862
834
        # it should invoke 'report_known_failure'.
863
835
        self.assertEqual(2, len(result._call))
864
836
        self.assertEqual(test, result._call[0])
865
 
        self.assertEqual(KnownFailure, result._call[1][0])
866
 
        self.assertIsInstance(result._call[1][1], KnownFailure)
 
837
        self.assertEqual(tests.KnownFailure, result._call[1][0])
 
838
        self.assertIsInstance(result._call[1][1], tests.KnownFailure)
867
839
        # we dont introspec the traceback, if the rest is ok, it would be
868
840
        # exceptional for it not to be.
869
841
        # it should update the known_failure_count on the object.
886
858
        # (class, exception object, traceback)
887
859
        # KnownFailures dont get their tracebacks shown though, so we
888
860
        # can skip that.
889
 
        err = (KnownFailure, KnownFailure('foo'), None)
 
861
        err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
890
862
        result.report_known_failure(test, err)
891
863
        output = result_stream.getvalue()[prefix:]
892
864
        lines = output.splitlines()
910
882
        # (class, exception object, traceback)
911
883
        # KnownFailures dont get their tracebacks shown though, so we
912
884
        # can skip that.
913
 
        err = (KnownFailure, KnownFailure('foo'), None)
 
885
        err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
914
886
        result.report_known_failure(test, err)
915
887
        self.assertEqual(
916
888
            [
937
909
 
938
910
    def test_add_not_supported(self):
939
911
        """Test the behaviour of invoking addNotSupported."""
940
 
        class InstrumentedTestResult(ExtendedTestResult):
 
912
        class InstrumentedTestResult(tests.ExtendedTestResult):
941
913
            def done(self): pass
942
914
            def startTests(self): pass
943
915
            def report_test_start(self, test): pass
945
917
                self._call = test, feature
946
918
        result = InstrumentedTestResult(None, None, None, None)
947
919
        test = SampleTestCase('_test_pass')
948
 
        feature = Feature()
 
920
        feature = tests.Feature()
949
921
        result.startTest(test)
950
922
        result.addNotSupported(test, feature)
951
923
        # it should invoke 'report_unsupported'.
970
942
            verbosity=2,
971
943
            )
972
944
        test = self.get_passing_test()
973
 
        feature = Feature()
 
945
        feature = tests.Feature()
974
946
        result.startTest(test)
975
947
        prefix = len(result_stream.getvalue())
976
948
        result.report_unsupported(test, feature)
977
949
        output = result_stream.getvalue()[prefix:]
978
950
        lines = output.splitlines()
979
 
        self.assertEqual(lines, ['NODEP                   0ms', "    The feature 'Feature' is not available."])
 
951
        self.assertEqual(lines, ['NODEP                   0ms',
 
952
                                 "    The feature 'Feature' is not available."])
980
953
 
981
954
    def test_text_report_unsupported(self):
982
955
        # text test output formatting
988
961
            pb=pb,
989
962
            )
990
963
        test = self.get_passing_test()
991
 
        feature = Feature()
 
964
        feature = tests.Feature()
992
965
        # this seeds the state to handle reporting the test.
993
966
        result.startTest(test)
994
967
        result.report_unsupported(test, feature)
1009
982
 
1010
983
    def test_unavailable_exception(self):
1011
984
        """An UnavailableFeature being raised should invoke addNotSupported."""
1012
 
        class InstrumentedTestResult(ExtendedTestResult):
 
985
        class InstrumentedTestResult(tests.ExtendedTestResult):
1013
986
            def done(self): pass
1014
987
            def startTests(self): pass
1015
988
            def report_test_start(self, test): pass
1016
989
            def addNotSupported(self, test, feature):
1017
990
                self._call = test, feature
1018
991
        result = InstrumentedTestResult(None, None, None, None)
1019
 
        feature = Feature()
 
992
        feature = tests.Feature()
1020
993
        def test_function():
1021
 
            raise UnavailableFeature(feature)
 
994
            raise tests.UnavailableFeature(feature)
1022
995
        test = unittest.FunctionTestCase(test_function)
1023
996
        test.run(result)
1024
997
        # it should invoke 'addNotSupported'.
1041
1014
        result = bzrlib.tests.TextTestResult(self._log_file, descriptions=0,
1042
1015
                                             verbosity=1)
1043
1016
        test = self.get_passing_test()
1044
 
        err = (KnownFailure, KnownFailure('foo'), None)
 
1017
        err = (tests.KnownFailure, tests.KnownFailure('foo'), None)
1045
1018
        result._addKnownFailure(test, err)
1046
1019
        self.assertFalse(result.wasStrictlySuccessful())
1047
1020
        self.assertEqual(None, result._extractBenchmarkTime(test))
1056
1029
 
1057
1030
    def test_startTests(self):
1058
1031
        """Starting the first test should trigger startTests."""
1059
 
        class InstrumentedTestResult(ExtendedTestResult):
 
1032
        class InstrumentedTestResult(tests.ExtendedTestResult):
1060
1033
            calls = 0
1061
1034
            def startTests(self): self.calls += 1
1062
1035
            def report_test_start(self, test): pass
1068
1041
        self.assertEquals(1, result.calls)
1069
1042
 
1070
1043
 
1071
 
class TestUnicodeFilenameFeature(TestCase):
 
1044
class TestUnicodeFilenameFeature(tests.TestCase):
1072
1045
 
1073
1046
    def test_probe_passes(self):
1074
1047
        """UnicodeFilenameFeature._probe passes."""
1077
1050
        tests.UnicodeFilenameFeature._probe()
1078
1051
 
1079
1052
 
1080
 
class TestRunner(TestCase):
 
1053
class TestRunner(tests.TestCase):
1081
1054
 
1082
1055
    def dummy_test(self):
1083
1056
        pass
1088
1061
        This current saves and restores:
1089
1062
        TestCaseInTempDir.TEST_ROOT
1090
1063
 
1091
 
        There should be no tests in this file that use bzrlib.tests.TextTestRunner
1092
 
        without using this convenience method, because of our use of global state.
 
1064
        There should be no tests in this file that use
 
1065
        bzrlib.tests.TextTestRunner without using this convenience method,
 
1066
        because of our use of global state.
1093
1067
        """
1094
 
        old_root = TestCaseInTempDir.TEST_ROOT
 
1068
        old_root = tests.TestCaseInTempDir.TEST_ROOT
1095
1069
        try:
1096
 
            TestCaseInTempDir.TEST_ROOT = None
 
1070
            tests.TestCaseInTempDir.TEST_ROOT = None
1097
1071
            return testrunner.run(test)
1098
1072
        finally:
1099
 
            TestCaseInTempDir.TEST_ROOT = old_root
 
1073
            tests.TestCaseInTempDir.TEST_ROOT = old_root
1100
1074
 
1101
1075
    def test_known_failure_failed_run(self):
1102
1076
        # run a test that generates a known failure which should be printed in
1103
1077
        # the final output when real failures occur.
1104
1078
        def known_failure_test():
1105
 
            raise KnownFailure('failed')
 
1079
            raise tests.KnownFailure('failed')
1106
1080
        test = unittest.TestSuite()
1107
1081
        test.addTest(unittest.FunctionTestCase(known_failure_test))
1108
1082
        def failing_test():
1109
1083
            raise AssertionError('foo')
1110
1084
        test.addTest(unittest.FunctionTestCase(failing_test))
1111
1085
        stream = StringIO()
1112
 
        runner = TextTestRunner(stream=stream)
 
1086
        runner = tests.TextTestRunner(stream=stream)
1113
1087
        result = self.run_test_runner(runner, test)
1114
1088
        lines = stream.getvalue().splitlines()
1115
1089
        self.assertEqual([
1129
1103
    def test_known_failure_ok_run(self):
1130
1104
        # run a test that generates a known failure which should be printed in the final output.
1131
1105
        def known_failure_test():
1132
 
            raise KnownFailure('failed')
 
1106
            raise tests.KnownFailure('failed')
1133
1107
        test = unittest.FunctionTestCase(known_failure_test)
1134
1108
        stream = StringIO()
1135
 
        runner = TextTestRunner(stream=stream)
 
1109
        runner = tests.TextTestRunner(stream=stream)
1136
1110
        result = self.run_test_runner(runner, test)
1137
1111
        self.assertContainsRe(stream.getvalue(),
1138
1112
            '\n'
1145
1119
        # run a test that is skipped, and check the suite as a whole still
1146
1120
        # succeeds.
1147
1121
        # skipping_test must be hidden in here so it's not run as a real test
1148
 
        class SkippingTest(TestCase):
 
1122
        class SkippingTest(tests.TestCase):
1149
1123
            def skipping_test(self):
1150
 
                raise TestSkipped('test intentionally skipped')
1151
 
        runner = TextTestRunner(stream=self._log_file)
 
1124
                raise tests.TestSkipped('test intentionally skipped')
 
1125
        runner = tests.TextTestRunner(stream=self._log_file)
1152
1126
        test = SkippingTest("skipping_test")
1153
1127
        result = self.run_test_runner(runner, test)
1154
1128
        self.assertTrue(result.wasSuccessful())
1155
1129
 
1156
1130
    def test_skipped_from_setup(self):
1157
1131
        calls = []
1158
 
        class SkippedSetupTest(TestCase):
 
1132
        class SkippedSetupTest(tests.TestCase):
1159
1133
 
1160
1134
            def setUp(self):
1161
1135
                calls.append('setUp')
1162
1136
                self.addCleanup(self.cleanup)
1163
 
                raise TestSkipped('skipped setup')
 
1137
                raise tests.TestSkipped('skipped setup')
1164
1138
 
1165
1139
            def test_skip(self):
1166
1140
                self.fail('test reached')
1168
1142
            def cleanup(self):
1169
1143
                calls.append('cleanup')
1170
1144
 
1171
 
        runner = TextTestRunner(stream=self._log_file)
 
1145
        runner = tests.TextTestRunner(stream=self._log_file)
1172
1146
        test = SkippedSetupTest('test_skip')
1173
1147
        result = self.run_test_runner(runner, test)
1174
1148
        self.assertTrue(result.wasSuccessful())
1177
1151
 
1178
1152
    def test_skipped_from_test(self):
1179
1153
        calls = []
1180
 
        class SkippedTest(TestCase):
 
1154
        class SkippedTest(tests.TestCase):
1181
1155
 
1182
1156
            def setUp(self):
1183
 
                TestCase.setUp(self)
 
1157
                tests.TestCase.setUp(self)
1184
1158
                calls.append('setUp')
1185
1159
                self.addCleanup(self.cleanup)
1186
1160
 
1187
1161
            def test_skip(self):
1188
 
                raise TestSkipped('skipped test')
 
1162
                raise tests.TestSkipped('skipped test')
1189
1163
 
1190
1164
            def cleanup(self):
1191
1165
                calls.append('cleanup')
1192
1166
 
1193
 
        runner = TextTestRunner(stream=self._log_file)
 
1167
        runner = tests.TextTestRunner(stream=self._log_file)
1194
1168
        test = SkippedTest('test_skip')
1195
1169
        result = self.run_test_runner(runner, test)
1196
1170
        self.assertTrue(result.wasSuccessful())
1200
1174
    def test_not_applicable(self):
1201
1175
        # run a test that is skipped because it's not applicable
1202
1176
        def not_applicable_test():
1203
 
            from bzrlib.tests import TestNotApplicable
1204
 
            raise TestNotApplicable('this test never runs')
 
1177
            raise tests.TestNotApplicable('this test never runs')
1205
1178
        out = StringIO()
1206
 
        runner = TextTestRunner(stream=out, verbosity=2)
 
1179
        runner = tests.TextTestRunner(stream=out, verbosity=2)
1207
1180
        test = unittest.FunctionTestCase(not_applicable_test)
1208
1181
        result = self.run_test_runner(runner, test)
1209
1182
        self._log_file.write(out.getvalue())
1216
1189
 
1217
1190
    def test_not_applicable_demo(self):
1218
1191
        # just so you can see it in the test output
1219
 
        raise TestNotApplicable('this test is just a demonstation')
 
1192
        raise tests.TestNotApplicable('this test is just a demonstation')
1220
1193
 
1221
1194
    def test_unsupported_features_listed(self):
1222
1195
        """When unsupported features are encountered they are detailed."""
1223
 
        class Feature1(Feature):
 
1196
        class Feature1(tests.Feature):
1224
1197
            def _probe(self): return False
1225
 
        class Feature2(Feature):
 
1198
        class Feature2(tests.Feature):
1226
1199
            def _probe(self): return False
1227
1200
        # create sample tests
1228
1201
        test1 = SampleTestCase('_test_pass')
1233
1206
        test.addTest(test1)
1234
1207
        test.addTest(test2)
1235
1208
        stream = StringIO()
1236
 
        runner = TextTestRunner(stream=stream)
 
1209
        runner = tests.TextTestRunner(stream=stream)
1237
1210
        result = self.run_test_runner(runner, test)
1238
1211
        lines = stream.getvalue().splitlines()
1239
1212
        self.assertEqual([
1250
1223
        workingtree = _get_bzr_source_tree()
1251
1224
        test = TestRunner('dummy_test')
1252
1225
        output = StringIO()
1253
 
        runner = TextTestRunner(stream=self._log_file, bench_history=output)
 
1226
        runner = tests.TextTestRunner(stream=self._log_file,
 
1227
                                      bench_history=output)
1254
1228
        result = self.run_test_runner(runner, test)
1255
1229
        output_string = output.getvalue()
1256
1230
        self.assertContainsRe(output_string, "--date [0-9.]+")
1267
1241
    def test_success_log_deleted(self):
1268
1242
        """Successful tests have their log deleted"""
1269
1243
 
1270
 
        class LogTester(TestCase):
 
1244
        class LogTester(tests.TestCase):
1271
1245
 
1272
1246
            def test_success(self):
1273
1247
                self.log('this will be removed\n')
1274
1248
 
1275
 
        sio = cStringIO.StringIO()
1276
 
        runner = TextTestRunner(stream=sio)
 
1249
        sio = StringIO()
 
1250
        runner = tests.TextTestRunner(stream=sio)
1277
1251
        test = LogTester('test_success')
1278
1252
        result = self.run_test_runner(runner, test)
1279
1253
 
1282
1256
    def test_skipped_log_deleted(self):
1283
1257
        """Skipped tests have their log deleted"""
1284
1258
 
1285
 
        class LogTester(TestCase):
 
1259
        class LogTester(tests.TestCase):
1286
1260
 
1287
1261
            def test_skipped(self):
1288
1262
                self.log('this will be removed\n')
1289
1263
                raise tests.TestSkipped()
1290
1264
 
1291
 
        sio = cStringIO.StringIO()
1292
 
        runner = TextTestRunner(stream=sio)
 
1265
        sio = StringIO()
 
1266
        runner = tests.TextTestRunner(stream=sio)
1293
1267
        test = LogTester('test_skipped')
1294
1268
        result = self.run_test_runner(runner, test)
1295
1269
 
1298
1272
    def test_not_aplicable_log_deleted(self):
1299
1273
        """Not applicable tests have their log deleted"""
1300
1274
 
1301
 
        class LogTester(TestCase):
 
1275
        class LogTester(tests.TestCase):
1302
1276
 
1303
1277
            def test_not_applicable(self):
1304
1278
                self.log('this will be removed\n')
1305
1279
                raise tests.TestNotApplicable()
1306
1280
 
1307
 
        sio = cStringIO.StringIO()
1308
 
        runner = TextTestRunner(stream=sio)
 
1281
        sio = StringIO()
 
1282
        runner = tests.TextTestRunner(stream=sio)
1309
1283
        test = LogTester('test_not_applicable')
1310
1284
        result = self.run_test_runner(runner, test)
1311
1285
 
1314
1288
    def test_known_failure_log_deleted(self):
1315
1289
        """Know failure tests have their log deleted"""
1316
1290
 
1317
 
        class LogTester(TestCase):
 
1291
        class LogTester(tests.TestCase):
1318
1292
 
1319
1293
            def test_known_failure(self):
1320
1294
                self.log('this will be removed\n')
1321
1295
                raise tests.KnownFailure()
1322
1296
 
1323
 
        sio = cStringIO.StringIO()
1324
 
        runner = TextTestRunner(stream=sio)
 
1297
        sio = StringIO()
 
1298
        runner = tests.TextTestRunner(stream=sio)
1325
1299
        test = LogTester('test_known_failure')
1326
1300
        result = self.run_test_runner(runner, test)
1327
1301
 
1330
1304
    def test_fail_log_kept(self):
1331
1305
        """Failed tests have their log kept"""
1332
1306
 
1333
 
        class LogTester(TestCase):
 
1307
        class LogTester(tests.TestCase):
1334
1308
 
1335
1309
            def test_fail(self):
1336
1310
                self.log('this will be kept\n')
1337
1311
                self.fail('this test fails')
1338
1312
 
1339
 
        sio = cStringIO.StringIO()
1340
 
        runner = TextTestRunner(stream=sio)
 
1313
        sio = StringIO()
 
1314
        runner = tests.TextTestRunner(stream=sio)
1341
1315
        test = LogTester('test_fail')
1342
1316
        result = self.run_test_runner(runner, test)
1343
1317
 
1352
1326
    def test_error_log_kept(self):
1353
1327
        """Tests with errors have their log kept"""
1354
1328
 
1355
 
        class LogTester(TestCase):
 
1329
        class LogTester(tests.TestCase):
1356
1330
 
1357
1331
            def test_error(self):
1358
1332
                self.log('this will be kept\n')
1359
1333
                raise ValueError('random exception raised')
1360
1334
 
1361
 
        sio = cStringIO.StringIO()
1362
 
        runner = TextTestRunner(stream=sio)
 
1335
        sio = StringIO()
 
1336
        runner = tests.TextTestRunner(stream=sio)
1363
1337
        test = LogTester('test_error')
1364
1338
        result = self.run_test_runner(runner, test)
1365
1339
 
1372
1346
        self.assertEqual(log, test._log_contents)
1373
1347
 
1374
1348
 
1375
 
class SampleTestCase(TestCase):
 
1349
class SampleTestCase(tests.TestCase):
1376
1350
 
1377
1351
    def _test_pass(self):
1378
1352
        pass
1380
1354
class _TestException(Exception):
1381
1355
    pass
1382
1356
 
1383
 
class TestTestCase(TestCase):
 
1357
class TestTestCase(tests.TestCase):
1384
1358
    """Tests that test the core bzrlib TestCase."""
1385
1359
 
1386
1360
    def test_assertLength_matches_empty(self):
1403
1377
            exception.args[0])
1404
1378
 
1405
1379
    def test_base_setUp_not_called_causes_failure(self):
1406
 
        class TestCaseWithBrokenSetUp(TestCase):
 
1380
        class TestCaseWithBrokenSetUp(tests.TestCase):
1407
1381
            def setUp(self):
1408
1382
                pass # does not call TestCase.setUp
1409
1383
            def test_foo(self):
1415
1389
        self.assertEqual(1, result.testsRun)
1416
1390
 
1417
1391
    def test_base_tearDown_not_called_causes_failure(self):
1418
 
        class TestCaseWithBrokenTearDown(TestCase):
 
1392
        class TestCaseWithBrokenTearDown(tests.TestCase):
1419
1393
            def tearDown(self):
1420
1394
                pass # does not call TestCase.tearDown
1421
1395
            def test_foo(self):
1429
1403
    def test_debug_flags_sanitised(self):
1430
1404
        """The bzrlib debug flags should be sanitised by setUp."""
1431
1405
        if 'allow_debug' in tests.selftest_debug_flags:
1432
 
            raise TestNotApplicable(
 
1406
            raise tests.TestNotApplicable(
1433
1407
                '-Eallow_debug option prevents debug flag sanitisation')
1434
1408
        # we could set something and run a test that will check
1435
1409
        # it gets santised, but this is probably sufficient for now:
1450
1424
        """
1451
1425
        self.change_selftest_debug_flags(set(['allow_debug']))
1452
1426
        bzrlib.debug.debug_flags = set(['a-flag'])
1453
 
        class TestThatRecordsFlags(TestCase):
 
1427
        class TestThatRecordsFlags(tests.TestCase):
1454
1428
            def test_foo(nested_self):
1455
1429
                self.flags = set(bzrlib.debug.debug_flags)
1456
1430
        test = TestThatRecordsFlags('test_foo')
1464
1438
        self.change_selftest_debug_flags(set(['allow_debug']))
1465
1439
        # Now run a test that modifies debug.debug_flags.
1466
1440
        bzrlib.debug.debug_flags = set(['original-state'])
1467
 
        class TestThatModifiesFlags(TestCase):
 
1441
        class TestThatModifiesFlags(tests.TestCase):
1468
1442
            def test_foo(self):
1469
1443
                bzrlib.debug.debug_flags = set(['modified'])
1470
1444
        test = TestThatModifiesFlags('test_foo')
1472
1446
        self.assertEqual(set(['original-state']), bzrlib.debug.debug_flags)
1473
1447
 
1474
1448
    def make_test_result(self):
1475
 
        return bzrlib.tests.TextTestResult(
1476
 
            self._log_file, descriptions=0, verbosity=1)
 
1449
        return tests.TextTestResult(self._log_file, descriptions=0, verbosity=1)
1477
1450
 
1478
1451
    def inner_test(self):
1479
1452
        # the inner child test
1555
1528
 
1556
1529
    def test_knownFailure(self):
1557
1530
        """Self.knownFailure() should raise a KnownFailure exception."""
1558
 
        self.assertRaises(KnownFailure, self.knownFailure, "A Failure")
 
1531
        self.assertRaises(tests.KnownFailure, self.knownFailure, "A Failure")
1559
1532
 
1560
1533
    def test_requireFeature_available(self):
1561
1534
        """self.requireFeature(available) is a no-op."""
1562
 
        class Available(Feature):
 
1535
        class Available(tests.Feature):
1563
1536
            def _probe(self):return True
1564
1537
        feature = Available()
1565
1538
        self.requireFeature(feature)
1566
1539
 
1567
1540
    def test_requireFeature_unavailable(self):
1568
1541
        """self.requireFeature(unavailable) raises UnavailableFeature."""
1569
 
        class Unavailable(Feature):
 
1542
        class Unavailable(tests.Feature):
1570
1543
            def _probe(self):return False
1571
1544
        feature = Unavailable()
1572
 
        self.assertRaises(UnavailableFeature, self.requireFeature, feature)
 
1545
        self.assertRaises(tests.UnavailableFeature,
 
1546
                          self.requireFeature, feature)
1573
1547
 
1574
1548
    def test_run_no_parameters(self):
1575
1549
        test = SampleTestCase('_test_pass')
1711
1685
        return sample_deprecated_function()
1712
1686
 
1713
1687
 
1714
 
class TestExtraAssertions(TestCase):
 
1688
class TestExtraAssertions(tests.TestCase):
1715
1689
    """Tests for new test assertions in bzrlib test suite"""
1716
1690
 
1717
1691
    def test_assert_isinstance(self):
1772
1746
        self.callDeprecated([], testfunc, be_deprecated=False)
1773
1747
 
1774
1748
 
1775
 
class TestWarningTests(TestCase):
 
1749
class TestWarningTests(tests.TestCase):
1776
1750
    """Tests for calling methods that raise warnings."""
1777
1751
 
1778
1752
    def test_callCatchWarnings(self):
1788
1762
        self.assertEquals("this is your last warning", str(w0))
1789
1763
 
1790
1764
 
1791
 
class TestConvenienceMakers(TestCaseWithTransport):
 
1765
class TestConvenienceMakers(tests.TestCaseWithTransport):
1792
1766
    """Test for the make_* convenience functions."""
1793
1767
 
1794
1768
    def test_make_branch_and_tree_with_format(self):
1807
1781
        self.assertIsInstance(tree, bzrlib.memorytree.MemoryTree)
1808
1782
 
1809
1783
 
1810
 
class TestSFTPMakeBranchAndTree(TestCaseWithSFTPServer):
 
1784
class TestSFTPMakeBranchAndTree(test_sftp_transport.TestCaseWithSFTPServer):
1811
1785
 
1812
1786
    def test_make_tree_for_sftp_branch(self):
1813
1787
        """Transports backed by local directories create local trees."""
1822
1796
                tree.branch.repository.bzrdir.root_transport)
1823
1797
 
1824
1798
 
1825
 
class TestSelftest(TestCase):
 
1799
class TestSelftest(tests.TestCase):
1826
1800
    """Tests of bzrlib.tests.selftest."""
1827
1801
 
1828
1802
    def test_selftest_benchmark_parameter_invokes_test_suite__benchmark__(self):
1829
1803
        factory_called = []
1830
1804
        def factory():
1831
1805
            factory_called.append(True)
1832
 
            return TestSuite()
 
1806
            return TestUtil.TestSuite()
1833
1807
        out = StringIO()
1834
1808
        err = StringIO()
1835
1809
        self.apply_redirected(out, err, None, bzrlib.tests.selftest,
1837
1811
        self.assertEqual([True], factory_called)
1838
1812
 
1839
1813
 
1840
 
class TestKnownFailure(TestCase):
 
1814
class TestKnownFailure(tests.TestCase):
1841
1815
 
1842
1816
    def test_known_failure(self):
1843
1817
        """Check that KnownFailure is defined appropriately."""
1844
1818
        # a KnownFailure is an assertion error for compatability with unaware
1845
1819
        # runners.
1846
 
        self.assertIsInstance(KnownFailure(""), AssertionError)
 
1820
        self.assertIsInstance(tests.KnownFailure(""), AssertionError)
1847
1821
 
1848
1822
    def test_expect_failure(self):
1849
1823
        try:
1850
1824
            self.expectFailure("Doomed to failure", self.assertTrue, False)
1851
 
        except KnownFailure, e:
 
1825
        except tests.KnownFailure, e:
1852
1826
            self.assertEqual('Doomed to failure', e.args[0])
1853
1827
        try:
1854
1828
            self.expectFailure("Doomed to failure", self.assertTrue, True)
1859
1833
            self.fail('Assertion not raised')
1860
1834
 
1861
1835
 
1862
 
class TestFeature(TestCase):
 
1836
class TestFeature(tests.TestCase):
1863
1837
 
1864
1838
    def test_caching(self):
1865
1839
        """Feature._probe is called by the feature at most once."""
1866
 
        class InstrumentedFeature(Feature):
 
1840
        class InstrumentedFeature(tests.Feature):
1867
1841
            def __init__(self):
1868
 
                Feature.__init__(self)
 
1842
                super(InstrumentedFeature, self).__init__()
1869
1843
                self.calls = []
1870
1844
            def _probe(self):
1871
1845
                self.calls.append('_probe')
1878
1852
 
1879
1853
    def test_named_str(self):
1880
1854
        """Feature.__str__ should thunk to feature_name()."""
1881
 
        class NamedFeature(Feature):
 
1855
        class NamedFeature(tests.Feature):
1882
1856
            def feature_name(self):
1883
1857
                return 'symlinks'
1884
1858
        feature = NamedFeature()
1886
1860
 
1887
1861
    def test_default_str(self):
1888
1862
        """Feature.__str__ should default to __class__.__name__."""
1889
 
        class NamedFeature(Feature):
 
1863
        class NamedFeature(tests.Feature):
1890
1864
            pass
1891
1865
        feature = NamedFeature()
1892
1866
        self.assertEqual('NamedFeature', str(feature))
1893
1867
 
1894
1868
 
1895
 
class TestUnavailableFeature(TestCase):
 
1869
class TestUnavailableFeature(tests.TestCase):
1896
1870
 
1897
1871
    def test_access_feature(self):
1898
 
        feature = Feature()
1899
 
        exception = UnavailableFeature(feature)
 
1872
        feature = tests.Feature()
 
1873
        exception = tests.UnavailableFeature(feature)
1900
1874
        self.assertIs(feature, exception.args[0])
1901
1875
 
1902
1876
 
1903
 
class TestSelftestFiltering(TestCase):
 
1877
class TestSelftestFiltering(tests.TestCase):
1904
1878
 
1905
1879
    def setUp(self):
1906
 
        TestCase.setUp(self)
 
1880
        tests.TestCase.setUp(self)
1907
1881
        self.suite = TestUtil.TestSuite()
1908
1882
        self.loader = TestUtil.TestLoader()
1909
1883
        self.suite.addTest(self.loader.loadTestsFromModuleNames([
1913
1887
    def test_condition_id_re(self):
1914
1888
        test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1915
1889
            'test_condition_id_re')
1916
 
        filtered_suite = filter_suite_by_condition(self.suite,
1917
 
            condition_id_re('test_condition_id_re'))
 
1890
        filtered_suite = tests.filter_suite_by_condition(
 
1891
            self.suite, tests.condition_id_re('test_condition_id_re'))
1918
1892
        self.assertEqual([test_name], _test_ids(filtered_suite))
1919
1893
 
1920
1894
    def test_condition_id_in_list(self):
1921
1895
        test_names = ['bzrlib.tests.test_selftest.TestSelftestFiltering.'
1922
1896
                      'test_condition_id_in_list']
1923
1897
        id_list = tests.TestIdList(test_names)
1924
 
        filtered_suite = filter_suite_by_condition(
 
1898
        filtered_suite = tests.filter_suite_by_condition(
1925
1899
            self.suite, tests.condition_id_in_list(id_list))
1926
1900
        my_pattern = 'TestSelftestFiltering.*test_condition_id_in_list'
1927
 
        re_filtered = filter_suite_by_re(self.suite, my_pattern)
 
1901
        re_filtered = tests.filter_suite_by_re(self.suite, my_pattern)
1928
1902
        self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1929
1903
 
1930
1904
    def test_condition_id_startswith(self):
1934
1908
        test_names = [ klass + 'test_condition_id_in_list',
1935
1909
                      klass + 'test_condition_id_startswith',
1936
1910
                     ]
1937
 
        filtered_suite = filter_suite_by_condition(
 
1911
        filtered_suite = tests.filter_suite_by_condition(
1938
1912
            self.suite, tests.condition_id_startswith([start1, start2]))
1939
1913
        self.assertEqual(test_names, _test_ids(filtered_suite))
1940
1914
 
1941
1915
    def test_condition_isinstance(self):
1942
 
        filtered_suite = filter_suite_by_condition(self.suite,
1943
 
            condition_isinstance(self.__class__))
 
1916
        filtered_suite = tests.filter_suite_by_condition(
 
1917
            self.suite, tests.condition_isinstance(self.__class__))
1944
1918
        class_pattern = 'bzrlib.tests.test_selftest.TestSelftestFiltering.'
1945
 
        re_filtered = filter_suite_by_re(self.suite, class_pattern)
 
1919
        re_filtered = tests.filter_suite_by_re(self.suite, class_pattern)
1946
1920
        self.assertEqual(_test_ids(re_filtered), _test_ids(filtered_suite))
1947
1921
 
1948
1922
    def test_exclude_tests_by_condition(self):
1949
1923
        excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1950
1924
            'test_exclude_tests_by_condition')
1951
 
        filtered_suite = exclude_tests_by_condition(self.suite,
 
1925
        filtered_suite = tests.exclude_tests_by_condition(self.suite,
1952
1926
            lambda x:x.id() == excluded_name)
1953
1927
        self.assertEqual(len(self.all_names) - 1,
1954
1928
            filtered_suite.countTestCases())
1959
1933
 
1960
1934
    def test_exclude_tests_by_re(self):
1961
1935
        self.all_names = _test_ids(self.suite)
1962
 
        filtered_suite = exclude_tests_by_re(self.suite, 'exclude_tests_by_re')
 
1936
        filtered_suite = tests.exclude_tests_by_re(self.suite,
 
1937
                                                   'exclude_tests_by_re')
1963
1938
        excluded_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1964
1939
            'test_exclude_tests_by_re')
1965
1940
        self.assertEqual(len(self.all_names) - 1,
1972
1947
    def test_filter_suite_by_condition(self):
1973
1948
        test_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
1974
1949
            'test_filter_suite_by_condition')
1975
 
        filtered_suite = filter_suite_by_condition(self.suite,
 
1950
        filtered_suite = tests.filter_suite_by_condition(self.suite,
1976
1951
            lambda x:x.id() == test_name)
1977
1952
        self.assertEqual([test_name], _test_ids(filtered_suite))
1978
1953
 
1979
1954
    def test_filter_suite_by_re(self):
1980
 
        filtered_suite = filter_suite_by_re(self.suite, 'test_filter_suite_by_r')
 
1955
        filtered_suite = tests.filter_suite_by_re(self.suite,
 
1956
                                                  'test_filter_suite_by_r')
1981
1957
        filtered_names = _test_ids(filtered_suite)
1982
1958
        self.assertEqual(filtered_names, ['bzrlib.tests.test_selftest.'
1983
1959
            'TestSelftestFiltering.test_filter_suite_by_re'])
2011
1987
 
2012
1988
    def test_preserve_input(self):
2013
1989
        # NB: Surely this is something in the stdlib to do this?
2014
 
        self.assertTrue(self.suite is preserve_input(self.suite))
2015
 
        self.assertTrue("@#$" is preserve_input("@#$"))
 
1990
        self.assertTrue(self.suite is tests.preserve_input(self.suite))
 
1991
        self.assertTrue("@#$" is tests.preserve_input("@#$"))
2016
1992
 
2017
1993
    def test_randomize_suite(self):
2018
 
        randomized_suite = randomize_suite(self.suite)
 
1994
        randomized_suite = tests.randomize_suite(self.suite)
2019
1995
        # randomizing should not add or remove test names.
2020
1996
        self.assertEqual(set(_test_ids(self.suite)),
2021
1997
                         set(_test_ids(randomized_suite)))
2031
2007
 
2032
2008
    def test_split_suit_by_condition(self):
2033
2009
        self.all_names = _test_ids(self.suite)
2034
 
        condition = condition_id_re('test_filter_suite_by_r')
2035
 
        split_suite = split_suite_by_condition(self.suite, condition)
 
2010
        condition = tests.condition_id_re('test_filter_suite_by_r')
 
2011
        split_suite = tests.split_suite_by_condition(self.suite, condition)
2036
2012
        filtered_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
2037
2013
            'test_filter_suite_by_re')
2038
2014
        self.assertEqual([filtered_name], _test_ids(split_suite[0]))
2043
2019
 
2044
2020
    def test_split_suit_by_re(self):
2045
2021
        self.all_names = _test_ids(self.suite)
2046
 
        split_suite = split_suite_by_re(self.suite, 'test_filter_suite_by_r')
 
2022
        split_suite = tests.split_suite_by_re(self.suite,
 
2023
                                              'test_filter_suite_by_r')
2047
2024
        filtered_name = ('bzrlib.tests.test_selftest.TestSelftestFiltering.'
2048
2025
            'test_filter_suite_by_re')
2049
2026
        self.assertEqual([filtered_name], _test_ids(split_suite[0]))
2053
2030
        self.assertEqual(remaining_names, _test_ids(split_suite[1]))
2054
2031
 
2055
2032
 
2056
 
class TestCheckInventoryShape(TestCaseWithTransport):
 
2033
class TestCheckInventoryShape(tests.TestCaseWithTransport):
2057
2034
 
2058
2035
    def test_check_inventory_shape(self):
2059
2036
        files = ['a', 'b/', 'b/c']
2067
2044
            tree.unlock()
2068
2045
 
2069
2046
 
2070
 
class TestBlackboxSupport(TestCase):
 
2047
class TestBlackboxSupport(tests.TestCase):
2071
2048
    """Tests for testsuite blackbox features."""
2072
2049
 
2073
2050
    def test_run_bzr_failure_not_caught(self):
2094
2071
            'bzr: ERROR: Not a branch: ".*nonexistantpath/".\n')
2095
2072
 
2096
2073
 
2097
 
class TestTestLoader(TestCase):
 
2074
class TestTestLoader(tests.TestCase):
2098
2075
    """Tests for the test loader."""
2099
2076
 
2100
2077
    def _get_loader_and_module(self):
2101
2078
        """Gets a TestLoader and a module with one test in it."""
2102
2079
        loader = TestUtil.TestLoader()
2103
2080
        module = {}
2104
 
        class Stub(TestCase):
 
2081
        class Stub(tests.TestCase):
2105
2082
            def test_foo(self):
2106
2083
                pass
2107
2084
        class MyModule(object):
2120
2097
        # load_tests do not need that :)
2121
2098
        def load_tests(self, standard_tests, module, loader):
2122
2099
            result = loader.suiteClass()
2123
 
            for test in iter_suite_tests(standard_tests):
 
2100
            for test in tests.iter_suite_tests(standard_tests):
2124
2101
                result.addTests([test, test])
2125
2102
            return result
2126
2103
        # add a load_tests() method which multiplies the tests from the module.
2145
2122
 
2146
2123
    def _create_suite(self, test_id_list):
2147
2124
 
2148
 
        class Stub(TestCase):
 
2125
        class Stub(tests.TestCase):
2149
2126
            def test_foo(self):
2150
2127
                pass
2151
2128
 
2161
2138
 
2162
2139
    def _test_ids(self, test_suite):
2163
2140
        """Get the ids for the tests in a test suite."""
2164
 
        return [t.id() for t in iter_suite_tests(test_suite)]
 
2141
        return [t.id() for t in tests.iter_suite_tests(test_suite)]
2165
2142
 
2166
2143
    def test_empty_list(self):
2167
2144
        id_list = self._create_id_list([])
2224
2201
        loader = TestUtil.TestLoader()
2225
2202
        suite = loader.loadTestsFromModuleName('bzrlib.tests.test_sampler')
2226
2203
        dupes = loader.suiteClass()
2227
 
        for test in iter_suite_tests(suite):
 
2204
        for test in tests.iter_suite_tests(suite):
2228
2205
            dupes.addTest(test)
2229
2206
            dupes.addTest(test) # Add it again
2230
2207
 
2364
2341
        self.assertEquals('bzrlib.plugins', tpr.resolve_alias('bp'))
2365
2342
 
2366
2343
 
2367
 
class TestRunSuite(TestCase):
 
2344
class TestRunSuite(tests.TestCase):
2368
2345
 
2369
2346
    def test_runner_class(self):
2370
2347
        """run_suite accepts and uses a runner_class keyword argument."""
2371
 
        class Stub(TestCase):
 
2348
        class Stub(tests.TestCase):
2372
2349
            def test_foo(self):
2373
2350
                pass
2374
2351
        suite = Stub("test_foo")
2375
2352
        calls = []
2376
 
        class MyRunner(TextTestRunner):
 
2353
        class MyRunner(tests.TextTestRunner):
2377
2354
            def run(self, test):
2378
2355
                calls.append(test)
2379
 
                return ExtendedTestResult(self.stream, self.descriptions,
2380
 
                    self.verbosity)
2381
 
        run_suite(suite, runner_class=MyRunner, stream=StringIO())
 
2356
                return tests.ExtendedTestResult(self.stream, self.descriptions,
 
2357
                                                self.verbosity)
 
2358
        tests.run_suite(suite, runner_class=MyRunner, stream=StringIO())
2382
2359
        self.assertEqual(calls, [suite])
2383
2360
 
2384
2361
    def test_done(self):
2388
2365
        def test_function():
2389
2366
            pass
2390
2367
        test = unittest.FunctionTestCase(test_function)
2391
 
        class InstrumentedTestResult(ExtendedTestResult):
 
2368
        class InstrumentedTestResult(tests.ExtendedTestResult):
2392
2369
            def done(self): one_more_call()
2393
 
        class MyRunner(TextTestRunner):
 
2370
        class MyRunner(tests.TextTestRunner):
2394
2371
            def run(self, test):
2395
2372
                return InstrumentedTestResult(self.stream, self.descriptions,
2396
2373
                                              self.verbosity)
2397
 
        run_suite(test, runner_class=MyRunner, stream=StringIO())
 
2374
        tests.run_suite(test, runner_class=MyRunner, stream=StringIO())
2398
2375
        self.assertEquals(1, self.calls)