57
56
from bzrlib.trace import mutter
58
57
from bzrlib.tests.TestUtil import TestLoader, TestSuite
59
58
from bzrlib.tests.treeshape import build_tree_contents
60
from bzrlib.workingtree import WorkingTree
59
from bzrlib.workingtree import WorkingTree, WorkingTreeFormat2
62
61
default_transport = LocalRelpathServer
83
82
import bzrlib.tests.blackbox
84
83
import bzrlib.tests.branch_implementations
84
import bzrlib.tests.bzrdir_implementations
85
import bzrlib.tests.repository_implementations
86
import bzrlib.tests.workingtree_implementations
87
89
bzrlib.tests.blackbox,
88
90
bzrlib.tests.branch_implementations,
91
bzrlib.tests.bzrdir_implementations,
92
bzrlib.tests.repository_implementations,
93
bzrlib.tests.workingtree_implementations,
329
334
charjunk=lambda x: False)
330
335
return ''.join(difflines)
332
def assertEqualDiff(self, a, b):
337
def assertEqualDiff(self, a, b, message=None):
333
338
"""Assert two texts are equal, if not raise an exception.
335
340
This is intended for use with multi-line strings where it can
338
343
# TODO: perhaps override assertEquals to call this for strings?
341
raise AssertionError("texts not equal:\n" +
347
message = "texts not equal:\n"
348
raise AssertionError(message +
342
349
self._ndiff_strings(a, b))
351
def assertEqualMode(self, mode, mode_test):
352
self.assertEqual(mode, mode_test,
353
'mode mismatch %o != %o' % (mode, mode_test))
344
355
def assertStartsWith(self, s, prefix):
345
356
if not s.startswith(prefix):
346
357
raise AssertionError('string %r does not start with %r' % (s, prefix))
683
694
elif line_endings == 'native':
686
raise BzrError('Invalid line ending request %r' % (line_endings,))
697
raise errors.BzrError('Invalid line ending request %r' % (line_endings,))
687
698
content = "contents of %s%s" % (name, end)
688
699
transport.put(urlescape(name), StringIO(content))
733
744
relpath provides for clients to get a path relative to the base url.
734
745
These should only be downwards relative, not upwards.
747
base = self.get_readonly_server().get_url()
748
if relpath is not None:
749
if not base.endswith('/'):
751
base = base + relpath
754
def get_readonly_server(self):
755
"""Get the server instance for the readonly transport
757
This is useful for some tests with specific servers to do diagnostics.
736
759
if self.__readonly_server is None:
737
760
if self.transport_readonly_server is None:
738
761
# readonly decorator requested
744
767
self.__readonly_server = self.transport_readonly_server()
745
768
self.__readonly_server.setUp()
746
769
self.addCleanup(self.__readonly_server.tearDown)
747
base = self.__readonly_server.get_url()
748
if relpath is not None:
749
if not base.endswith('/'):
751
base = base + relpath
770
return self.__readonly_server
772
def get_server(self):
773
"""Get the read/write server instance.
775
This is useful for some tests with specific servers that need
778
if self.__server is None:
779
self.__server = self.transport_server()
780
self.__server.setUp()
781
self.addCleanup(self.__server.tearDown)
754
784
def get_url(self, relpath=None):
755
785
"""Get a URL for the readwrite transport.
759
789
relpath provides for clients to get a path relative to the base url.
760
790
These should only be downwards relative, not upwards.
762
if self.__server is None:
763
self.__server = self.transport_server()
764
self.__server.setUp()
765
self.addCleanup(self.__server.tearDown)
766
base = self.__server.get_url()
792
base = self.get_server().get_url()
767
793
if relpath is not None and relpath != '.':
768
794
if not base.endswith('/'):
769
795
base = base + '/'
773
799
def make_branch(self, relpath):
774
800
"""Create a branch on the transport at relpath."""
801
repo = self.make_repository(relpath)
802
return repo.bzrdir.create_branch()
804
def make_bzrdir(self, relpath):
776
806
url = self.get_url(relpath)
777
segments = relpath.split('/')
807
segments = url.split('/')
778
808
if segments and segments[-1] not in ('', '.'):
779
parent = self.get_url('/'.join(segments[:-1]))
809
parent = '/'.join(segments[:-1])
780
810
t = bzrlib.transport.get_transport(parent)
782
812
t.mkdir(segments[-1])
813
except errors.FileExists:
785
return bzrlib.branch.Branch.create(url)
786
except UninitializableFormat:
815
return bzrlib.bzrdir.BzrDir.create(url)
816
except errors.UninitializableFormat:
787
817
raise TestSkipped("Format %s is not initializable.")
819
def make_repository(self, relpath):
820
"""Create a repository on our default transport at relpath."""
821
made_control = self.make_bzrdir(relpath)
822
return made_control.create_repository()
789
824
def make_branch_and_tree(self, relpath):
790
825
"""Create a branch on the transport and a tree locally.
792
827
Returns the tree.
829
# TODO: always use the local disk path for the working tree,
830
# this obviously requires a format that supports branch references
831
# so check for that by checking bzrdir.BzrDirFormat.get_default_format()
794
833
b = self.make_branch(relpath)
795
return WorkingTree.create(b, relpath)
835
return b.bzrdir.create_workingtree()
836
except errors.NotLocalUrl:
837
# new formats - catch No tree error and create
838
# a branch reference and a checkout.
839
# old formats at that point - raise TestSkipped.
841
return WorkingTreeFormat2().initialize(bzrdir.BzrDir.open(relpath))
798
844
class ChrootedTestCase(TestCaseWithTransport):
876
922
'bzrlib.tests.test_bad_files',
877
923
'bzrlib.tests.test_basis_inventory',
878
924
'bzrlib.tests.test_branch',
925
'bzrlib.tests.test_bzrdir',
879
926
'bzrlib.tests.test_command',
880
927
'bzrlib.tests.test_commit',
881
928
'bzrlib.tests.test_commit_merge',
884
931
'bzrlib.tests.test_decorators',
885
932
'bzrlib.tests.test_diff',
886
933
'bzrlib.tests.test_doc_generate',
934
'bzrlib.tests.test_errors',
887
935
'bzrlib.tests.test_fetch',
888
'bzrlib.tests.test_fileid_involved',
889
936
'bzrlib.tests.test_gpg',
890
937
'bzrlib.tests.test_graph',
891
938
'bzrlib.tests.test_hashcache',
902
949
'bzrlib.tests.test_nonascii',
903
950
'bzrlib.tests.test_options',
904
951
'bzrlib.tests.test_osutils',
905
'bzrlib.tests.test_parent',
906
952
'bzrlib.tests.test_permissions',
907
953
'bzrlib.tests.test_plugins',
954
'bzrlib.tests.test_repository',
908
955
'bzrlib.tests.test_revision',
909
956
'bzrlib.tests.test_revisionnamespaces',
910
957
'bzrlib.tests.test_revprops',