~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-05 10:27:33 UTC
  • mto: (5008.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5009.
  • Revision ID: v.ladeuil+lp@free.fr-20100205102733-8wpjnqz6g4nvrbfu
All Conflict action method names start with 'action_' to avoid potential namespace collisions

Show diffs side-by-side

added added

removed removed

Lines of Context:
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():
758
 
            return None
759
 
        orig_get_bzr_source_tree = bzrlib.version._get_bzr_source_tree
760
 
        bzrlib.version._get_bzr_source_tree = _get_bzr_source_tree
761
 
        def restore():
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)
764
758
 
765
759
    def test_assigned_benchmark_file_stores_date(self):
766
760
        self._patch_get_bzr_source_tree()
1057
1051
            '(?sm)^bzr selftest.*$'
1058
1052
            '.*'
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():
 
1198
        def new_get():
1205
1199
            self._get_source_tree_calls.append("called")
1206
1200
            return None
1207
 
        orig_get_bzr_source_tree = bzrlib.version._get_bzr_source_tree
1208
 
        bzrlib.version._get_bzr_source_tree = _get_bzr_source_tree
1209
 
        def restore():
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)
1212
1202
 
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)
1323
1313
 
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)
1328
 
 
1329
 
    def _restore_selftest_debug_flags(self, flags):
1330
 
        tests.selftest_debug_flags = flags
 
1315
        self.overrideAttr(tests, 'selftest_debug_flags', set(new_flags))
1331
1316
 
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)
1636
1621
 
 
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):
 
1626
 
 
1627
            def setUp(self):
 
1628
                tests.TestCase.setUp(self)
 
1629
                self.orig = self.overrideAttr(obj, 'test_attr')
 
1630
 
 
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)
 
1636
 
 
1637
        test = Test('test_value')
 
1638
        test.run(unittest.TestResult())
 
1639
        self.assertEqual('original', obj.test_attr)
 
1640
 
 
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):
 
1645
 
 
1646
            def setUp(self):
 
1647
                tests.TestCase.setUp(self)
 
1648
                self.orig = self.overrideAttr(obj, 'test_attr', new='modified')
 
1649
 
 
1650
            def test_value(self):
 
1651
                self.assertEqual('original', self.orig)
 
1652
                self.assertEqual('modified', obj.test_attr)
 
1653
 
 
1654
        test = Test('test_value')
 
1655
        test.run(unittest.TestResult())
 
1656
        self.assertEqual('original', obj.test_attr)
 
1657
 
1637
1658
 
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
2764
2785
        # are loaded.
2765
2786
        calls = []
2766
 
        def _test_suite_testmod_names():
 
2787
        def testmod_names():
2767
2788
            calls.append("testmod_names")
2768
2789
            return [
2769
2790
                'bzrlib.tests.blackbox.test_branch',
2770
2791
                'bzrlib.tests.per_transport',
2771
2792
                'bzrlib.tests.test_selftest',
2772
2793
                ]
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)
 
2795
        def doctests():
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',