~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

Move working tree initialisation out from  Branch.initialize, deprecated Branch.initialize to Branch.create.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
 
38
38
import bzrlib.branch
39
39
import bzrlib.commands
40
 
from bzrlib.errors import BzrError
 
40
from bzrlib.errors import (BzrError,
 
41
                           FileExists,
 
42
                           UninitializableFormat,
 
43
                           )
41
44
import bzrlib.inventory
42
45
import bzrlib.merge3
43
46
import bzrlib.osutils
52
55
from bzrlib.trace import mutter
53
56
from bzrlib.tests.TestUtil import TestLoader, TestSuite
54
57
from bzrlib.tests.treeshape import build_tree_contents
 
58
from bzrlib.workingtree import WorkingTree
55
59
 
56
60
default_transport = LocalRelpathServer
57
61
 
658
662
        super(TestCaseWithTransport, self).__init__(methodName)
659
663
        self.__readonly_server = None
660
664
        self.__server = None
661
 
        self.transport_server = bzrlib.transport.local.LocalRelpathServer
 
665
        self.transport_server = default_transport
662
666
        self.transport_readonly_server = None
663
667
 
664
668
    def get_readonly_url(self, relpath=None):
700
704
            self.__server.setUp()
701
705
            self.addCleanup(self.__server.tearDown)
702
706
        base = self.__server.get_url()
703
 
        if relpath is not None:
 
707
        if relpath is not None and relpath != '.':
704
708
            if not base.endswith('/'):
705
709
                base = base + '/'
706
710
            base = base + relpath
707
711
        return base
708
712
 
 
713
    def make_branch(self, relpath):
 
714
        """Create a branch on the transport at relpath."""
 
715
        try:
 
716
            url = self.get_url(relpath)
 
717
            segments = relpath.split('/')
 
718
            if segments and segments[-1] not in ('', '.'):
 
719
                parent = self.get_url('/'.join(segments[:-1]))
 
720
                t = bzrlib.transport.get_transport(parent)
 
721
                try:
 
722
                    t.mkdir(segments[-1])
 
723
                except FileExists:
 
724
                    pass
 
725
            return bzrlib.branch.Branch.create(url)
 
726
        except UninitializableFormat:
 
727
            raise TestSkipped("Format %s is not initializable.")
 
728
 
 
729
    def make_branch_and_tree(self, relpath):
 
730
        """Create a branch on the transport and a tree locally.
 
731
 
 
732
        Returns the tree.
 
733
        """
 
734
        b = self.make_branch(relpath)
 
735
        return WorkingTree.create(b, relpath)
 
736
 
709
737
 
710
738
def filter_suite_by_re(suite, pattern):
711
739
    result = TestSuite()
752
780
    old_transport = default_transport
753
781
    default_transport = transport
754
782
    suite = test_suite()
755
 
    default_transport = old_transport
756
 
    return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
 
783
    try:
 
784
        return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
757
785
                     stop_on_failure=stop_on_failure, keep_output=keep_output,
758
786
                     transport=transport)
 
787
    finally:
 
788
        default_transport = old_transport
 
789
 
759
790
 
760
791
 
761
792
def test_suite():
797
828
                   'bzrlib.tests.test_parent',
798
829
                   'bzrlib.tests.test_permissions',
799
830
                   'bzrlib.tests.test_plugins',
800
 
                   'bzrlib.tests.test_remove',
801
831
                   'bzrlib.tests.test_revision',
802
832
                   'bzrlib.tests.test_revisionnamespaces',
803
833
                   'bzrlib.tests.test_revprops',
809
839
                   'bzrlib.tests.test_sftp_transport',
810
840
                   'bzrlib.tests.test_smart_add',
811
841
                   'bzrlib.tests.test_source',
812
 
                   'bzrlib.tests.test_status',
813
842
                   'bzrlib.tests.test_store',
814
843
                   'bzrlib.tests.test_symbol_versioning',
815
844
                   'bzrlib.tests.test_testament',