697
687
self.assertEqual(url, t.clone('..').base)
700
class TestProfileResult(tests.TestCase):
702
def test_profiles_tests(self):
703
self.requireFeature(test_lsprof.LSProfFeature)
704
terminal = testtools.tests.helpers.ExtendedTestResult()
705
result = tests.ProfileResult(terminal)
706
class Sample(tests.TestCase):
708
self.sample_function()
709
def sample_function(self):
713
case = terminal._events[0][1]
714
self.assertLength(1, case._benchcalls)
715
# We must be able to unpack it as the test reporting code wants
716
(_, _, _), stats = case._benchcalls[0]
717
self.assertTrue(callable(stats.pprint))
720
690
class TestTestResult(tests.TestCase):
722
692
def check_timing(self, test_case, expected_re):
839
800
def test_known_failure(self):
840
801
"""A KnownFailure being raised should trigger several result actions."""
841
802
class InstrumentedTestResult(tests.ExtendedTestResult):
842
def stopTestRun(self): pass
843
804
def startTests(self): pass
844
805
def report_test_start(self, test): pass
845
def report_known_failure(self, test, err=None, details=None):
846
self._call = test, 'known failure'
806
def report_known_failure(self, test, err):
807
self._call = test, err
847
808
result = InstrumentedTestResult(None, None, None, None)
848
class Test(tests.TestCase):
849
def test_function(self):
850
raise tests.KnownFailure('failed!')
851
test = Test("test_function")
810
raise tests.KnownFailure('failed!')
811
test = unittest.FunctionTestCase(test_function)
853
813
# it should invoke 'report_known_failure'.
854
814
self.assertEqual(2, len(result._call))
855
self.assertEqual(test.id(), result._call[0].id())
856
self.assertEqual('known failure', result._call[1])
815
self.assertEqual(test, result._call[0])
816
self.assertEqual(tests.KnownFailure, result._call[1][0])
817
self.assertIsInstance(result._call[1][1], tests.KnownFailure)
857
818
# we dont introspec the traceback, if the rest is ok, it would be
858
819
# exceptional for it not to be.
859
820
# it should update the known_failure_count on the object.
931
892
result.report_unsupported(test, feature)
932
893
output = result_stream.getvalue()[prefix:]
933
894
lines = output.splitlines()
934
# We don't check for the final '0ms' since it may fail on slow hosts
935
self.assertStartsWith(lines[0], 'NODEP')
936
self.assertEqual(lines[1],
937
" The feature 'Feature' is not available.")
895
# XXX: This is a timing dependent test. I've had it fail because it
896
# took 6ms to evaluate... :(
897
self.assertEqual(lines, ['NODEP 0ms',
898
" The feature 'Feature' is not available."])
939
900
def test_unavailable_exception(self):
940
901
"""An UnavailableFeature being raised should invoke addNotSupported."""
941
902
class InstrumentedTestResult(tests.ExtendedTestResult):
942
def stopTestRun(self): pass
943
904
def startTests(self): pass
944
905
def report_test_start(self, test): pass
945
906
def addNotSupported(self, test, feature):
946
907
self._call = test, feature
947
908
result = InstrumentedTestResult(None, None, None, None)
948
909
feature = tests.Feature()
949
class Test(tests.TestCase):
950
def test_function(self):
951
raise tests.UnavailableFeature(feature)
952
test = Test("test_function")
911
raise tests.UnavailableFeature(feature)
912
test = unittest.FunctionTestCase(test_function)
954
914
# it should invoke 'addNotSupported'.
955
915
self.assertEqual(2, len(result._call))
956
self.assertEqual(test.id(), result._call[0].id())
916
self.assertEqual(test, result._call[0])
957
917
self.assertEqual(feature, result._call[1])
958
918
# and not count as an error
959
919
self.assertEqual(0, result.error_count)
1023
983
because of our use of global state.
1025
985
old_root = tests.TestCaseInTempDir.TEST_ROOT
1026
old_leak = tests.TestCase._first_thread_leaker_id
1028
987
tests.TestCaseInTempDir.TEST_ROOT = None
1029
tests.TestCase._first_thread_leaker_id = None
1030
988
return testrunner.run(test)
1032
990
tests.TestCaseInTempDir.TEST_ROOT = old_root
1033
tests.TestCase._first_thread_leaker_id = old_leak
1035
992
def test_known_failure_failed_run(self):
1036
993
# run a test that generates a known failure which should be printed in
1037
994
# the final output when real failures occur.
1038
class Test(tests.TestCase):
1039
def known_failure_test(self):
1040
self.expectFailure('failed', self.assertTrue, False)
995
def known_failure_test():
996
raise tests.KnownFailure('failed')
1041
997
test = unittest.TestSuite()
1042
test.addTest(Test("known_failure_test"))
998
test.addTest(unittest.FunctionTestCase(known_failure_test))
1043
999
def failing_test():
1000
raise AssertionError('foo')
1045
1001
test.addTest(unittest.FunctionTestCase(failing_test))
1046
1002
stream = StringIO()
1047
1003
runner = tests.TextTestRunner(stream=stream)
1048
1004
result = self.run_test_runner(runner, test)
1049
1005
lines = stream.getvalue().splitlines()
1050
1006
self.assertContainsRe(stream.getvalue(),
1051
'(?sm)^bzr selftest.*$'
1053
1009
'^======================================================================\n'
1054
'^FAIL: failing_test\n'
1010
'^FAIL: unittest.FunctionTestCase \\(failing_test\\)\n'
1055
1011
'^----------------------------------------------------------------------\n'
1056
1012
'Traceback \\(most recent call last\\):\n'
1057
1013
' .*' # File .*, line .*, in failing_test' - but maybe not from .pyc
1058
' self.fail\\(\'foo\'\\)\n'
1014
' raise AssertionError\\(\'foo\'\\)\n'
1060
1016
'^----------------------------------------------------------------------\n'
1194
def _patch_get_bzr_source_tree(self):
1195
# Reading from the actual source tree breaks isolation, but we don't
1196
# want to assume that thats *all* that would happen.
1197
self._get_source_tree_calls = []
1199
self._get_source_tree_calls.append("called")
1201
self.overrideAttr(bzrlib.version, '_get_bzr_source_tree', new_get)
1203
1137
def test_bench_history(self):
1204
# tests that the running the benchmark passes bench_history into
1205
# the test result object. We can tell that happens if
1206
# _get_bzr_source_tree is called.
1207
self._patch_get_bzr_source_tree()
1138
# tests that the running the benchmark produces a history file
1139
# containing a timestamp and the revision id of the bzrlib source which
1141
workingtree = _get_bzr_source_tree()
1208
1142
test = TestRunner('dummy_test')
1209
1143
output = StringIO()
1210
1144
runner = tests.TextTestRunner(stream=self._log_file,
1212
1146
result = self.run_test_runner(runner, test)
1213
1147
output_string = output.getvalue()
1214
1148
self.assertContainsRe(output_string, "--date [0-9.]+")
1215
self.assertLength(1, self._get_source_tree_calls)
1217
def test_startTestRun(self):
1218
"""run should call result.startTestRun()"""
1220
class LoggingDecorator(tests.ForwardingResult):
1221
def startTestRun(self):
1222
tests.ForwardingResult.startTestRun(self)
1223
calls.append('startTestRun')
1224
test = unittest.FunctionTestCase(lambda:None)
1226
runner = tests.TextTestRunner(stream=stream,
1227
result_decorators=[LoggingDecorator])
1228
result = self.run_test_runner(runner, test)
1229
self.assertLength(1, calls)
1231
def test_stopTestRun(self):
1232
"""run should call result.stopTestRun()"""
1234
class LoggingDecorator(tests.ForwardingResult):
1235
def stopTestRun(self):
1236
tests.ForwardingResult.stopTestRun(self)
1237
calls.append('stopTestRun')
1238
test = unittest.FunctionTestCase(lambda:None)
1240
runner = tests.TextTestRunner(stream=stream,
1241
result_decorators=[LoggingDecorator])
1242
result = self.run_test_runner(runner, test)
1243
self.assertLength(1, calls)
1149
if workingtree is not None:
1150
revision_id = workingtree.get_parent_ids()[0]
1151
self.assertEndsWith(output_string.rstrip(), revision_id)
1153
def assertLogDeleted(self, test):
1154
log = test._get_log()
1155
self.assertEqual("DELETED log file to reduce memory footprint", log)
1156
self.assertEqual('', test._log_contents)
1157
self.assertIs(None, test._log_file_name)
1159
def test_success_log_deleted(self):
1160
"""Successful tests have their log deleted"""
1162
class LogTester(tests.TestCase):
1164
def test_success(self):
1165
self.log('this will be removed\n')
1168
runner = tests.TextTestRunner(stream=sio)
1169
test = LogTester('test_success')
1170
result = self.run_test_runner(runner, test)
1172
self.assertLogDeleted(test)
1174
def test_skipped_log_deleted(self):
1175
"""Skipped tests have their log deleted"""
1177
class LogTester(tests.TestCase):
1179
def test_skipped(self):
1180
self.log('this will be removed\n')
1181
raise tests.TestSkipped()
1184
runner = tests.TextTestRunner(stream=sio)
1185
test = LogTester('test_skipped')
1186
result = self.run_test_runner(runner, test)
1188
self.assertLogDeleted(test)
1190
def test_not_aplicable_log_deleted(self):
1191
"""Not applicable tests have their log deleted"""
1193
class LogTester(tests.TestCase):
1195
def test_not_applicable(self):
1196
self.log('this will be removed\n')
1197
raise tests.TestNotApplicable()
1200
runner = tests.TextTestRunner(stream=sio)
1201
test = LogTester('test_not_applicable')
1202
result = self.run_test_runner(runner, test)
1204
self.assertLogDeleted(test)
1206
def test_known_failure_log_deleted(self):
1207
"""Know failure tests have their log deleted"""
1209
class LogTester(tests.TestCase):
1211
def test_known_failure(self):
1212
self.log('this will be removed\n')
1213
raise tests.KnownFailure()
1216
runner = tests.TextTestRunner(stream=sio)
1217
test = LogTester('test_known_failure')
1218
result = self.run_test_runner(runner, test)
1220
self.assertLogDeleted(test)
1222
def test_fail_log_kept(self):
1223
"""Failed tests have their log kept"""
1225
class LogTester(tests.TestCase):
1227
def test_fail(self):
1228
self.log('this will be kept\n')
1229
self.fail('this test fails')
1232
runner = tests.TextTestRunner(stream=sio)
1233
test = LogTester('test_fail')
1234
result = self.run_test_runner(runner, test)
1236
text = sio.getvalue()
1237
self.assertContainsRe(text, 'this will be kept')
1238
self.assertContainsRe(text, 'this test fails')
1240
log = test._get_log()
1241
self.assertContainsRe(log, 'this will be kept')
1242
self.assertEqual(log, test._log_contents)
1244
def test_error_log_kept(self):
1245
"""Tests with errors have their log kept"""
1247
class LogTester(tests.TestCase):
1249
def test_error(self):
1250
self.log('this will be kept\n')
1251
raise ValueError('random exception raised')
1254
runner = tests.TextTestRunner(stream=sio)
1255
test = LogTester('test_error')
1256
result = self.run_test_runner(runner, test)
1258
text = sio.getvalue()
1259
self.assertContainsRe(text, 'this will be kept')
1260
self.assertContainsRe(text, 'random exception raised')
1262
log = test._get_log()
1263
self.assertContainsRe(log, 'this will be kept')
1264
self.assertEqual(log, test._log_contents)
1246
1267
class SampleTestCase(tests.TestCase):
1458
1482
self.assertEqual((time.sleep, (0.003,), {}), self._benchcalls[1][0])
1459
1483
self.assertIsInstance(self._benchcalls[0][1], bzrlib.lsprof.Stats)
1460
1484
self.assertIsInstance(self._benchcalls[1][1], bzrlib.lsprof.Stats)
1461
del self._benchcalls[:]
1463
1486
def test_knownFailure(self):
1464
1487
"""Self.knownFailure() should raise a KnownFailure exception."""
1465
1488
self.assertRaises(tests.KnownFailure, self.knownFailure, "A Failure")
1467
def test_open_bzrdir_safe_roots(self):
1468
# even a memory transport should fail to open when its url isn't
1470
# Manually set one up (TestCase doesn't and shouldn't provide magic
1472
transport_server = memory.MemoryServer()
1473
transport_server.start_server()
1474
self.addCleanup(transport_server.stop_server)
1475
t = transport.get_transport(transport_server.get_url())
1476
bzrdir.BzrDir.create(t.base)
1477
self.assertRaises(errors.BzrError,
1478
bzrdir.BzrDir.open_from_transport, t)
1479
# But if we declare this as safe, we can open the bzrdir.
1480
self.permit_url(t.base)
1481
self._bzr_selftest_roots.append(t.base)
1482
bzrdir.BzrDir.open_from_transport(t)
1484
1490
def test_requireFeature_available(self):
1485
1491
"""self.requireFeature(available) is a no-op."""
1486
1492
class Available(tests.Feature):
1548
1552
self.calls.append(('addNotSupported', test, feature))
1549
1553
result = InstrumentedTestResult()
1550
1554
test.run(result)
1551
case = result.calls[0][1]
1552
1555
self.assertEqual([
1553
('startTest', case),
1554
('addNotSupported', case, the_feature),
1556
('startTest', test),
1557
('addNotSupported', test, the_feature),
1559
def test_start_server_registers_url(self):
1560
transport_server = memory.MemoryServer()
1561
# A little strict, but unlikely to be changed soon.
1562
self.assertEqual([], self._bzr_selftest_roots)
1563
self.start_server(transport_server)
1564
self.assertSubset([transport_server.get_url()],
1565
self._bzr_selftest_roots)
1567
1562
def test_assert_list_raises_on_generator(self):
1568
1563
def generator_which_will_raise():
1569
1564
# This will not raise until after the first yield
1619
1614
self.assertRaises(AssertionError,
1620
1615
self.assertListRaises, _TestException, success_generator)
1622
def test_overrideAttr_without_value(self):
1623
self.test_attr = 'original' # Define a test attribute
1624
obj = self # Make 'obj' visible to the embedded test
1625
class Test(tests.TestCase):
1628
tests.TestCase.setUp(self)
1629
self.orig = self.overrideAttr(obj, 'test_attr')
1631
def test_value(self):
1632
self.assertEqual('original', self.orig)
1633
self.assertEqual('original', obj.test_attr)
1634
obj.test_attr = 'modified'
1635
self.assertEqual('modified', obj.test_attr)
1637
test = Test('test_value')
1638
test.run(unittest.TestResult())
1639
self.assertEqual('original', obj.test_attr)
1641
def test_overrideAttr_with_value(self):
1642
self.test_attr = 'original' # Define a test attribute
1643
obj = self # Make 'obj' visible to the embedded test
1644
class Test(tests.TestCase):
1647
tests.TestCase.setUp(self)
1648
self.orig = self.overrideAttr(obj, 'test_attr', new='modified')
1650
def test_value(self):
1651
self.assertEqual('original', self.orig)
1652
self.assertEqual('modified', obj.test_attr)
1654
test = Test('test_value')
1655
test.run(unittest.TestResult())
1656
self.assertEqual('original', obj.test_attr)
1659
1618
# NB: Don't delete this; it's not actually from 0.11!
1660
1619
@deprecated_function(deprecated_in((0, 11, 0)))
1703
1662
self.assertEndsWith('foo', 'oo')
1704
1663
self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
1706
def test_assertEqualDiff(self):
1707
e = self.assertRaises(AssertionError,
1708
self.assertEqualDiff, '', '\n')
1709
self.assertEquals(str(e),
1710
# Don't blink ! The '+' applies to the second string
1711
'first string is missing a final newline.\n+ \n')
1712
e = self.assertRaises(AssertionError,
1713
self.assertEqualDiff, '\n', '')
1714
self.assertEquals(str(e),
1715
# Don't blink ! The '-' applies to the second string
1716
'second string is missing a final newline.\n- \n')
1719
class TestDeprecations(tests.TestCase):
1721
1665
def test_applyDeprecated_not_deprecated(self):
1722
1666
sample_object = ApplyDeprecatedHelper()
1723
1667
# calling an undeprecated callable raises an assertion
1800
1744
tree = self.make_branch_and_memory_tree('a')
1801
1745
self.assertIsInstance(tree, bzrlib.memorytree.MemoryTree)
1803
def test_make_tree_for_local_vfs_backed_transport(self):
1804
# make_branch_and_tree has to use local branch and repositories
1805
# when the vfs transport and local disk are colocated, even if
1806
# a different transport is in use for url generation.
1807
self.transport_server = test_server.FakeVFATServer
1808
self.assertFalse(self.get_url('t1').startswith('file://'))
1748
class TestSFTPMakeBranchAndTree(test_sftp_transport.TestCaseWithSFTPServer):
1750
def test_make_tree_for_sftp_branch(self):
1751
"""Transports backed by local directories create local trees."""
1752
# NB: This is arguably a bug in the definition of make_branch_and_tree.
1809
1753
tree = self.make_branch_and_tree('t1')
1810
1754
base = tree.bzrdir.root_transport.base
1811
self.assertStartsWith(base, 'file://')
1755
self.failIf(base.startswith('sftp'),
1756
'base %r is on sftp but should be local' % base)
1812
1757
self.assertEquals(tree.bzrdir.root_transport,
1813
1758
tree.branch.bzrdir.root_transport)
1814
1759
self.assertEquals(tree.bzrdir.root_transport,
1983
1917
Attempts to run bzr from inside this class don't actually run it.
1985
We test how run_bzr actually invokes bzr in another location. Here we
1986
only need to test that it passes the right parameters to run_bzr.
1919
We test how run_bzr actually invokes bzr in another location.
1920
Here we only need to test that it is run_bzr passes the right
1921
parameters to run_bzr.
1988
1923
self.argv = list(argv)
1989
1924
self.retcode = retcode
1990
1925
self.encoding = encoding
1991
1926
self.stdin = stdin
1992
1927
self.working_dir = working_dir
1993
return self.retcode, self.out, self.err
1928
return self.out, self.err
1995
1930
def test_run_bzr_error(self):
1996
1931
self.out = "It sure does!\n"
1997
1932
out, err = self.run_bzr_error(['^$'], ['rocks'], retcode=34)
1998
1933
self.assertEqual(['rocks'], self.argv)
1999
1934
self.assertEqual(34, self.retcode)
2000
self.assertEqual('It sure does!\n', out)
2001
self.assertEquals(out, self.out)
2002
self.assertEqual('', err)
2003
self.assertEquals(err, self.err)
1935
self.assertEqual(out, 'It sure does!\n')
2005
1937
def test_run_bzr_error_regexes(self):
2007
1939
self.err = "bzr: ERROR: foobarbaz is not versioned"
2008
1940
out, err = self.run_bzr_error(
2009
["bzr: ERROR: foobarbaz is not versioned"],
2010
['file-id', 'foobarbaz'])
1941
["bzr: ERROR: foobarbaz is not versioned"],
1942
['file-id', 'foobarbaz'])
2012
1944
def test_encoding(self):
2013
1945
"""Test that run_bzr passes encoding to _run_bzr_core"""
2231
2159
StubProcess(), '', allow_plugins=True)
2234
class TestFinishBzrSubprocess(TestWithFakedStartBzrSubprocess):
2236
def test_finish_bzr_subprocess_with_error(self):
2237
"""finish_bzr_subprocess allows specification of the desired exit code.
2239
process = StubProcess(err="unknown command", retcode=3)
2240
result = self.finish_bzr_subprocess(process, retcode=3)
2241
self.assertEqual('', result[0])
2242
self.assertContainsRe(result[1], 'unknown command')
2244
def test_finish_bzr_subprocess_ignoring_retcode(self):
2245
"""finish_bzr_subprocess allows the exit code to be ignored."""
2246
process = StubProcess(err="unknown command", retcode=3)
2247
result = self.finish_bzr_subprocess(process, retcode=None)
2248
self.assertEqual('', result[0])
2249
self.assertContainsRe(result[1], 'unknown command')
2251
def test_finish_subprocess_with_unexpected_retcode(self):
2252
"""finish_bzr_subprocess raises self.failureException if the retcode is
2253
not the expected one.
2255
process = StubProcess(err="unknown command", retcode=3)
2256
self.assertRaises(self.failureException, self.finish_bzr_subprocess,
2260
2162
class _DontSpawnProcess(Exception):
2261
2163
"""A simple exception which just allows us to skip unnecessary steps"""
2340
2242
self.assertEqual(['foo', 'current'], chdirs)
2343
class TestActuallyStartBzrSubprocess(tests.TestCaseWithTransport):
2344
"""Tests that really need to do things with an external bzr."""
2245
class TestBzrSubprocess(tests.TestCaseWithTransport):
2247
def test_start_and_stop_bzr_subprocess(self):
2248
"""We can start and perform other test actions while that process is
2251
process = self.start_bzr_subprocess(['--version'])
2252
result = self.finish_bzr_subprocess(process)
2253
self.assertContainsRe(result[0], 'is free software')
2254
self.assertEqual('', result[1])
2256
def test_start_and_stop_bzr_subprocess_with_error(self):
2257
"""finish_bzr_subprocess allows specification of the desired exit code.
2259
process = self.start_bzr_subprocess(['--versionn'])
2260
result = self.finish_bzr_subprocess(process, retcode=3)
2261
self.assertEqual('', result[0])
2262
self.assertContainsRe(result[1], 'unknown command')
2264
def test_start_and_stop_bzr_subprocess_ignoring_retcode(self):
2265
"""finish_bzr_subprocess allows the exit code to be ignored."""
2266
process = self.start_bzr_subprocess(['--versionn'])
2267
result = self.finish_bzr_subprocess(process, retcode=None)
2268
self.assertEqual('', result[0])
2269
self.assertContainsRe(result[1], 'unknown command')
2271
def test_start_and_stop_bzr_subprocess_with_unexpected_retcode(self):
2272
"""finish_bzr_subprocess raises self.failureException if the retcode is
2273
not the expected one.
2275
process = self.start_bzr_subprocess(['--versionn'])
2276
self.assertRaises(self.failureException, self.finish_bzr_subprocess,
2346
2279
def test_start_and_stop_bzr_subprocess_send_signal(self):
2347
2280
"""finish_bzr_subprocess raises self.failureException if the retcode is
2348
2281
not the expected one.
2350
self.disable_missing_extensions_warning()
2351
2283
process = self.start_bzr_subprocess(['wait-until-signalled'],
2352
2284
skip_if_plan_to_signal=True)
2353
2285
self.assertEqual('running\n', process.stdout.readline())
2356
2288
self.assertEqual('', result[0])
2357
2289
self.assertEqual('bzr: interrupted\n', result[1])
2291
def test_start_and_stop_working_dir(self):
2292
cwd = osutils.getcwd()
2293
self.make_branch_and_tree('one')
2294
process = self.start_bzr_subprocess(['root'], working_dir='one')
2295
result = self.finish_bzr_subprocess(process, universal_newlines=True)
2296
self.assertEndsWith(result[0], 'one\n')
2297
self.assertEqual('', result[1])
2300
class TestKnownFailure(tests.TestCase):
2302
def test_known_failure(self):
2303
"""Check that KnownFailure is defined appropriately."""
2304
# a KnownFailure is an assertion error for compatability with unaware
2306
self.assertIsInstance(tests.KnownFailure(""), AssertionError)
2308
def test_expect_failure(self):
2310
self.expectFailure("Doomed to failure", self.assertTrue, False)
2311
except tests.KnownFailure, e:
2312
self.assertEqual('Doomed to failure', e.args[0])
2314
self.expectFailure("Doomed to failure", self.assertTrue, True)
2315
except AssertionError, e:
2316
self.assertEqual('Unexpected success. Should have failed:'
2317
' Doomed to failure', e.args[0])
2319
self.fail('Assertion not raised')
2360
2322
class TestFeature(tests.TestCase):
2398
2360
self.assertIs(feature, exception.args[0])
2401
simple_thunk_feature = tests._CompatabilityThunkFeature(
2402
deprecated_in((2, 1, 0)),
2403
'bzrlib.tests.test_selftest',
2404
'simple_thunk_feature','UnicodeFilename',
2405
replacement_module='bzrlib.tests'
2408
class Test_CompatibilityFeature(tests.TestCase):
2410
def test_does_thunk(self):
2411
res = self.callDeprecated(
2412
['bzrlib.tests.test_selftest.simple_thunk_feature was deprecated'
2413
' in version 2.1.0. Use bzrlib.tests.UnicodeFilename instead.'],
2414
simple_thunk_feature.available)
2415
self.assertEqual(tests.UnicodeFilename.available(), res)
2418
class TestModuleAvailableFeature(tests.TestCase):
2420
def test_available_module(self):
2421
feature = tests.ModuleAvailableFeature('bzrlib.tests')
2422
self.assertEqual('bzrlib.tests', feature.module_name)
2423
self.assertEqual('bzrlib.tests', str(feature))
2424
self.assertTrue(feature.available())
2425
self.assertIs(tests, feature.module)
2427
def test_unavailable_module(self):
2428
feature = tests.ModuleAvailableFeature('bzrlib.no_such_module_exists')
2429
self.assertEqual('bzrlib.no_such_module_exists', str(feature))
2430
self.assertFalse(feature.available())
2431
self.assertIs(None, feature.module)
2434
2363
class TestSelftestFiltering(tests.TestCase):
2436
2365
def setUp(self):
2615
2544
# the test framework
2616
2545
self.assertEquals('always fails', str(e))
2617
2546
# check that there's no traceback in the test log
2618
self.assertNotContainsRe(self.get_log(), r'Traceback')
2547
self.assertNotContainsRe(self._get_log(keep_log_file=True),
2620
2550
def test_run_bzr_user_error_caught(self):
2621
2551
# Running bzr in blackbox mode, normal/expected/user errors should be
2622
2552
# caught in the regular way and turned into an error message plus exit
2624
transport_server = memory.MemoryServer()
2625
transport_server.start_server()
2626
self.addCleanup(transport_server.stop_server)
2627
url = transport_server.get_url()
2628
self.permit_url(url)
2629
out, err = self.run_bzr(["log", "%s/nonexistantpath" % url], retcode=3)
2554
out, err = self.run_bzr(["log", "/nonexistantpath"], retcode=3)
2630
2555
self.assertEqual(out, '')
2631
2556
self.assertContainsRe(err,
2632
2557
'bzr: ERROR: Not a branch: ".*nonexistantpath/".\n')
2759
2684
class TestTestSuite(tests.TestCase):
2761
def test__test_suite_testmod_names(self):
2762
# Test that a plausible list of test module names are returned
2763
# by _test_suite_testmod_names.
2764
test_list = tests._test_suite_testmod_names()
2766
'bzrlib.tests.blackbox',
2767
'bzrlib.tests.per_transport',
2768
'bzrlib.tests.test_selftest',
2772
def test__test_suite_modules_to_doctest(self):
2773
# Test that a plausible list of modules to doctest is returned
2774
# by _test_suite_modules_to_doctest.
2775
test_list = tests._test_suite_modules_to_doctest()
2781
2686
def test_test_suite(self):
2782
# test_suite() loads the entire test suite to operate. To avoid this
2783
# overhead, and yet still be confident that things are happening,
2784
# we temporarily replace two functions used by test_suite with
2785
# test doubles that supply a few sample tests to load, and check they
2788
def testmod_names():
2789
calls.append("testmod_names")
2791
'bzrlib.tests.blackbox.test_branch',
2792
'bzrlib.tests.per_transport',
2793
'bzrlib.tests.test_selftest',
2795
self.overrideAttr(tests, '_test_suite_testmod_names', testmod_names)
2797
calls.append("modules_to_doctest")
2798
return ['bzrlib.timestamp']
2799
self.overrideAttr(tests, '_test_suite_modules_to_doctest', doctests)
2800
expected_test_list = [
2687
# This test is slow - it loads the entire test suite to operate, so we
2688
# do a single test with one test in each category
2801
2690
# testmod_names
2802
2691
'bzrlib.tests.blackbox.test_branch.TestBranch.test_branch',
2803
2692
('bzrlib.tests.per_transport.TransportTests'
2804
'.test_abspath(LocalTransport,LocalURLServer)'),
2693
'.test_abspath(LocalURLServer)'),
2805
2694
'bzrlib.tests.test_selftest.TestTestSuite.test_test_suite',
2806
2695
# modules_to_doctest
2807
2696
'bzrlib.timestamp.format_highres_date',
2808
2697
# plugins can't be tested that way since selftest may be run with
2811
suite = tests.test_suite()
2812
self.assertEqual(set(["testmod_names", "modules_to_doctest"]),
2814
self.assertSubset(expected_test_list, _test_ids(suite))
2700
suite = tests.test_suite(test_list)
2701
self.assertEquals(test_list, _test_ids(suite))
2816
2703
def test_test_suite_list_and_start(self):
2817
2704
# We cannot test this at the same time as the main load, because we want
2818
# to know that starting_with == None works. So a second load is
2819
# incurred - note that the starting_with parameter causes a partial load
2820
# rather than a full load so this test should be pretty quick.
2705
# to know that starting_with == None works. So a second full load is
2821
2707
test_list = ['bzrlib.tests.test_selftest.TestTestSuite.test_test_suite']
2822
2708
suite = tests.test_suite(test_list,
2823
2709
['bzrlib.tests.test_selftest.TestTestSuite'])