21
21
# little as possible, so this should be used rarely if it's added at all.
22
22
# (Suggestion from j-a-meinel, 2005-11-24)
24
# NOTE: Some classes in here use camelCaseNaming() rather than
25
# underscore_naming(). That's for consistency with unittest; it's not the
26
# general style of bzrlib. Please continue that consistency when adding e.g.
27
# new assertFoo() methods.
25
30
from cStringIO import StringIO
42
47
import bzrlib.errors as errors
43
48
import bzrlib.inventory
44
49
import bzrlib.iterablefile
51
from bzrlib.merge import merge_inner
45
52
import bzrlib.merge3
46
53
import bzrlib.osutils
47
54
import bzrlib.osutils as osutils
48
55
import bzrlib.plugin
49
56
import bzrlib.progress as progress
57
from bzrlib.revision import common_ancestor
50
58
import bzrlib.store
51
59
import bzrlib.trace
52
from bzrlib.transport import urlescape
60
from bzrlib.transport import urlescape, get_transport
53
61
import bzrlib.transport
54
62
from bzrlib.transport.local import LocalRelpathServer
55
63
from bzrlib.transport.readonly import ReadonlyServer
82
91
import bzrlib.tests.blackbox
83
92
import bzrlib.tests.branch_implementations
84
93
import bzrlib.tests.bzrdir_implementations
94
import bzrlib.tests.interrepository_implementations
95
import bzrlib.tests.interversionedfile_implementations
85
96
import bzrlib.tests.repository_implementations
97
import bzrlib.tests.revisionstore_implementations
86
98
import bzrlib.tests.workingtree_implementations
89
101
bzrlib.tests.blackbox,
90
102
bzrlib.tests.branch_implementations,
91
103
bzrlib.tests.bzrdir_implementations,
104
bzrlib.tests.interrepository_implementations,
105
bzrlib.tests.interversionedfile_implementations,
92
106
bzrlib.tests.repository_implementations,
107
bzrlib.tests.revisionstore_implementations,
93
108
bzrlib.tests.workingtree_implementations,
274
289
# This is still a little bogus,
275
290
# but only a little. Folk not using our testrunner will
276
291
# have to delete their temp directories themselves.
292
test_root = TestCaseInTempDir.TEST_ROOT
277
293
if result.wasSuccessful() and not self.keep_output:
278
if TestCaseInTempDir.TEST_ROOT is not None:
279
shutil.rmtree(TestCaseInTempDir.TEST_ROOT)
294
if test_root is not None:
295
print 'Deleting test root %s...' % test_root
297
shutil.rmtree(test_root)
281
301
self.stream.write("Failed tests working directories are in '%s'\n"
282
302
% TestCaseInTempDir.TEST_ROOT)
405
425
def assertTransportMode(self, transport, path, mode):
406
426
"""Fail if a path does not have mode mode.
408
If modes are not supported on this platform, the test is skipped.
428
If modes are not supported on this transport, the assertion is ignored.
410
if sys.platform == 'win32':
430
if not transport._can_roundtrip_unix_modebits():
412
432
path_stat = transport.stat(path)
413
433
actual_mode = stat.S_IMODE(path_stat.st_mode)
414
434
self.assertEqual(mode, actual_mode,
415
435
'mode of %r incorrect (%o != %o)' % (path, mode, actual_mode))
437
def assertIsInstance(self, obj, kls):
438
"""Fail if obj is not an instance of kls"""
439
if not isinstance(obj, kls):
440
self.fail("%r is an instance of %s rather than %s" % (
441
obj, obj.__class__, kls))
417
443
def _startLogFile(self):
418
444
"""Send bzr and test log messages to a temporary file.
622
648
sys.stderr = real_stderr
623
649
sys.stdin = real_stdin
651
def merge(self, branch_from, wt_to):
652
"""A helper for tests to do a ui-less merge.
654
This should move to the main library when someone has time to integrate
657
# minimal ui-less merge.
658
wt_to.branch.fetch(branch_from)
659
base_rev = common_ancestor(branch_from.last_revision(),
660
wt_to.branch.last_revision(),
661
wt_to.branch.repository)
662
merge_inner(wt_to.branch, branch_from.basis_tree(),
663
wt_to.branch.repository.revision_tree(base_rev),
665
wt_to.add_pending_merge(branch_from.last_revision())
626
668
BzrTestBase = TestCase
671
713
# make a fake bzr directory there to prevent any tests propagating
672
714
# up onto the source directory's real branch
673
os.mkdir(osutils.pathjoin(TestCaseInTempDir.TEST_ROOT, '.bzr'))
715
bzrdir.BzrDir.create_standalone_workingtree(TestCaseInTempDir.TEST_ROOT)
676
718
super(TestCaseInTempDir, self).setUp()
677
719
self._make_test_root()
678
720
_currentdir = os.getcwdu()
721
# shorten the name, to avoid test failures due to path length
679
722
short_id = self.id().replace('bzrlib.tests.', '') \
680
.replace('__main__.', '')
681
self.test_dir = osutils.pathjoin(self.TEST_ROOT, short_id)
682
os.mkdir(self.test_dir)
683
os.chdir(self.test_dir)
723
.replace('__main__.', '')[-100:]
724
# it's possible the same test class is run several times for
725
# parameterized tests, so make sure the names don't collide.
729
candidate_dir = '%s/%s.%d' % (self.TEST_ROOT, short_id, i)
731
candidate_dir = '%s/%s' % (self.TEST_ROOT, short_id)
732
if os.path.exists(candidate_dir):
736
self.test_dir = candidate_dir
737
os.mkdir(self.test_dir)
738
os.chdir(self.test_dir)
684
740
os.environ['HOME'] = self.test_dir
685
741
os.environ['APPDATA'] = self.test_dir
686
742
def _leaveDirectory():
818
874
base = base + relpath
821
def make_branch(self, relpath):
877
def get_transport(self):
878
"""Return a writeable transport for the test scratch space"""
879
t = get_transport(self.get_url())
880
self.assertFalse(t.is_readonly())
883
def get_readonly_transport(self):
884
"""Return a readonly transport for the test scratch space
886
This can be used to test that operations which should only need
887
readonly access in fact do not try to write.
889
t = get_transport(self.get_readonly_url())
890
self.assertTrue(t.is_readonly())
893
def make_branch(self, relpath, format=None):
822
894
"""Create a branch on the transport at relpath."""
823
repo = self.make_repository(relpath)
895
repo = self.make_repository(relpath, format=format)
824
896
return repo.bzrdir.create_branch()
826
def make_bzrdir(self, relpath):
898
def make_bzrdir(self, relpath, format=None):
828
900
url = self.get_url(relpath)
829
segments = url.split('/')
901
segments = relpath.split('/')
830
902
if segments and segments[-1] not in ('', '.'):
831
parent = '/'.join(segments[:-1])
832
t = bzrlib.transport.get_transport(parent)
903
parent = self.get_url('/'.join(segments[:-1]))
904
t = get_transport(parent)
834
906
t.mkdir(segments[-1])
835
907
except errors.FileExists:
837
return bzrlib.bzrdir.BzrDir.create(url)
910
format=bzrlib.bzrdir.BzrDirFormat.get_default_format()
911
# FIXME: make this use a single transport someday. RBC 20060418
912
return format.initialize_on_transport(get_transport(relpath))
838
913
except errors.UninitializableFormat:
839
914
raise TestSkipped("Format %s is not initializable.")
841
def make_repository(self, relpath):
916
def make_repository(self, relpath, shared=False, format=None):
842
917
"""Create a repository on our default transport at relpath."""
843
made_control = self.make_bzrdir(relpath)
844
return made_control.create_repository()
918
made_control = self.make_bzrdir(relpath, format=format)
919
return made_control.create_repository(shared=shared)
846
def make_branch_and_tree(self, relpath):
921
def make_branch_and_tree(self, relpath, format=None):
847
922
"""Create a branch on the transport and a tree locally.
849
924
Returns the tree.
852
927
# this obviously requires a format that supports branch references
853
928
# so check for that by checking bzrdir.BzrDirFormat.get_default_format()
855
b = self.make_branch(relpath)
930
b = self.make_branch(relpath, format=format)
857
932
return b.bzrdir.create_workingtree()
858
933
except errors.NotLocalUrl:
862
937
# TODO: rbc 20060208
863
938
return WorkingTreeFormat2().initialize(bzrdir.BzrDir.open(relpath))
940
def assertIsDirectory(self, relpath, transport):
941
"""Assert that relpath within transport is a directory.
943
This may not be possible on all transports; in that case it propagates
944
a TransportNotPossible.
947
mode = transport.stat(relpath).st_mode
948
except errors.NoSuchFile:
949
self.fail("path %s is not a directory; no such file"
951
if not stat.S_ISDIR(mode):
952
self.fail("path %s is not a directory; has mode %#o"
866
956
class ChrootedTestCase(TestCaseWithTransport):
867
957
"""A support class that provides readonly urls outside the local namespace.
942
1032
'bzrlib.tests.test_annotate',
943
1033
'bzrlib.tests.test_api',
944
1034
'bzrlib.tests.test_bad_files',
945
'bzrlib.tests.test_basis_inventory',
946
1035
'bzrlib.tests.test_branch',
947
1036
'bzrlib.tests.test_bzrdir',
948
1037
'bzrlib.tests.test_command',
954
1043
'bzrlib.tests.test_diff',
955
1044
'bzrlib.tests.test_doc_generate',
956
1045
'bzrlib.tests.test_errors',
1046
'bzrlib.tests.test_escaped_store',
957
1047
'bzrlib.tests.test_fetch',
958
1048
'bzrlib.tests.test_gpg',
959
1049
'bzrlib.tests.test_graph',
961
1051
'bzrlib.tests.test_http',
962
1052
'bzrlib.tests.test_identitymap',
963
1053
'bzrlib.tests.test_inv',
1054
'bzrlib.tests.test_knit',
1055
'bzrlib.tests.test_lockdir',
964
1056
'bzrlib.tests.test_lockable_files',
965
1057
'bzrlib.tests.test_log',
966
1058
'bzrlib.tests.test_merge',
971
1063
'bzrlib.tests.test_nonascii',
972
1064
'bzrlib.tests.test_options',
973
1065
'bzrlib.tests.test_osutils',
1066
'bzrlib.tests.test_patch',
974
1067
'bzrlib.tests.test_permissions',
975
1068
'bzrlib.tests.test_plugins',
1069
'bzrlib.tests.test_progress',
1070
'bzrlib.tests.test_reconcile',
976
1071
'bzrlib.tests.test_repository',
977
1072
'bzrlib.tests.test_revision',
978
1073
'bzrlib.tests.test_revisionnamespaces',
979
1074
'bzrlib.tests.test_revprops',
980
'bzrlib.tests.test_reweave',
981
1075
'bzrlib.tests.test_rio',
982
1076
'bzrlib.tests.test_sampler',
983
1077
'bzrlib.tests.test_selftest',
988
1082
'bzrlib.tests.test_store',
989
1083
'bzrlib.tests.test_symbol_versioning',
990
1084
'bzrlib.tests.test_testament',
1085
'bzrlib.tests.test_textfile',
1086
'bzrlib.tests.test_textmerge',
991
1087
'bzrlib.tests.test_trace',
992
1088
'bzrlib.tests.test_transactions',
1089
'bzrlib.tests.test_transform',
993
1090
'bzrlib.tests.test_transport',
994
1091
'bzrlib.tests.test_tsort',
1092
'bzrlib.tests.test_tuned_gzip',
995
1093
'bzrlib.tests.test_ui',
996
'bzrlib.tests.test_uncommit',
997
1094
'bzrlib.tests.test_upgrade',
1095
'bzrlib.tests.test_versionedfile',
998
1096
'bzrlib.tests.test_weave',
999
1097
'bzrlib.tests.test_whitebox',
1000
1098
'bzrlib.tests.test_workingtree',