1
# Copyright (C) 2005, 2006 by Canonical Ltd
1
# Copyright (C) 2005, 2006 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License version 2 as published by
5
# the Free Software Foundation.
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
8
# This program is distributed in the hope that it will be useful,
8
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
503
503
def test_get_readonly_url_http(self):
504
504
from bzrlib.transport import get_transport
505
from bzrlib.transport.local import LocalRelpathServer
505
from bzrlib.transport.local import LocalURLServer
506
506
from bzrlib.transport.http import HttpServer, HttpTransportBase
507
self.transport_server = LocalRelpathServer
507
self.transport_server = LocalURLServer
508
508
self.transport_readonly_server = HttpServer
509
509
# calling get_readonly_transport() gives us a HTTP server instance.
510
510
url = self.get_readonly_url()
575
575
class TestTestResult(TestCase):
577
def test_progress_bar_style_quiet(self):
578
# test using a progress bar.
579
dummy_test = TestTestResult('test_progress_bar_style_quiet')
580
dummy_error = (Exception, None, [])
581
mypb = MockProgress()
582
mypb.update('Running tests', 0, 4)
583
last_calls = mypb.calls[:]
585
result = bzrlib.tests._MyResult(self._log_file,
589
self.assertEqual(last_calls, mypb.calls)
592
"""Shorten a string based on the terminal width"""
593
return result._ellipsise_unimportant_words(s,
594
osutils.terminal_width())
597
result.startTest(dummy_test)
598
# starting a test prints the test name
599
last_calls += [('update', '...tyle_quiet', 0, None)]
600
self.assertEqual(last_calls, mypb.calls)
601
result.addError(dummy_test, dummy_error)
602
last_calls += [('update', 'ERROR ', 1, None),
603
('note', shorten(dummy_test.id() + ': ERROR'), ())
605
self.assertEqual(last_calls, mypb.calls)
608
result.startTest(dummy_test)
609
last_calls += [('update', '...tyle_quiet', 1, None)]
610
self.assertEqual(last_calls, mypb.calls)
611
last_calls += [('update', 'FAIL ', 2, None),
612
('note', shorten(dummy_test.id() + ': FAIL'), ())
614
result.addFailure(dummy_test, dummy_error)
615
self.assertEqual(last_calls, mypb.calls)
618
result.startTest(dummy_test)
619
last_calls += [('update', '...tyle_quiet', 2, None)]
620
self.assertEqual(last_calls, mypb.calls)
621
result.addSuccess(dummy_test)
622
last_calls += [('update', 'OK ', 3, None)]
623
self.assertEqual(last_calls, mypb.calls)
626
result.startTest(dummy_test)
627
last_calls += [('update', '...tyle_quiet', 3, None)]
628
self.assertEqual(last_calls, mypb.calls)
629
result.addSkipped(dummy_test, dummy_error)
630
last_calls += [('update', 'SKIP ', 4, None)]
631
self.assertEqual(last_calls, mypb.calls)
633
577
def test_elapsed_time_with_benchmarking(self):
634
result = bzrlib.tests._MyResult(self._log_file,
578
result = bzrlib.tests.TextTestResult(self._log_file,
759
704
TestCaseInTempDir.TEST_ROOT = old_root
761
def test_accepts_and_uses_pb_parameter(self):
762
test = TestRunner('dummy_test')
763
mypb = MockProgress()
764
self.assertEqual([], mypb.calls)
765
runner = TextTestRunner(stream=self._log_file, pb=mypb)
766
result = self.run_test_runner(runner, test)
767
self.assertEqual(1, result.testsRun)
768
self.assertEqual(('update', 'Running tests', 0, 1), mypb.calls[0])
769
self.assertEqual(('update', '...dummy_test', 0, None), mypb.calls[1])
770
self.assertEqual(('update', 'OK ', 1, None), mypb.calls[2])
771
self.assertEqual(('update', 'Cleaning up', 0, 1), mypb.calls[3])
772
self.assertEqual(('clear',), mypb.calls[4])
773
self.assertEqual(5, len(mypb.calls))
775
706
def test_skipped_test(self):
776
707
# run a test that is skipped, and check the suite as a whole still
907
838
"""Test that the TestCase.time() method accumulates a benchmark time."""
908
839
sample_test = TestTestCase("method_that_times_a_bit_twice")
909
840
output_stream = StringIO()
910
result = bzrlib.tests._MyResult(
841
result = bzrlib.tests.VerboseTestResult(
911
842
unittest._WritelnDecorator(output_stream),
845
num_tests=sample_test.countTestCases())
914
846
sample_test.run(result)
915
847
self.assertContainsRe(
916
848
output_stream.getvalue(),
917
"[1-9][0-9]ms/ [1-9][0-9]ms\n$")
919
851
def test__gather_lsprof_in_benchmarks(self):
920
852
"""When _gather_lsprof_in_benchmarks is on, accumulate profile data.