754
754
def _patch_get_bzr_source_tree(self):
755
755
# Reading from the actual source tree breaks isolation, but we don't
756
756
# want to assume that thats *all* that would happen.
757
def _get_bzr_source_tree():
759
orig_get_bzr_source_tree = bzrlib.version._get_bzr_source_tree
760
bzrlib.version._get_bzr_source_tree = _get_bzr_source_tree
762
bzrlib.version._get_bzr_source_tree = orig_get_bzr_source_tree
763
self.addCleanup(restore)
757
self.overrideAttr(bzrlib.version, '_get_bzr_source_tree', lambda: None)
765
759
def test_assigned_benchmark_file_stores_date(self):
766
760
self._patch_get_bzr_source_tree()
1057
1051
'(?sm)^bzr selftest.*$'
1059
1053
'^======================================================================\n'
1060
'^FAIL: unittest.FunctionTestCase \\(failing_test\\)\n'
1054
'^FAIL: failing_test\n'
1061
1055
'^----------------------------------------------------------------------\n'
1062
1056
'Traceback \\(most recent call last\\):\n'
1063
1057
' .*' # File .*, line .*, in failing_test' - but maybe not from .pyc
1201
1195
# Reading from the actual source tree breaks isolation, but we don't
1202
1196
# want to assume that thats *all* that would happen.
1203
1197
self._get_source_tree_calls = []
1204
def _get_bzr_source_tree():
1205
1199
self._get_source_tree_calls.append("called")
1207
orig_get_bzr_source_tree = bzrlib.version._get_bzr_source_tree
1208
bzrlib.version._get_bzr_source_tree = _get_bzr_source_tree
1210
bzrlib.version._get_bzr_source_tree = orig_get_bzr_source_tree
1211
self.addCleanup(restore)
1201
self.overrideAttr(bzrlib.version, '_get_bzr_source_tree', new_get)
1213
1203
def test_bench_history(self):
1214
1204
# tests that the running the benchmark passes bench_history into
1322
1312
self.assertEqual(flags, bzrlib.debug.debug_flags)
1324
1314
def change_selftest_debug_flags(self, new_flags):
1325
orig_selftest_flags = tests.selftest_debug_flags
1326
self.addCleanup(self._restore_selftest_debug_flags, orig_selftest_flags)
1327
tests.selftest_debug_flags = set(new_flags)
1329
def _restore_selftest_debug_flags(self, flags):
1330
tests.selftest_debug_flags = flags
1315
self.overrideAttr(tests, 'selftest_debug_flags', set(new_flags))
1332
1317
def test_allow_debug_flag(self):
1333
1318
"""The -Eallow_debug flag prevents bzrlib.debug.debug_flags from being
1634
1619
self.assertRaises(AssertionError,
1635
1620
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)
1638
1659
# NB: Don't delete this; it's not actually from 0.11!
1639
1660
@deprecated_function(deprecated_in((0, 11, 0)))
2763
2784
# test doubles that supply a few sample tests to load, and check they
2766
def _test_suite_testmod_names():
2787
def testmod_names():
2767
2788
calls.append("testmod_names")
2769
2790
'bzrlib.tests.blackbox.test_branch',
2770
2791
'bzrlib.tests.per_transport',
2771
2792
'bzrlib.tests.test_selftest',
2773
original_testmod_names = tests._test_suite_testmod_names
2774
def _test_suite_modules_to_doctest():
2794
self.overrideAttr(tests, '_test_suite_testmod_names', testmod_names)
2775
2796
calls.append("modules_to_doctest")
2776
2797
return ['bzrlib.timestamp']
2777
orig_modules_to_doctest = tests._test_suite_modules_to_doctest
2778
def restore_names():
2779
tests._test_suite_testmod_names = original_testmod_names
2780
tests._test_suite_modules_to_doctest = orig_modules_to_doctest
2781
self.addCleanup(restore_names)
2782
tests._test_suite_testmod_names = _test_suite_testmod_names
2783
tests._test_suite_modules_to_doctest = _test_suite_modules_to_doctest
2798
self.overrideAttr(tests, '_test_suite_modules_to_doctest', doctests)
2784
2799
expected_test_list = [
2785
2800
# testmod_names
2786
2801
'bzrlib.tests.blackbox.test_branch.TestBranch.test_branch',