38
39
import bzrlib.branch
40
import bzrlib.bzrdir as bzrdir
39
41
import bzrlib.commands
40
from bzrlib.errors import (BzrError,
42
UninitializableFormat,
42
import bzrlib.errors as errors
44
43
import bzrlib.inventory
45
44
import bzrlib.iterablefile
46
46
import bzrlib.merge3
47
47
import bzrlib.osutils
48
48
import bzrlib.osutils as osutils
49
49
import bzrlib.plugin
50
50
import bzrlib.store
51
51
import bzrlib.trace
52
from bzrlib.transport import urlescape
52
from bzrlib.transport import urlescape, get_transport
53
53
import bzrlib.transport
54
54
from bzrlib.transport.local import LocalRelpathServer
55
55
from bzrlib.transport.readonly import ReadonlyServer
56
56
from bzrlib.trace import mutter
57
57
from bzrlib.tests.TestUtil import TestLoader, TestSuite
58
58
from bzrlib.tests.treeshape import build_tree_contents
59
from bzrlib.workingtree import WorkingTree
59
from bzrlib.workingtree import WorkingTree, WorkingTreeFormat2
61
61
default_transport = LocalRelpathServer
82
83
import bzrlib.tests.blackbox
83
84
import bzrlib.tests.branch_implementations
85
import bzrlib.tests.bzrdir_implementations
86
import bzrlib.tests.interrepository_implementations
87
import bzrlib.tests.repository_implementations
88
import bzrlib.tests.workingtree_implementations
91
bzrlib.tests.blackbox,
86
92
bzrlib.tests.branch_implementations,
93
bzrlib.tests.bzrdir_implementations,
94
bzrlib.tests.interrepository_implementations,
95
bzrlib.tests.repository_implementations,
96
bzrlib.tests.workingtree_implementations,
259
269
charjunk=lambda x: False)
260
270
return ''.join(difflines)
262
def assertEqualDiff(self, a, b):
272
def assertEqualDiff(self, a, b, message=None):
263
273
"""Assert two texts are equal, if not raise an exception.
265
275
This is intended for use with multi-line strings where it can
268
278
# TODO: perhaps override assertEquals to call this for strings?
271
raise AssertionError("texts not equal:\n" +
282
message = "texts not equal:\n"
283
raise AssertionError(message +
272
284
self._ndiff_strings(a, b))
286
def assertEqualMode(self, mode, mode_test):
287
self.assertEqual(mode, mode_test,
288
'mode mismatch %o != %o' % (mode, mode_test))
274
290
def assertStartsWith(self, s, prefix):
275
291
if not s.startswith(prefix):
276
292
raise AssertionError('string %r does not start with %r' % (s, prefix))
663
679
relpath provides for clients to get a path relative to the base url.
664
680
These should only be downwards relative, not upwards.
682
base = self.get_readonly_server().get_url()
683
if relpath is not None:
684
if not base.endswith('/'):
686
base = base + relpath
689
def get_readonly_server(self):
690
"""Get the server instance for the readonly transport
692
This is useful for some tests with specific servers to do diagnostics.
666
694
if self.__readonly_server is None:
667
695
if self.transport_readonly_server is None:
668
696
# readonly decorator requested
674
702
self.__readonly_server = self.transport_readonly_server()
675
703
self.__readonly_server.setUp()
676
704
self.addCleanup(self.__readonly_server.tearDown)
677
base = self.__readonly_server.get_url()
678
if relpath is not None:
679
if not base.endswith('/'):
681
base = base + relpath
705
return self.__readonly_server
707
def get_server(self):
708
"""Get the read/write server instance.
710
This is useful for some tests with specific servers that need
713
if self.__server is None:
714
self.__server = self.transport_server()
715
self.__server.setUp()
716
self.addCleanup(self.__server.tearDown)
684
719
def get_url(self, relpath=None):
685
720
"""Get a URL for the readwrite transport.
689
724
relpath provides for clients to get a path relative to the base url.
690
725
These should only be downwards relative, not upwards.
692
if self.__server is None:
693
self.__server = self.transport_server()
694
self.__server.setUp()
695
self.addCleanup(self.__server.tearDown)
696
base = self.__server.get_url()
727
base = self.get_server().get_url()
697
728
if relpath is not None and relpath != '.':
698
729
if not base.endswith('/'):
699
730
base = base + '/'
700
731
base = base + relpath
734
def get_transport(self):
735
"""Return a writeable transport for the test scratch space"""
736
t = get_transport(self.get_url())
737
self.assertFalse(t.is_readonly())
740
def get_readonly_transport(self):
741
"""Return a readonly transport for the test scratch space
743
This can be used to test that operations which should only need
744
readonly access in fact do not try to write.
746
t = get_transport(self.get_readonly_url())
747
self.assertTrue(t.is_readonly())
703
750
def make_branch(self, relpath):
704
751
"""Create a branch on the transport at relpath."""
752
repo = self.make_repository(relpath)
753
return repo.bzrdir.create_branch()
755
def make_bzrdir(self, relpath):
706
757
url = self.get_url(relpath)
707
758
segments = relpath.split('/')
708
759
if segments and segments[-1] not in ('', '.'):
709
760
parent = self.get_url('/'.join(segments[:-1]))
710
t = bzrlib.transport.get_transport(parent)
761
t = get_transport(parent)
712
763
t.mkdir(segments[-1])
764
except errors.FileExists:
715
return bzrlib.branch.Branch.create(url)
716
except UninitializableFormat:
766
return bzrlib.bzrdir.BzrDir.create(url)
767
except errors.UninitializableFormat:
717
768
raise TestSkipped("Format %s is not initializable.")
770
def make_repository(self, relpath, shared=False):
771
"""Create a repository on our default transport at relpath."""
772
made_control = self.make_bzrdir(relpath)
773
return made_control.create_repository(shared=shared)
719
775
def make_branch_and_tree(self, relpath):
720
776
"""Create a branch on the transport and a tree locally.
722
778
Returns the tree.
780
# TODO: always use the local disk path for the working tree,
781
# this obviously requires a format that supports branch references
782
# so check for that by checking bzrdir.BzrDirFormat.get_default_format()
724
784
b = self.make_branch(relpath)
725
return WorkingTree.create(b, relpath)
786
return b.bzrdir.create_workingtree()
787
except errors.NotLocalUrl:
788
# new formats - catch No tree error and create
789
# a branch reference and a checkout.
790
# old formats at that point - raise TestSkipped.
792
return WorkingTreeFormat2().initialize(bzrdir.BzrDir.open(relpath))
728
795
class ChrootedTestCase(TestCaseWithTransport):
810
877
'bzrlib.tests.test_bad_files',
811
878
'bzrlib.tests.test_basis_inventory',
812
879
'bzrlib.tests.test_branch',
880
'bzrlib.tests.test_bzrdir',
813
881
'bzrlib.tests.test_command',
814
882
'bzrlib.tests.test_commit',
815
883
'bzrlib.tests.test_commit_merge',
818
886
'bzrlib.tests.test_decorators',
819
887
'bzrlib.tests.test_diff',
820
888
'bzrlib.tests.test_doc_generate',
889
'bzrlib.tests.test_errors',
821
890
'bzrlib.tests.test_fetch',
822
'bzrlib.tests.test_fileid_involved',
823
891
'bzrlib.tests.test_gpg',
824
892
'bzrlib.tests.test_graph',
825
893
'bzrlib.tests.test_hashcache',
826
894
'bzrlib.tests.test_http',
827
895
'bzrlib.tests.test_identitymap',
828
896
'bzrlib.tests.test_inv',
897
'bzrlib.tests.test_lockdir',
829
898
'bzrlib.tests.test_lockable_files',
830
899
'bzrlib.tests.test_log',
831
900
'bzrlib.tests.test_merge',
836
905
'bzrlib.tests.test_nonascii',
837
906
'bzrlib.tests.test_options',
838
907
'bzrlib.tests.test_osutils',
839
'bzrlib.tests.test_parent',
840
908
'bzrlib.tests.test_permissions',
841
909
'bzrlib.tests.test_plugins',
910
'bzrlib.tests.test_reconcile',
911
'bzrlib.tests.test_repository',
842
912
'bzrlib.tests.test_revision',
843
913
'bzrlib.tests.test_revisionnamespaces',
844
914
'bzrlib.tests.test_revprops',
855
925
'bzrlib.tests.test_testament',
856
926
'bzrlib.tests.test_trace',
857
927
'bzrlib.tests.test_transactions',
928
'bzrlib.tests.test_transform',
858
929
'bzrlib.tests.test_transport',
859
930
'bzrlib.tests.test_tsort',
860
931
'bzrlib.tests.test_ui',