~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_selftest.py

  • Committer: Martin Pool
  • Date: 2006-08-10 01:16:16 UTC
  • mto: (1904.1.2 0.9)
  • mto: This revision was merged to the branch mainline in revision 1913.
  • Revision ID: mbp@sourcefrog.net-20060810011616-d74881eba696e746
compare_trees is deprecated in 0.9 not 0.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by Canonical Ltd
2
2
#
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 as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
 
4
# it under the terms of the GNU General Public License version 2 as published by
 
5
# the Free Software Foundation.
7
6
#
8
7
# This program is distributed in the hope that it will be useful,
9
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
15
 
17
16
"""Tests for the test framework."""
18
17
 
19
 
import cStringIO
20
18
import os
21
19
from StringIO import StringIO
22
20
import sys
24
22
import unittest
25
23
import warnings
26
24
 
 
25
from bzrlib import osutils
27
26
import bzrlib
28
 
from bzrlib import (
29
 
    bzrdir,
30
 
    memorytree,
31
 
    osutils,
32
 
    repository,
33
 
    )
34
27
from bzrlib.progress import _BaseProgressBar
35
28
from bzrlib.tests import (
36
29
                          ChrootedTestCase,
37
30
                          TestCase,
38
31
                          TestCaseInTempDir,
39
 
                          TestCaseWithMemoryTransport,
40
32
                          TestCaseWithTransport,
41
33
                          TestSkipped,
42
34
                          TestSuite,
43
35
                          TextTestRunner,
44
36
                          )
45
 
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer
46
37
from bzrlib.tests.TestUtil import _load_module_by_name
47
38
import bzrlib.errors as errors
48
 
from bzrlib import symbol_versioning
49
 
from bzrlib.symbol_versioning import zero_ten, zero_eleven
50
39
from bzrlib.trace import note
51
 
from bzrlib.transport.memory import MemoryServer, MemoryTransport
52
 
from bzrlib.version import _get_bzr_source_tree
53
40
 
54
41
 
55
42
class SelftestTests(TestCase):
63
50
                          _load_module_by_name,
64
51
                          'bzrlib.no-name-yet')
65
52
 
 
53
 
66
54
class MetaTestLog(TestCase):
67
55
 
68
56
    def test_logging(self):
69
57
        """Test logs are captured when a test fails."""
70
58
        self.log('a test message')
71
59
        self._log_file.flush()
72
 
        self.assertContainsRe(self._get_log(keep_log_file=True),
73
 
                              'a test message\n')
 
60
        self.assertContainsRe(self._get_log(), 'a test message\n')
74
61
 
75
62
 
76
63
class TestTreeShape(TestCaseInTempDir):
430
417
        self.assertEqual(tests[1].transport_server, server1)
431
418
        self.assertEqual(tests[1].transport_readonly_server, server2)
432
419
 
433
 
 
434
 
class TestTestCaseInTempDir(TestCaseInTempDir):
435
 
 
436
 
    def test_home_is_not_working(self):
437
 
        self.assertNotEqual(self.test_dir, self.test_home_dir)
438
 
        cwd = osutils.getcwd()
439
 
        self.assertEqual(self.test_dir, cwd)
440
 
        self.assertEqual(self.test_home_dir, os.environ['HOME'])
441
 
 
442
 
 
443
 
class TestTestCaseWithMemoryTransport(TestCaseWithMemoryTransport):
444
 
 
445
 
    def test_home_is_non_existant_dir_under_root(self):
446
 
        """The test_home_dir for TestCaseWithMemoryTransport is missing.
447
 
 
448
 
        This is because TestCaseWithMemoryTransport is for tests that do not
449
 
        need any disk resources: they should be hooked into bzrlib in such a 
450
 
        way that no global settings are being changed by the test (only a 
451
 
        few tests should need to do that), and having a missing dir as home is
452
 
        an effective way to ensure that this is the case.
453
 
        """
454
 
        self.assertEqual(self.TEST_ROOT + "/MemoryTransportMissingHomeDir",
455
 
            self.test_home_dir)
