458
459
self.time(time.sleep, 0.001)
459
460
result.extractBenchmarkTime(self)
460
461
timed_string = result._testTimeString()
461
self.assertContainsRe(timed_string, "^ [0-9]ms/ [ 1-9][0-9]ms$")
462
self.assertContainsRe(timed_string, "^ [ 1-9][0-9]ms/ [ 1-9][0-9]ms$")
462
463
# extracting the time from a non-bzrlib testcase sets to None
463
464
result._recordTestStartTime()
464
465
result.extractBenchmarkTime(
465
466
unittest.FunctionTestCase(self.test_elapsed_time_with_benchmarking))
466
467
timed_string = result._testTimeString()
467
self.assertContainsRe(timed_string, "^ [0-9]ms$")
468
self.assertContainsRe(timed_string, "^ [ 1-9][0-9]ms$")
468
469
# cheat. Yes, wash thy mouth out with soap.
469
470
self._benchtime = None
506
507
# 1 0 ??? ??? ???(sleep)
507
508
# and then repeated but with 'world', rather than 'hello'.
508
509
# 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"
510
output = result_stream.getvalue()
511
self.assertContainsRe(output,
512
r"LSProf output for <type 'unicode'>\(\('hello',\), {'errors': 'replace'}\)")
513
self.assertContainsRe(output,
514
r" *CallCount *Recursive *Total\(ms\) *Inline\(ms\) *module:lineno\(function\)\n")
515
self.assertContainsRe(output,
516
r"( +1 +0 +0\.\d+ +0\.\d+ +<method 'disable' of '_lsprof\.Profiler' objects>\n)?")
517
self.assertContainsRe(output,
518
r"LSProf output for <type 'unicode'>\(\('world',\), {'errors': 'replace'}\)\n")
519
521
class TestRunner(TestCase):
679
681
self.apply_redirected(out, err, None, bzrlib.tests.selftest,
680
682
test_suite_factory=factory)
681
683
self.assertEqual([True], factory_called)
685
def test_run_bzr_subprocess(self):
686
"""The run_bzr_helper_external comand behaves nicely."""
687
result = self.run_bzr_subprocess('--version')
688
result = self.run_bzr_subprocess('--version', retcode=None)
689
self.assertContainsRe(result[0], 'is free software')
690
self.assertRaises(AssertionError, self.run_bzr_subprocess,
692
result = self.run_bzr_subprocess('--versionn', retcode=3)
693
result = self.run_bzr_subprocess('--versionn', retcode=None)
694
self.assertContainsRe(result[1], 'unknown command')
695
err = self.run_bzr_subprocess('merge', '--merge-type', 'magic merge',
697
self.assertContainsRe(err, 'No known merge type magic merge')
699
def test_run_bzr_error(self):
700
out, err = self.run_bzr_error(['^$'], 'rocks', retcode=0)
701
self.assertEqual(out, 'it sure does!\n')
703
out, err = self.run_bzr_error(["'foobarbaz' is not a versioned file"],
704
'file-id', 'foobarbaz')