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
465
470
self.failIfExists('dir')
466
471
self.assertIsInstance(tree, memorytree.MemoryTree)
473
def test_make_branch_and_memory_tree_with_format(self):
474
"""make_branch_and_memory_tree should accept a format option."""
475
format = bzrdir.BzrDirMetaFormat1()
476
format.repository_format = repository.RepositoryFormat7()
477
tree = self.make_branch_and_memory_tree('dir', format=format)
478
self.failIfExists('dir')
479
self.assertIsInstance(tree, memorytree.MemoryTree)
480
self.assertEqual(format.repository_format.__class__,
481
tree.branch.repository._format.__class__)
469
484
class TestTestCaseWithTransport(TestCaseWithTransport):
470
485
"""Tests for the convenience functions TestCaseWithTransport introduces."""
488
503
def test_get_readonly_url_http(self):
489
504
from bzrlib.transport import get_transport
490
from bzrlib.transport.local import LocalRelpathServer
505
from bzrlib.transport.local import LocalURLServer
491
506
from bzrlib.transport.http import HttpServer, HttpTransportBase
492
self.transport_server = LocalRelpathServer
507
self.transport_server = LocalURLServer
493
508
self.transport_readonly_server = HttpServer
494
509
# calling get_readonly_transport() gives us a HTTP server instance.
495
510
url = self.get_readonly_url()
560
575
class TestTestResult(TestCase):
562
def test_progress_bar_style_quiet(self):
563
# test using a progress bar.
564
dummy_test = TestTestResult('test_progress_bar_style_quiet')
565
dummy_error = (Exception, None, [])
566
mypb = MockProgress()
567
mypb.update('Running tests', 0, 4)
568
last_calls = mypb.calls[:]
570
result = bzrlib.tests._MyResult(self._log_file,
574
self.assertEqual(last_calls, mypb.calls)
577
"""Shorten a string based on the terminal width"""
578
return result._ellipsise_unimportant_words(s,
579
osutils.terminal_width())
582
result.startTest(dummy_test)
583
# starting a test prints the test name
584
last_calls += [('update', '...tyle_quiet', 0, None)]
585
self.assertEqual(last_calls, mypb.calls)
586
result.addError(dummy_test, dummy_error)
587
last_calls += [('update', 'ERROR ', 1, None),
588
('note', shorten(dummy_test.id() + ': ERROR'), ())
590
self.assertEqual(last_calls, mypb.calls)
593
result.startTest(dummy_test)
594
last_calls += [('update', '...tyle_quiet', 1, None)]
595
self.assertEqual(last_calls, mypb.calls)
596
last_calls += [('update', 'FAIL ', 2, None),
597
('note', shorten(dummy_test.id() + ': FAIL'), ())
599
result.addFailure(dummy_test, dummy_error)
600
self.assertEqual(last_calls, mypb.calls)
603
result.startTest(dummy_test)
604
last_calls += [('update', '...tyle_quiet', 2, None)]
605
self.assertEqual(last_calls, mypb.calls)
606
result.addSuccess(dummy_test)
607
last_calls += [('update', 'OK ', 3, None)]
608
self.assertEqual(last_calls, mypb.calls)
611
result.startTest(dummy_test)
612
last_calls += [('update', '...tyle_quiet', 3, None)]
613
self.assertEqual(last_calls, mypb.calls)
614
result.addSkipped(dummy_test, dummy_error)
615
last_calls += [('update', 'SKIP ', 4, None)]
616
self.assertEqual(last_calls, mypb.calls)
618
577
def test_elapsed_time_with_benchmarking(self):
619
result = bzrlib.tests._MyResult(self._log_file,
578
result = bzrlib.tests.TextTestResult(self._log_file,
744
704
TestCaseInTempDir.TEST_ROOT = old_root
746
def test_accepts_and_uses_pb_parameter(self):
747
test = TestRunner('dummy_test')
748
mypb = MockProgress()
749
self.assertEqual([], mypb.calls)
750
runner = TextTestRunner(stream=self._log_file, pb=mypb)
751
result = self.run_test_runner(runner, test)
752
self.assertEqual(1, result.testsRun)
753
self.assertEqual(('update', 'Running tests', 0, 1), mypb.calls[0])
754
self.assertEqual(('update', '...dummy_test', 0, None), mypb.calls[1])
755
self.assertEqual(('update', 'OK ', 1, None), mypb.calls[2])
756
self.assertEqual(('update', 'Cleaning up', 0, 1), mypb.calls[3])
757
self.assertEqual(('clear',), mypb.calls[4])
758
self.assertEqual(5, len(mypb.calls))
760
706
def test_skipped_test(self):
761
707
# run a test that is skipped, and check the suite as a whole still