456
 
        self.assertEqual(self.test_home_dir, os.environ['HOME'])
457
 
        
458
 
    def test_cwd_is_TEST_ROOT(self):
459
 
        self.assertEqual(self.test_dir, self.TEST_ROOT)
460
 
        cwd = osutils.getcwd()
461
 
        self.assertEqual(self.test_dir, cwd)
462
 
 
463
 
    def test_make_branch_and_memory_tree(self):
464
 
        """In TestCaseWithMemoryTransport we should not make the branch on disk.
465
 
 
466
 
        This is hard to comprehensively robustly test, so we settle for making
467
 
        a branch and checking no directory was created at its relpath.
468
 
        """
469
 
        tree = self.make_branch_and_memory_tree('dir')
470
 
        # Guard against regression into MemoryTransport leaking
471
 
        # files to disk instead of keeping them in memory.
472
 
        self.failIf(osutils.lexists('dir'))
473
 
        self.assertIsInstance(tree, memorytree.MemoryTree)
474
 
 
475
 
    def test_make_branch_and_memory_tree_with_format(self):
476
 
        """make_branch_and_memory_tree should accept a format option."""
477
 
        format = bzrdir.BzrDirMetaFormat1()
478
 
        format.repository_format = repository.RepositoryFormat7()
479
 
        tree = self.make_branch_and_memory_tree('dir', format=format)
480
 
        # Guard against regression into MemoryTransport leaking
481
 
        # files to disk instead of keeping them in memory.
482
 
        self.failIf(osutils.lexists('dir'))
483
 
        self.assertIsInstance(tree, memorytree.MemoryTree)
484
 
        self.assertEqual(format.repository_format.__class__,
485
 
            tree.branch.repository._format.__class__)
486
 
 
487
 
 
488
420
class TestTestCaseWithTransport(TestCaseWithTransport):
489
421
    """Tests for the convenience functions TestCaseWithTransport introduces."""
490
422
 
505
437
        self.assertEqual(t2.base[:-1], t.abspath('foo/bar'))
506
438
 
507
439
    def test_get_readonly_url_http(self):
508
 
        from bzrlib.tests.HttpServer import HttpServer
509
440
        from bzrlib.transport import get_transport
510
 
        from bzrlib.transport.local import LocalURLServer
511
 
        from bzrlib.transport.http import HttpTransportBase
512
 
        self.transport_server = LocalURLServer
 
441
        from bzrlib.transport.local import LocalRelpathServer
 
442
        from bzrlib.transport.http import HttpServer, HttpTransportBase
 
443
        self.transport_server = LocalRelpathServer
513
444
        self.transport_readonly_server = HttpServer
514
445
        # calling get_readonly_transport() gives us a HTTP server instance.
515
446
        url = self.get_readonly_url()
530
461
        self.assertRaises(AssertionError, self.assertIsDirectory, 'not_here', t)
531
462
 
532
463
 
533
 
class TestTestCaseTransports(TestCaseWithTransport):
534
 
 
535
 
    def setUp(self):
536
 
        super(TestTestCaseTransports, self).setUp()
537
 
        self.transport_server = MemoryServer
538
 
 
539
 
    def test_make_bzrdir_preserves_transport(self):
540
 
        t = self.get_transport()
541
 
        result_bzrdir = self.make_bzrdir('subdir')
542
 
        self.assertIsInstance(result_bzrdir.transport, 
543
 
                              MemoryTransport)
544
 
        # should not be on disk, should only be in memory
545
 
        self.failIfExists('subdir')
546
 
 
547
 
 
548
464
class TestChrootedTest(ChrootedTestCase):
549
465
 
550
466
    def test_root_is_root(self):
579
495
 
580
496
class TestTestResult(TestCase):
581
497
 
 
498
    def test_progress_bar_style_quiet(self):
 
499
        # test using a progress bar.
 
500
        dummy_test = TestTestResult('test_progress_bar_style_quiet')
 
501
        dummy_error = (Exception, None, [])
 
502
        mypb = MockProgress()
 
503
        mypb.update('Running tests', 0, 4)
 
