749
749
self.check_timing(ShortDelayTestCase('test_short_delay'),
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)
757
def test_assigned_benchmark_file_stores_date(self):
758
self._patch_get_bzr_source_tree()
760
result = bzrlib.tests.TextTestResult(self._log_file,
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.]+")
771
def test_benchhistory_records_test_times(self):
772
self._patch_get_bzr_source_tree()
773
result_stream = StringIO()
774
result = bzrlib.tests.TextTestResult(
778
bench_history=result_stream
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")
792
752
def _time_hello_world_encoding(self):
793
753
"""Profile two sleep calls
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 = []
1221
self._get_source_tree_calls.append("called")
1223
self.overrideAttr(bzrlib.version, '_get_bzr_source_tree', new_get)
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')
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)
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)
1428
bzrlib.smart.server.SmartServerHooks(),
1492
1429
bzrlib.smart.server.SmartTCPServer.hooks)
1493
self.assertEqual(bzrlib.commands.CommandHooks(),
1494
bzrlib.commands.Command.hooks)
1431
bzrlib.commands.CommandHooks(), bzrlib.commands.Command.hooks)
1496
1433
def test__gather_lsprof_in_benchmarks(self):
1497
1434
"""When _gather_lsprof_in_benchmarks is on, accumulate profile data.