~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Andrew Bennetts
  • Date: 2011-04-08 03:31:54 UTC
  • mfrom: (5766 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5767.
  • Revision ID: andrew.bennetts@canonical.com-20110408033154-la08nghd4391sw5m
Merge latest lp:bzr, move our new release notes entries to the current release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
749
749
        self.check_timing(ShortDelayTestCase('test_short_delay'),
750
750
                          r"^ +[0-9]+ms$")
751
751
 
752
 
    def _patch_get_bzr_source_tree(self):
753
 
        # Reading from the actual source tree breaks isolation, but we don't
754
 
        # want to assume that thats *all* that would happen.
755
 
        self.overrideAttr(bzrlib.version, '_get_bzr_source_tree', lambda: None)
756
 
 
757
 
    def test_assigned_benchmark_file_stores_date(self):
758
 
        self._patch_get_bzr_source_tree()
759
 
        output = StringIO()
760
 
        result = bzrlib.tests.TextTestResult(self._log_file,
761
 
                                        descriptions=0,
762
 
                                        verbosity=1,
763
 
                                        bench_history=output
764
 
                                        )
765
 
        output_string = output.getvalue()
766
 
        # if you are wondering about the regexp please read the comment in
767
 
        # test_bench_history (bzrlib.tests.test_selftest.TestRunner)
768
 
        # XXX: what comment?  -- Andrew Bennetts
769
 
        self.assertContainsRe(output_string, "--date [0-9.]+")
770
 
 
771
 
    def test_benchhistory_records_test_times(self):
772
 
        self._patch_get_bzr_source_tree()
773
 
        result_stream = StringIO()
774
 
        result = bzrlib.tests.TextTestResult(
775
 
            self._log_file,
776
 
            descriptions=0,
777
 
            verbosity=1,
778
 
            bench_history=result_stream
779
 
            )
780
 
 
781
 
        # we want profile a call and check that its test duration is recorded
782
 
        # make a new test instance that when run will generate a benchmark
783
 
        example_test_case = TestTestResult("_time_hello_world_encoding")
784
 
        # execute the test, which should succeed and record times
785
 
        example_test_case.run(result)
786
 
        lines = result_stream.getvalue().splitlines()
787
 
        self.assertEqual(2, len(lines))
788
 
        self.assertContainsRe(lines[1],
789
 
            " *[0-9]+ms bzrlib.tests.test_selftest.TestTestResult"
790
 
            "._time_hello_world_encoding")
791
 
 
792
752
    def _time_hello_world_encoding(self):
793
753
        """Profile two sleep calls
794
754
 
1213
1173
            ],
1214
1174
            lines[-3:])
1215
1175
 
1216
 
    def _patch_get_bzr_source_tree(self):
1217
 
        # Reading from the actual source tree breaks isolation, but we don't
1218
 
        # want to assume that thats *all* that would happen.
1219
 
        self._get_source_tree_calls = []
1220
 
        def new_get():
1221
 
            self._get_source_tree_calls.append("called")
1222
 
            return None
1223
 
        self.overrideAttr(bzrlib.version, '_get_bzr_source_tree',  new_get)
1224
 
 
1225
 
    def test_bench_history(self):
1226
 
        # tests that the running the benchmark passes bench_history into
1227
 
        # the test result object. We can tell that happens if
1228
 
        # _get_bzr_source_tree is called.
1229
 
        self._patch_get_bzr_source_tree()
1230
 
        test = TestRunner('dummy_test')
1231
 
        output = StringIO()
1232
 
        runner = tests.TextTestRunner(stream=self._log_file,
1233
 
                                      bench_history=output)
1234
 
        result = self.run_test_runner(runner, test)
1235
 
        output_string = output.getvalue()
1236
 
        self.assertContainsRe(output_string, "--date [0-9.]+")
1237
 
        self.assertLength(1, self._get_source_tree_calls)
1238
 
 
1239
1176
    def test_verbose_test_count(self):
1240
1177
        """A verbose test run reports the right test count at the start"""
1241
1178
        suite = TestUtil.TestSuite([
1486
1423
        # Note this test won't fail with hooks that the core library doesn't
1487
1424
        # use - but it trigger with a plugin that adds hooks, so its still a
1488
1425
        # useful warning in that case.
1489
 
        self.assertEqual(bzrlib.branch.BranchHooks(),
1490
 
            bzrlib.branch.Branch.hooks)
1491
 
        self.assertEqual(bzrlib.smart.server.SmartServerHooks(),
 
1426
        self.assertEqual(bzrlib.branch.BranchHooks(), bzrlib.branch.Branch.hooks)
 
1427
        self.assertEqual(
 
1428
            bzrlib.smart.server.SmartServerHooks(),
1492
1429
            bzrlib.smart.server.SmartTCPServer.hooks)
1493
 
        self.assertEqual(bzrlib.commands.CommandHooks(),
1494
 
            bzrlib.commands.Command.hooks)
 
1430
        self.assertEqual(
 
1431
            bzrlib.commands.CommandHooks(), bzrlib.commands.Command.hooks)
1495
1432
 
1496
1433
    def test__gather_lsprof_in_benchmarks(self):
1497
1434
        """When _gather_lsprof_in_benchmarks is on, accumulate profile data.