504
        last_calls = mypb.calls[:]
 
505
 
 
506
        result = bzrlib.tests._MyResult(self._log_file,
 
507
                                        descriptions=0,
 
508
                                        verbosity=1,
 
509
                                        pb=mypb)
 
510
        self.assertEqual(last_calls, mypb.calls)
 
511
 
 
512
        def shorten(s):
 
513
            """Shorten a string based on the terminal width"""
 
514
            return result._ellipsise_unimportant_words(s,
 
515
                                 osutils.terminal_width())
 
516
 
 
517
        # an error 
 
518
        result.startTest(dummy_test)
 
519
        # starting a test prints the test name
 
520
        last_calls += [('update', '...tyle_quiet', 0, None)]
 
521
        self.assertEqual(last_calls, mypb.calls)
 
522
        result.addError(dummy_test, dummy_error)
 
523
        last_calls += [('update', 'ERROR        ', 1, None),
 
524
                       ('note', shorten(dummy_test.id() + ': ERROR'), ())
 
525
                      ]
 
526
        self.assertEqual(last_calls, mypb.calls)
 
527
 
 
528
        # a failure
 
529
        result.startTest(dummy_test)
 
530
        last_calls += [('update', '...tyle_quiet', 1, None)]
 
531
        self.assertEqual(last_calls, mypb.calls)
 
532
        last_calls += [('update', 'FAIL         ', 2, None),
 
533
                       ('note', shorten(dummy_test.id() + ': FAIL'), ())
 
534
                      ]
 
535
        result.addFailure(dummy_test, dummy_error)
 
536
        self.assertEqual(last_calls, mypb.calls)
 
537
 
 
538
        # a success
 
539
        result.startTest(dummy_test)
 
540
        last_calls += [('update', '...tyle_quiet', 2, None)]
 
541
        self.assertEqual(last_calls, mypb.calls)
 
542
        result.addSuccess(dummy_test)
 
543
        last_calls += [('update', 'OK           ', 3, None)]
 
544
        self.assertEqual(last_calls, mypb.calls)
 
545
 
 
546
        # a skip
 
547
        result.startTest(dummy_test)
 
548
        last_calls += [('update', '...tyle_quiet', 3, None)]
 
549
        self.assertEqual(last_calls, mypb.calls)
 
550
        result.addSkipped(dummy_test, dummy_error)
 
551
        last_calls += [('update', 'SKIP         ', 4, None)]
 
552
        self.assertEqual(last_calls, mypb.calls)
 
553
 
582
554
    def test_elapsed_time_with_benchmarking(self):
