395
395
self.calls.append(('clear',))
398
class TestResult(TestCase):
398
class TestTestResult(TestCase):
400
400
def test_progress_bar_style_quiet(self):
401
401
# test using a progress bar.
468
468
# cheat. Yes, wash thy mouth out with soap.
469
469
self._benchtime = None
471
def _time_hello_world_encoding(self):
472
"""Profile two sleep calls
474
This is used to exercise the test framework.
476
self.time(unicode, 'hello', errors='replace')
477
self.time(unicode, 'world', errors='replace')
479
def test_lsprofiling(self):
480
"""Verbose test result prints lsprof statistics from test cases."""
484
raise TestSkipped("lsprof not installed.")
485
result_stream = StringIO()
486
result = bzrlib.tests._MyResult(
487
unittest._WritelnDecorator(result_stream),
491
# we want profile a call of some sort and check it is output by
492
# addSuccess. We dont care about addError or addFailure as they
493
# are not that interesting for performance tuning.
494
# make a new test instance that when run will generate a profile
495
example_test_case = TestTestResult("_time_hello_world_encoding")
496
example_test_case._gather_lsprof_in_benchmarks = True
497
# execute the test, which should succeed and record profiles
498
example_test_case.run(result)
499
# lsprofile_something()
500
# if this worked we want
501
# LSProf output for <built in function unicode> (['hello'], {'errors': 'replace'})
502
# CallCount Recursive Total(ms) Inline(ms) module:lineno(function)
503
# (the lsprof header)
504
# ... an arbitrary number of lines
505
# and the function call which is time.sleep.
506
# 1 0 ??? ??? ???(sleep)
507
# and then repeated but with 'world', rather than 'hello'.
508
# this should appear in the output stream of our test result.
509
self.assertContainsRe(result_stream.getvalue(),
510
r"LSProf output for <type 'unicode'>\(\('hello',\), {'errors': 'replace'}\)\n"
511
r" *CallCount *Recursive *Total\(ms\) *Inline\(ms\) *module:lineno\(function\)\n"
512
r" +1 +0 +0\.\d+ +0\.\d+ +<method 'disable' of '_lsprof\.Profiler' objects>\n"
513
r"LSProf output for <type 'unicode'>\(\('world',\), {'errors': 'replace'}\)\n"
514
r" *CallCount *Recursive *Total\(ms\) *Inline\(ms\) *module:lineno\(function\)\n"
515
r" +1 +0 +0\.\d+ +0\.\d+ +<method 'disable' of '_lsprof\.Profiler' objects>\n"
472
519
class TestRunner(TestCase):
571
618
output_stream.getvalue(),
572
619
"[1-9][0-9]ms/ [1-9][0-9]ms\n$")
621
def test__gather_lsprof_in_benchmarks(self):
622
"""When _gather_lsprof_in_benchmarks is on, accumulate profile data.
624
Each self.time() call is individually and separately profiled.
629
raise TestSkipped("lsprof not installed.")
630
# overrides the class member with an instance member so no cleanup
632
self._gather_lsprof_in_benchmarks = True
633
self.time(time.sleep, 0.000)
634
self.time(time.sleep, 0.003)
635
self.assertEqual(2, len(self._benchcalls))
636
self.assertEqual((time.sleep, (0.000,), {}), self._benchcalls[0][0])
637
self.assertEqual((time.sleep, (0.003,), {}), self._benchcalls[1][0])
638
self.assertIsInstance(self._benchcalls[0][1], bzrlib.lsprof.Stats)
639
self.assertIsInstance(self._benchcalls[1][1], bzrlib.lsprof.Stats)
575
642
class TestExtraAssertions(TestCase):
576
643
"""Tests for new test assertions in bzrlib test suite"""