52
51
from bzrlib.tests import (
59
TestCaseWithMemoryTransport,
60
TestCaseWithTransport,
69
exclude_tests_by_condition,
71
filter_suite_by_condition,
77
split_suite_by_condition,
82
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
83
from bzrlib.tests.TestUtil import _load_module_by_name
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
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)]
94
class SelftestTests(TestCase):
63
return [t.id() for t in tests.iter_suite_tests(test_suite)]
66
class SelftestTests(tests.TestCase):
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)
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')
105
class MetaTestLog(TestCase):
77
class MetaTestLog(tests.TestCase):
107
79
def test_logging(self):
108
80
"""Test logs are captured when a test fails."""
121
93
tests.UnicodeFilename._probe()
124
class TestTreeShape(TestCaseInTempDir):
96
class TestTreeShape(tests.TestCaseInTempDir):
126
98
def test_unicode_paths(self):
127
99
self.requireFeature(tests.UnicodeFilename)
131
103
self.failUnlessExists(filename)
134
class TestTransportScenarios(TestCase):
106
class TestTransportScenarios(tests.TestCase):
135
107
"""A group of tests that test the transport implementation adaption core.
137
109
This is a meta test that the tests are applied to all available
190
162
bzrlib.transport.Server))
193
class TestBranchScenarios(TestCase):
165
class TestBranchScenarios(tests.TestCase):
195
167
def test_scenarios(self):
196
168
# check that constructor parameters are passed through to the adapted
448
420
self.assertEqual(expected_scenarios, scenarios)
451
class TestInterTreeScenarios(TestCase):
423
class TestInterTreeScenarios(tests.TestCase):
452
424
"""A group of tests that test the InterTreeTestAdapter."""
454
426
def test_scenarios(self):
504
476
self.assertEqual(scenarios, expected_scenarios)
507
class TestTestCaseInTempDir(TestCaseInTempDir):
479
class TestTestCaseInTempDir(tests.TestCaseInTempDir):
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"))
529
class TestTestCaseWithMemoryTransport(TestCaseWithMemoryTransport):
501
class TestTestCaseWithMemoryTransport(tests.TestCaseWithMemoryTransport):
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)
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))
636
class TestTestCaseWithTransport(TestCaseWithTransport):
608
class TestTestCaseWithTransport(tests.TestCaseWithTransport):
637
609
"""Tests for the convenience functions TestCaseWithTransport introduces."""
639
611
def test_get_readonly_url_none(self):
690
662
self.assertEqual((1, rev_id), a_branch.last_revision_info())
693
class TestTestCaseTransports(TestCaseWithTransport):
665
class TestTestCaseTransports(tests.TestCaseWithTransport):
696
668
super(TestTestCaseTransports, self).setUp()
705
677
self.failIfExists('subdir')
708
class TestChrootedTest(ChrootedTestCase):
680
class TestChrootedTest(tests.ChrootedTestCase):
710
682
def test_root_is_root(self):
711
683
from bzrlib.transport import get_transport
714
686
self.assertEqual(url, t.clone('..').base)
717
class MockProgress(_BaseProgressBar):
689
class MockProgress(progress._BaseProgressBar):
718
690
"""Progress-bar standin that records calls.
720
692
Useful for testing pb using code.
723
695
def __init__(self):
724
_BaseProgressBar.__init__(self)
696
progress._BaseProgressBar.__init__(self)
737
709
self.calls.append(('note', msg, args))
740
class TestTestResult(TestCase):
712
class TestTestResult(tests.TestCase):
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)
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):
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)
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
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
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(
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')
920
feature = tests.Feature()
949
921
result.startTest(test)
950
922
result.addNotSupported(test, feature)
951
923
# it should invoke 'report_unsupported'.
972
944
test = self.get_passing_test()
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."])
981
954
def test_text_report_unsupported(self):
982
955
# text test output formatting
990
963
test = self.get_passing_test()
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)
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)
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,
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))
1057
1030
def test_startTests(self):
1058
1031
"""Starting the first test should trigger startTests."""
1059
class InstrumentedTestResult(ExtendedTestResult):
1032
class InstrumentedTestResult(tests.ExtendedTestResult):
1061
1034
def startTests(self): self.calls += 1
1062
1035
def report_test_start(self, test): pass
1068
1041
self.assertEquals(1, result.calls)
1071
class TestUnicodeFilenameFeature(TestCase):
1044
class TestUnicodeFilenameFeature(tests.TestCase):
1073
1046
def test_probe_passes(self):
1074
1047
"""UnicodeFilenameFeature._probe passes."""
1088
1061
This current saves and restores:
1089
1062
TestCaseInTempDir.TEST_ROOT
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.
1094
old_root = TestCaseInTempDir.TEST_ROOT
1068
old_root = tests.TestCaseInTempDir.TEST_ROOT
1096
TestCaseInTempDir.TEST_ROOT = None
1070
tests.TestCaseInTempDir.TEST_ROOT = None
1097
1071
return testrunner.run(test)
1099
TestCaseInTempDir.TEST_ROOT = old_root
1073
tests.TestCaseInTempDir.TEST_ROOT = old_root
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(),
1145
1119
# run a test that is skipped, and check the suite as a whole still
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())
1156
1130
def test_skipped_from_setup(self):
1158
class SkippedSetupTest(TestCase):
1132
class SkippedSetupTest(tests.TestCase):
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')
1165
1139
def test_skip(self):
1166
1140
self.fail('test reached')
1168
1142
def cleanup(self):
1169
1143
calls.append('cleanup')
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())
1178
1152
def test_skipped_from_test(self):
1180
class SkippedTest(TestCase):
1154
class SkippedTest(tests.TestCase):
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)
1187
1161
def test_skip(self):
1188
raise TestSkipped('skipped test')
1162
raise tests.TestSkipped('skipped test')
1190
1164
def cleanup(self):
1191
1165
calls.append('cleanup')
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())
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')
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"""
1270
class LogTester(TestCase):
1244
class LogTester(tests.TestCase):
1272
1246
def test_success(self):
1273
1247
self.log('this will be removed\n')
1275
sio = cStringIO.StringIO()
1276
runner = TextTestRunner(stream=sio)
1250
runner = tests.TextTestRunner(stream=sio)
1277
1251
test = LogTester('test_success')
1278
1252
result = self.run_test_runner(runner, test)
1282
1256
def test_skipped_log_deleted(self):
1283
1257
"""Skipped tests have their log deleted"""
1285
class LogTester(TestCase):
1259
class LogTester(tests.TestCase):
1287
1261
def test_skipped(self):
1288
1262
self.log('this will be removed\n')
1289
1263
raise tests.TestSkipped()
1291
sio = cStringIO.StringIO()
1292
runner = TextTestRunner(stream=sio)
1266
runner = tests.TextTestRunner(stream=sio)
1293
1267
test = LogTester('test_skipped')
1294
1268
result = self.run_test_runner(runner, test)
1298
1272
def test_not_aplicable_log_deleted(self):
1299
1273
"""Not applicable tests have their log deleted"""
1301
class LogTester(TestCase):
1275
class LogTester(tests.TestCase):
1303
1277
def test_not_applicable(self):
1304
1278
self.log('this will be removed\n')
1305
1279
raise tests.TestNotApplicable()
1307
sio = cStringIO.StringIO()
1308
runner = TextTestRunner(stream=sio)
1282
runner = tests.TextTestRunner(stream=sio)
1309
1283
test = LogTester('test_not_applicable')
1310
1284
result = self.run_test_runner(runner, test)
1314
1288
def test_known_failure_log_deleted(self):
1315
1289
"""Know failure tests have their log deleted"""
1317
class LogTester(TestCase):
1291
class LogTester(tests.TestCase):
1319
1293
def test_known_failure(self):
1320
1294
self.log('this will be removed\n')
1321
1295
raise tests.KnownFailure()
1323
sio = cStringIO.StringIO()
1324
runner = TextTestRunner(stream=sio)
1298
runner = tests.TextTestRunner(stream=sio)
1325
1299
test = LogTester('test_known_failure')
1326
1300
result = self.run_test_runner(runner, test)
1330
1304
def test_fail_log_kept(self):
1331
1305
"""Failed tests have their log kept"""
1333
class LogTester(TestCase):
1307
class LogTester(tests.TestCase):
1335
1309
def test_fail(self):
1336
1310
self.log('this will be kept\n')
1337
1311
self.fail('this test fails')
1339
sio = cStringIO.StringIO()
1340
runner = TextTestRunner(stream=sio)
1314
runner = tests.TextTestRunner(stream=sio)
1341
1315
test = LogTester('test_fail')
1342
1316
result = self.run_test_runner(runner, test)
1352
1326
def test_error_log_kept(self):
1353
1327
"""Tests with errors have their log kept"""
1355
class LogTester(TestCase):
1329
class LogTester(tests.TestCase):
1357
1331
def test_error(self):
1358
1332
self.log('this will be kept\n')
1359
1333
raise ValueError('random exception raised')
1361
sio = cStringIO.StringIO()
1362
runner = TextTestRunner(stream=sio)
1336
runner = tests.TextTestRunner(stream=sio)
1363
1337
test = LogTester('test_error')
1364
1338
result = self.run_test_runner(runner, test)
1380
1354
class _TestException(Exception):
1383
class TestTestCase(TestCase):
1357
class TestTestCase(tests.TestCase):
1384
1358
"""Tests that test the core bzrlib TestCase."""
1386
1360
def test_assertLength_matches_empty(self):
1415
1389
self.assertEqual(1, result.testsRun)
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:
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)
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)
1478
1451
def inner_test(self):
1479
1452
# the inner child test
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")
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)
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)
1574
1548
def test_run_no_parameters(self):
1575
1549
test = SampleTestCase('_test_pass')
1711
1685
return sample_deprecated_function()
1714
class TestExtraAssertions(TestCase):
1688
class TestExtraAssertions(tests.TestCase):
1715
1689
"""Tests for new test assertions in bzrlib test suite"""
1717
1691
def test_assert_isinstance(self):
1772
1746
self.callDeprecated([], testfunc, be_deprecated=False)
1775
class TestWarningTests(TestCase):
1749
class TestWarningTests(tests.TestCase):
1776
1750
"""Tests for calling methods that raise warnings."""
1778
1752
def test_callCatchWarnings(self):
1788
1762
self.assertEquals("this is your last warning", str(w0))
1791
class TestConvenienceMakers(TestCaseWithTransport):
1765
class TestConvenienceMakers(tests.TestCaseWithTransport):
1792
1766
"""Test for the make_* convenience functions."""
1794
1768
def test_make_branch_and_tree_with_format(self):
1807
1781
self.assertIsInstance(tree, bzrlib.memorytree.MemoryTree)
1810
class TestSFTPMakeBranchAndTree(TestCaseWithSFTPServer):
1784
class TestSFTPMakeBranchAndTree(test_sftp_transport.TestCaseWithSFTPServer):
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)
1825
class TestSelftest(TestCase):
1799
class TestSelftest(tests.TestCase):
1826
1800
"""Tests of bzrlib.tests.selftest."""
1828
1802
def test_selftest_benchmark_parameter_invokes_test_suite__benchmark__(self):
1829
1803
factory_called = []
1831
1805
factory_called.append(True)
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)
1840
class TestKnownFailure(TestCase):
1814
class TestKnownFailure(tests.TestCase):
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
1846
self.assertIsInstance(KnownFailure(""), AssertionError)
1820
self.assertIsInstance(tests.KnownFailure(""), AssertionError)
1848
1822
def test_expect_failure(self):
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])
1854
1828
self.expectFailure("Doomed to failure", self.assertTrue, True)
1859
1833
self.fail('Assertion not raised')
1862
class TestFeature(TestCase):
1836
class TestFeature(tests.TestCase):
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')
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):
1891
1865
feature = NamedFeature()
1892
1866
self.assertEqual('NamedFeature', str(feature))
1895
class TestUnavailableFeature(TestCase):
1869
class TestUnavailableFeature(tests.TestCase):
1897
1871
def test_access_feature(self):
1899
exception = UnavailableFeature(feature)
1872
feature = tests.Feature()
1873
exception = tests.UnavailableFeature(feature)
1900
1874
self.assertIs(feature, exception.args[0])
1903
class TestSelftestFiltering(TestCase):
1877
class TestSelftestFiltering(tests.TestCase):
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))
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))
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',
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))
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))
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())
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))
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'])
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("@#$"))
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)))
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]))
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]))
2056
class TestCheckInventoryShape(TestCaseWithTransport):
2033
class TestCheckInventoryShape(tests.TestCaseWithTransport):
2058
2035
def test_check_inventory_shape(self):
2059
2036
files = ['a', 'b/', 'b/c']
2094
2071
'bzr: ERROR: Not a branch: ".*nonexistantpath/".\n')
2097
class TestTestLoader(TestCase):
2074
class TestTestLoader(tests.TestCase):
2098
2075
"""Tests for the test loader."""
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()
2104
class Stub(TestCase):
2081
class Stub(tests.TestCase):
2105
2082
def test_foo(self):
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])
2126
2103
# add a load_tests() method which multiplies the tests from the module.
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)]
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
2364
2341
self.assertEquals('bzrlib.plugins', tpr.resolve_alias('bp'))
2367
class TestRunSuite(TestCase):
2344
class TestRunSuite(tests.TestCase):
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):
2374
2351
suite = Stub("test_foo")
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,
2381
run_suite(suite, runner_class=MyRunner, stream=StringIO())
2356
return tests.ExtendedTestResult(self.stream, self.descriptions,
2358
tests.run_suite(suite, runner_class=MyRunner, stream=StringIO())
2382
2359
self.assertEqual(calls, [suite])
2384
2361
def test_done(self):
2388
2365
def test_function():
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)