583
 
        result = bzrlib.tests.TextTestResult(self._log_file,
 
555
        result = bzrlib.tests._MyResult(self._log_file,
584
556
                                        descriptions=0,
585
557
                                        verbosity=1,
586
558
                                        )
589
561
        result.extractBenchmarkTime(self)
590
562
        timed_string = result._testTimeString()
591
563
        # without explicit benchmarking, we should get a simple time.
592
 
        self.assertContainsRe(timed_string, "^ *[ 1-9][0-9]ms$")
 
564
        self.assertContainsRe(timed_string, "^         [ 1-9][0-9]ms$")
593
565
        # if a benchmark time is given, we want a x of y style result.
594
566
        self.time(time.sleep, 0.001)
595
567
        result.extractBenchmarkTime(self)
596
568
        timed_string = result._testTimeString()
597
 
        self.assertContainsRe(timed_string, "^ *[ 1-9][0-9]ms/ *[ 1-9][0-9]ms$")
 
569
        self.assertContainsRe(timed_string, "^   [ 1-9][0-9]ms/   [ 1-9][0-9]ms$")
598
570
        # extracting the time from a non-bzrlib testcase sets to None
599
571
        result._recordTestStartTime()
600
572
        result.extractBenchmarkTime(
601
573
            unittest.FunctionTestCase(self.test_elapsed_time_with_benchmarking))
602
574
        timed_string = result._testTimeString()
603
 
        self.assertContainsRe(timed_string, "^ *[ 1-9][0-9]ms$")
 
575
        self.assertContainsRe(timed_string, "^         [ 1-9][0-9]ms$")
604
576
        # cheat. Yes, wash thy mouth out with soap.
605
577
        self._benchtime = None
606
578
 
607
 
    def test_assigned_benchmark_file_stores_date(self):
608
 
        output = StringIO()
609
 
        result = bzrlib.tests.TextTestResult(self._log_file,
610
 
                                        descriptions=0,
611
 
                                        verbosity=1,
612
 
                                        bench_history=output
613
 
                                        )
614
 
        output_string = output.getvalue()
615
 
        
616
 
        # if you are wondering about the regexp please read the comment in
617
 
        # test_bench_history (bzrlib.tests.test_selftest.TestRunner)
618
 
        # XXX: what comment?  -- Andrew Bennetts
619
 
        self.assertContainsRe(output_string, "--date [0-9.]+")
620
 
 
621
 
    def test_benchhistory_records_test_times(self):
622
 
        result_stream = StringIO()
623
 
        result = bzrlib.tests.TextTestResult(
624
 
            self._log_file,
625
 
            descriptions=0,
626
 
            verbosity=1,
627
 
            bench_history=result_stream
628
 
            )
629
 
 
630
 
        # we want profile a call and check that its test duration is recorded
631
 
        # make a new test instance that when run will generate a benchmark
632
 
        example_test_case = TestTestResult("_time_hello_world_encoding")
633
 
        # execute the test, which should succeed and record times
634
 
        example_test_case.run(result)
635
 
        lines = result_stream.getvalue().splitlines()
636
 
        self.assertEqual(2, len(lines))
637
 
        self.assertContainsRe(lines[1],
638
 
            " *[0-9]+ms bzrlib.tests.test_selftest.TestTestResult"
639
 
            "._time_hello_world_encoding")
640
 
 
641
579
    def _time_hello_world_encoding(self):
642
580
        """Profile two sleep calls
643
581
        
653
591
        except ImportError:
654
592
            raise TestSkipped("lsprof not installed.")
655
593
        result_stream = StringIO()
656
 
        result = bzrlib.tests.VerboseTestResult(
 
594
        result = bzrlib.tests._MyResult(
657
595
            unittest._WritelnDecorator(result_stream),
658
596
            descriptions=0,
659
597
            verbosity=2,
708
646
        finally:
709
647
            TestCaseInTempDir.TEST_ROOT = old_root
710
648
 
 
649
    def test_accepts_and_uses_pb_parameter(self):
 
650
        test = TestRunner('dummy_test')
 
651
        mypb = MockProgress()
 
652
        self.assertEqual([], mypb.calls)
 
653
        runner = TextTestRunner(stream=self._log_file, pb=mypb)
 
654
        result = self.run_test_runner(runner, test)
 
655
        self.assertEqual(1, result.testsRun)
 
656
        self.assertEqual(('update', 'Running tests', 0, 1), mypb.calls[0])
 
657
        self.assertEqual(('update', '...dummy_test', 0, None), mypb.calls[1])
 
658
        self.assertEqual(('update', 'OK           ', 1, None), mypb.calls[2])
 
659
        self.assertEqual(('update', 'Cleaning up', 0, 1), mypb.calls[3])
 
660
        self.assertEqual(('clear',), mypb.calls[4])
 
661
        self.assertEqual(5, len(mypb.calls))
 
662
 
711
663
    def test_skipped_test(self):
712
664
        # run a test that is skipped, and check the suite as a whole still
713
665
        # succeeds.
719
671
        result = self.run_test_runner(runner, test)
720
672
        self.assertTrue(result.wasSuccessful())
721
673
 
722
 
    def test_bench_history(self):
723
 
        # tests that the running the benchmark produces a history file
724
 
        # containing a timestamp and the revision id of the bzrlib source which
725
 
        # was tested.
726
 
        workingtree = _get_bzr_source_tree()
727
 
        test = TestRunner('dummy_test')
728
 
        output = StringIO()
729
 
        runner = TextTestRunner(stream=self._log_file, bench_history=output)
730
 
        result = self.run_test_runner(runner, test)
731
 
        output_string = output.getvalue()
732
 
        self.assertContainsRe(output_string, "--date [0-9.]+")
733
 
        if workingtree is not None:
734
 
            revision_id = workingtree.get_parent_ids()[0]
735
 
            self.assertEndsWith(output_string.rstrip(), revision_id)
736
 
 
737
 
    def test_success_log_deleted(self):
738
 
        """Successful tests have their log deleted"""
739
 
 
740
 
        class LogTester(TestCase):
741
 
 
742
 
            def test_success(self):
743
 
                self.log('this will be removed\n')
744
 
 
745
 
        sio = cStringIO.StringIO()
746
 
        runner = TextTestRunner(stream=sio)
747
 
        test = LogTester('test_success')
748
 
        result = self.run_test_runner(runner, test)
749
 
 
750
 
        log = test._get_log()
751
 
        self.assertEqual("DELETED log file to reduce memory footprint", log)
752
 
        self.assertEqual('', test._log_contents)
753
 
        self.assertIs(None, test._log_file_name)
754
 
 
755
 
    def test_fail_log_kept(self):
756
 
        """Failed tests have their log kept"""
757
 
 
758
 
        class LogTester(TestCase):
759
 
 
760
 
            def test_fail(self):
761
 
                self.log('this will be kept\n')
762
 
                self.fail('this test fails')
763
 
 
764
 
        sio = cStringIO.StringIO()
765
 
        runner = TextTestRunner(stream=sio)
766
 
        test = LogTester('test_fail')
767
 
        result = self.run_test_runner(runner, test)
768
 
 
769
 
        text = sio.getvalue()
770
 
        self.assertContainsRe(text, 'this will be kept')
771
 
        self.assertContainsRe(text, 'this test fails')
772
 
 
773
 
        log = test._get_log()
774
 
        self.assertContainsRe(log, 'this will be kept')
775
 
        self.assertEqual(log, test._log_contents)
776
 
 
777
 
    def test_error_log_kept(self):
778
 
        """Tests with errors have their log kept"""
779
 
 
780
 
        class LogTester(TestCase):
781
 
 
782
 
            def test_error(self):
783
 
                self.log('this will be kept\n')
784
 
                raise ValueError('random exception raised')
785
 
 
786
 
        sio = cStringIO.StringIO()
787
 
        runner = TextTestRunner(stream=sio)
788
 
        test = LogTester('test_error')
789
 
        result = self.run_test_runner(runner, test)
790
 
 
791
 
        text = sio.getvalue()
792
 
        self.assertContainsRe(text, 'this will be kept')
793
 
        self.assertContainsRe(text, 'random exception raised')
794
 
 
795
 
        log = test._get_log()
796
 
        self.assertContainsRe(log, 'this will be kept')
797
 
        self.assertEqual(log, test._log_contents)
798
 
 
799
674
 
800
675
class TestTestCase(TestCase):
801
676
    """Tests that test the core bzrlib TestCase."""
808
683
        # the outer child test
809
684
        note("outer_start")
810
685
        self.inner_test = TestTestCase("inner_child")
811
 
        result = bzrlib.tests.TextTestResult(self._log_file,
 
686
        result = bzrlib.tests._MyResult(self._log_file,
812
687
                                        descriptions=0,
813
688
                                        verbosity=1)
814
689
        self.inner_test.run(result)
828
703
        # the outer child test
829
704
        original_trace = bzrlib.trace._trace_file
830
705
        outer_test = TestTestCase("outer_child")
831
 
        result = bzrlib.tests.TextTestResult(self._log_file,
 
706
        result = bzrlib.tests._MyResult(self._log_file,
832
707
                                        descriptions=0,
833
708
                                        verbosity=1)
834
709
        outer_test.run(result)
843
718
        """Test that the TestCase.time() method accumulates a benchmark time."""
844
719
        sample_test = TestTestCase("method_that_times_a_bit_twice")
845
720
        output_stream = StringIO()
846
 
        result = bzrlib.tests.VerboseTestResult(
 
721
        result = bzrlib.tests._MyResult(
847
722
            unittest._WritelnDecorator(output_stream),
848
723
            descriptions=0,
849
 
            verbosity=2,
850
 
            num_tests=sample_test.countTestCases())
 
724
            verbosity=2)
851
725
        sample_test.run(result)
852
726
        self.assertContainsRe(
853
727
            output_stream.getvalue(),
854
 
            r"\d+ms/ +\d+ms\n$")
855
 
 
856
 
    def test_hooks_sanitised(self):
857
 
        """The bzrlib hooks should be sanitised by setUp."""
858
 
        self.assertEqual(bzrlib.branch.BranchHooks(),
859
 
            bzrlib.branch.Branch.hooks)
860
 
 
 
728
            "[1-9][0-9]ms/   [1-9][0-9]ms\n$")
 
729
        
861
730
    def test__gather_lsprof_in_benchmarks(self):
862
731
        """When _gather_lsprof_in_benchmarks is on, accumulate profile data.
863
732
        
879
748
        self.assertIsInstance(self._benchcalls[1][1], bzrlib.lsprof.Stats)
880
749
 
881
750
 
882
 
@symbol_versioning.deprecated_function(zero_eleven)
883
 
def sample_deprecated_function():
884
 
    """A deprecated function to test applyDeprecated with."""
885
 
    return 2
886
 
 
887
 
 
888
 
def sample_undeprecated_function(a_param):
889
 
    """A undeprecated function to test applyDeprecated with."""
890
 
 
891
 
 
892
 
class ApplyDeprecatedHelper(object):
893
 
    """A helper class for ApplyDeprecated tests."""
894
 
 
895
 
    @symbol_versioning.deprecated_method(zero_eleven)
896
 
    def sample_deprecated_method(self, param_one):
897
 
        """A deprecated method for testing with."""
898
 
        return param_one
899
 
 
900
 
    def sample_normal_method(self):
901
 
        """A undeprecated method."""
902
 
 
903
 
    @symbol_versioning.deprecated_method(zero_ten)
904
 
    def sample_nested_deprecation(self):
905
 
        return sample_deprecated_function()
906
 
 
907
 
 
908
751
class TestExtraAssertions(TestCase):
909
752
    """Tests for new test assertions in bzrlib test suite"""
910
753
 
918
761
        self.assertEndsWith('foo', 'oo')
919
762
        self.assertRaises(AssertionError, self.assertEndsWith, 'o', 'oo')
920
763
 
921
 
    def test_applyDeprecated_not_deprecated(self):
922
 
        sample_object = ApplyDeprecatedHelper()
923
 
        # calling an undeprecated callable raises an assertion
924
 
        self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
925
 
            sample_object.sample_normal_method)
