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
45
import bzrlib.lockdir
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
84
83
import bzrlib.tests.blackbox
85
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,
88
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,
261
269
charjunk=lambda x: False)
262
270
return ''.join(difflines)
264
def assertEqualDiff(self, a, b):
272
def assertEqualDiff(self, a, b, message=None):
265
273
"""Assert two texts are equal, if not raise an exception.
267
275
This is intended for use with multi-line strings where it can
270
278
# TODO: perhaps override assertEquals to call this for strings?
273
raise AssertionError("texts not equal:\n" +
282
message = "texts not equal:\n"
283
raise AssertionError(message +
274
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))
276
290
def assertStartsWith(self, s, prefix):
277
291
if not s.startswith(prefix):
278
292
raise AssertionError('string %r does not start with %r' % (s, prefix))
570
584
# make a fake bzr directory there to prevent any tests propagating
571
585
# up onto the source directory's real branch
572
os.mkdir(osutils.pathjoin(TestCaseInTempDir.TEST_ROOT, '.bzr'))
586
bzrdir.BzrDir.create_standalone_workingtree(TestCaseInTempDir.TEST_ROOT)
575
589
super(TestCaseInTempDir, self).setUp()
615
629
elif line_endings == 'native':
618
raise BzrError('Invalid line ending request %r' % (line_endings,))
632
raise errors.BzrError('Invalid line ending request %r' % (line_endings,))
619
633
content = "contents of %s%s" % (name, end)
620
634
transport.put(urlescape(name), StringIO(content))
665
679
relpath provides for clients to get a path relative to the base url.
666
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.
668
694
if self.__readonly_server is None:
669
695
if self.transport_readonly_server is None:
670
696
# readonly decorator requested
676
702
self.__readonly_server = self.transport_readonly_server()
677
703
self.__readonly_server.setUp()
678
704
self.addCleanup(self.__readonly_server.tearDown)
679
base = self.__readonly_server.get_url()
680
if relpath is not None:
681
if not base.endswith('/'):
683
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)
686
719
def get_url(self, relpath=None):
687
720
"""Get a URL for the readwrite transport.
691
724
relpath provides for clients to get a path relative to the base url.
692
725
These should only be downwards relative, not upwards.
694
if self.__server is None:
695
self.__server = self.transport_server()
696
self.__server.setUp()
697
self.addCleanup(self.__server.tearDown)
698
base = self.__server.get_url()
727
base = self.get_server().get_url()
699
728
if relpath is not None and relpath != '.':
700
729
if not base.endswith('/'):
701
730
base = base + '/'
721
750
def make_branch(self, relpath):
722
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):
724
757
url = self.get_url(relpath)
725
758
segments = relpath.split('/')
728
761
t = get_transport(parent)
730
763
t.mkdir(segments[-1])
764
except errors.FileExists:
733
return bzrlib.branch.Branch.create(url)
734
except UninitializableFormat:
766
return bzrlib.bzrdir.BzrDir.create(url)
767
except errors.UninitializableFormat:
735
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)
737
775
def make_branch_and_tree(self, relpath):
738
776
"""Create a branch on the transport and a tree locally.
740
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()
742
784
b = self.make_branch(relpath)
743
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))
746
795
class ChrootedTestCase(TestCaseWithTransport):
828
877
'bzrlib.tests.test_bad_files',
829
878
'bzrlib.tests.test_basis_inventory',
830
879
'bzrlib.tests.test_branch',
880
'bzrlib.tests.test_bzrdir',
831
881
'bzrlib.tests.test_command',
832
882
'bzrlib.tests.test_commit',
833
883
'bzrlib.tests.test_commit_merge',
836
886
'bzrlib.tests.test_decorators',
837
887
'bzrlib.tests.test_diff',
838
888
'bzrlib.tests.test_doc_generate',
889
'bzrlib.tests.test_errors',
839
890
'bzrlib.tests.test_fetch',
840
'bzrlib.tests.test_fileid_involved',
841
891
'bzrlib.tests.test_gpg',
842
892
'bzrlib.tests.test_graph',
843
893
'bzrlib.tests.test_hashcache',
855
905
'bzrlib.tests.test_nonascii',
856
906
'bzrlib.tests.test_options',
857
907
'bzrlib.tests.test_osutils',
858
'bzrlib.tests.test_parent',
859
908
'bzrlib.tests.test_permissions',
860
909
'bzrlib.tests.test_plugins',
910
'bzrlib.tests.test_repository',
861
911
'bzrlib.tests.test_revision',
862
912
'bzrlib.tests.test_revisionnamespaces',
863
913
'bzrlib.tests.test_revprops',
874
924
'bzrlib.tests.test_testament',
875
925
'bzrlib.tests.test_trace',
876
926
'bzrlib.tests.test_transactions',
927
'bzrlib.tests.test_transform',
877
928
'bzrlib.tests.test_transport',
878
929
'bzrlib.tests.test_tsort',
879
930
'bzrlib.tests.test_ui',