926
 
        self.assertRaises(AssertionError, self.applyDeprecated, zero_eleven,
927
 
            sample_undeprecated_function, "a param value")
928
 
        # calling a deprecated callable (function or method) with the wrong
929
 
        # expected deprecation fails.
930
 
        self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
931
 
            sample_object.sample_deprecated_method, "a param value")
932
 
        self.assertRaises(AssertionError, self.applyDeprecated, zero_ten,
933
 
            sample_deprecated_function)
934
 
        # calling a deprecated callable (function or method) with the right
935
 
        # expected deprecation returns the functions result.
936
 
        self.assertEqual("a param value", self.applyDeprecated(zero_eleven,
937
 
            sample_object.sample_deprecated_method, "a param value"))
938
 
        self.assertEqual(2, self.applyDeprecated(zero_eleven,
939
 
            sample_deprecated_function))
940
 
        # calling a nested deprecation with the wrong deprecation version
941
 
        # fails even if a deeper nested function was deprecated with the 
942
 
        # supplied version.
943
 
        self.assertRaises(AssertionError, self.applyDeprecated,
944
 
            zero_eleven, sample_object.sample_nested_deprecation)
945
 
        # calling a nested deprecation with the right deprecation value
946
 
        # returns the calls result.
947
 
        self.assertEqual(2, self.applyDeprecated(zero_ten,
948
 
            sample_object.sample_nested_deprecation))
949
 
 
950
 
    def test_callDeprecated(self):
951
 
        def testfunc(be_deprecated, result=None):
952
 
            if be_deprecated is True:
953
 
                symbol_versioning.warn('i am deprecated', DeprecationWarning, 
954
 
                                       stacklevel=1)
955
 
            return result
956
 
        result = self.callDeprecated(['i am deprecated'], testfunc, True)
957
 
        self.assertIs(None, result)
958
 
        result = self.callDeprecated([], testfunc, False, 'result')
959
 
        self.assertEqual('result', result)
960
 
        self.callDeprecated(['i am deprecated'], testfunc, be_deprecated=True)
961
 
        self.callDeprecated([], testfunc, be_deprecated=False)
962
 
 
963
764
 
964
765
class TestConvenienceMakers(TestCaseWithTransport):
965
766
    """Test for the make_* convenience functions."""
973
774
        self.assertIsInstance(bzrlib.bzrdir.BzrDir.open('b')._format,
974
775
                              bzrlib.bzrdir.BzrDirFormat6)
975
776
 
976
 
    def test_make_branch_and_memory_tree(self):
977
 
        # we should be able to get a new branch and a mutable tree from
978
 
        # TestCaseWithTransport
979
 
        tree = self.make_branch_and_memory_tree('a')
980
 
        self.assertIsInstance(tree, bzrlib.memorytree.MemoryTree)
981
 
 
982
 
 
983
 
class TestSFTPMakeBranchAndTree(TestCaseWithSFTPServer):
984
 
 
985
 
    def test_make_tree_for_sftp_branch(self):
986
 
        """Transports backed by local directories create local trees."""
987
 
 
988
 
        tree = self.make_branch_and_tree('t1')
989
 
        base = tree.bzrdir.root_transport.base
990
 
        self.failIf(base.startswith('sftp'),
991
 
                'base %r is on sftp but should be local' % base)
992
 
        self.assertEquals(tree.bzrdir.root_transport,
993
 
                tree.branch.bzrdir.root_transport)
994
 
        self.assertEquals(tree.bzrdir.root_transport,
995
 
                tree.branch.repository.bzrdir.root_transport)
996
 
 
997
777
 
998
778
class TestSelftest(TestCase):
999
779
    """Tests of bzrlib.tests.selftest."""
1008
788
        self.apply_redirected(out, err, None, bzrlib.tests.selftest, 
1009
789
            test_suite_factory=factory)
1010
790
        self.assertEqual([True], factory_called)
1011
 
 
1012
 
 
1013
 
class TestSelftestCleanOutput(TestCaseInTempDir):
1014
 
 
1015
 
    def test_clean_output(self):
1016
 
        # test functionality of clean_selftest_output()
1017
 
        from bzrlib.tests import clean_selftest_output
1018
 
 
1019
 
        dirs = ('test0000.tmp', 'test0001.tmp', 'bzrlib', 'tests')
1020
 
        files = ('bzr', 'setup.py', 'test9999.tmp')
1021
 
        for i in dirs:
1022
 
            os.mkdir(i)
1023
 
        for i in files:
1024
 
            f = file(i, 'wb')
1025
 
            f.write('content of ')
1026
 
            f.write(i)
1027
 
            f.close()
1028
 
 
1029
 
        root = os.getcwdu()
1030
 
        before = os.listdir(root)
1031
 
        before.sort()
1032
 
        self.assertEquals(['bzr','bzrlib','setup.py',
1033
 
                           'test0000.tmp','test0001.tmp',
1034
 
                           'test9999.tmp','tests'],
1035
 
                           before)
1036
 
        clean_selftest_output(root, quiet=True)
1037
 
        after = os.listdir(root)
1038
 
        after.sort()
1039
 
        self.assertEquals(['bzr','bzrlib','setup.py',
1040
 
                           'test9999.tmp','tests'],
1041
 
                           after)