129
131
my_format_registry = self.make_format_registry()
130
132
self.assertEqual('Format registered lazily',
131
133
my_format_registry.get_help('lazy'))
132
self.assertEqual('Format using knits',
134
self.assertEqual('Format using knits',
133
135
my_format_registry.get_help('knit'))
134
self.assertEqual('Format using knits',
136
self.assertEqual('Format using knits',
135
137
my_format_registry.get_help('default'))
136
138
self.assertEqual('Pre-0.8 format. Slower and does not support'
137
' checkouts or shared repositories',
139
' checkouts or shared repositories',
138
140
my_format_registry.get_help('weave'))
140
142
def test_help_topic(self):
141
143
topics = help_topics.HelpTopicRegistry()
142
topics.register('formats', self.make_format_registry().help_topic,
144
topic = topics.get_detail('formats')
145
new, rest = topic.split('Experimental formats')
144
registry = self.make_format_registry()
145
topics.register('current-formats', registry.help_topic,
147
topics.register('other-formats', registry.help_topic,
149
new = topics.get_detail('current-formats')
150
rest = topics.get_detail('other-formats')
146
151
experimental, deprecated = rest.split('Deprecated formats')
147
self.assertContainsRe(new, 'These formats can be used')
148
self.assertContainsRe(new,
152
self.assertContainsRe(new, 'bzr help formats')
153
self.assertContainsRe(new,
149
154
':knit:\n \(native\) \(default\) Format using knits\n')
150
self.assertContainsRe(experimental,
155
self.assertContainsRe(experimental,
151
156
':branch6:\n \(native\) Experimental successor to knit')
152
self.assertContainsRe(deprecated,
157
self.assertContainsRe(deprecated,
153
158
':lazy:\n \(native\) Format registered lazily\n')
154
159
self.assertNotContainsRe(new, 'hidden')
319
331
# create standalone working tree always makes a repo.
320
332
format = bzrdir.format_registry.make_bzrdir('knit')
321
333
self.make_repository('.', shared=True, format=format)
322
# note this is deliberately readonly, as this failure should
334
# note this is deliberately readonly, as this failure should
323
335
# occur before any writes.
324
336
self.assertRaises(errors.NotLocalUrl,
325
337
bzrdir.BzrDir.create_standalone_workingtree,
326
338
self.get_readonly_url('child'), format=format)
327
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
339
tree = bzrdir.BzrDir.create_standalone_workingtree('child',
329
341
tree.bzrdir.open_repository()
870
882
def test_needs_conversion_different_working_tree(self):
871
883
# meta1dirs need an conversion if any element is not the default.
872
old_format = bzrdir.BzrDirFormat.get_default_format()
874
new_default = bzrdir.format_registry.make_bzrdir('dirstate')
875
bzrdir.BzrDirFormat._set_default_format(new_default)
877
tree = self.make_branch_and_tree('tree', format='knit')
878
self.assertTrue(tree.bzrdir.needs_format_conversion())
880
bzrdir.BzrDirFormat._set_default_format(old_format)
884
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
885
tree = self.make_branch_and_tree('tree', format='knit')
886
self.assertTrue(tree.bzrdir.needs_format_conversion(
889
def test_initialize_on_format_uses_smart_transport(self):
890
self.setup_smart_server_with_call_log()
891
new_format = bzrdir.format_registry.make_bzrdir('dirstate')
892
transport = self.get_transport('target')
893
transport.ensure_base()
894
self.reset_smart_call_log()
895
instance = new_format.initialize_on_transport(transport)
896
self.assertIsInstance(instance, remote.RemoteBzrDir)
897
rpc_count = len(self.hpss_calls)
898
# This figure represent the amount of work to perform this use case. It
899
# is entirely ok to reduce this number if a test fails due to rpc_count
900
# being too low. If rpc_count increases, more network roundtrips have
901
# become necessary for this use case. Please do not adjust this number
902
# upwards without agreement from bzr's network support maintainers.
903
self.assertEqual(2, rpc_count)
883
906
class TestFormat5(TestCaseWithTransport):
884
907
"""Tests specific to the version 5 bzrdir format."""
886
909
def test_same_lockfiles_between_tree_repo_branch(self):
887
# this checks that only a single lockfiles instance is created
910
# this checks that only a single lockfiles instance is created
888
911
# for format 5 objects
889
912
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
890
913
def check_dir_components_use_same_lock(dir):
897
920
# and if we open it normally.
898
921
dir = bzrdir.BzrDir.open(self.get_url())
899
922
check_dir_components_use_same_lock(dir)
901
924
def test_can_convert(self):
902
925
# format 5 dirs are convertable
903
926
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
904
927
self.assertTrue(dir.can_convert_format())
906
929
def test_needs_conversion(self):
907
# format 5 dirs need a conversion if they are not the default.
908
# and they start of not the default.
909
old_format = bzrdir.BzrDirFormat.get_default_format()
910
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirFormat5())
912
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
913
self.assertFalse(dir.needs_format_conversion())
915
bzrdir.BzrDirFormat._set_default_format(old_format)
916
self.assertTrue(dir.needs_format_conversion())
930
# format 5 dirs need a conversion if they are not the default,
932
dir = bzrdir.BzrDirFormat5().initialize(self.get_url())
933
# don't need to convert it to itself
934
self.assertFalse(dir.needs_format_conversion(bzrdir.BzrDirFormat5()))
935
# do need to convert it to the current default
936
self.assertTrue(dir.needs_format_conversion(
937
bzrdir.BzrDirFormat.get_default_format()))
919
940
class TestFormat6(TestCaseWithTransport):
920
941
"""Tests specific to the version 6 bzrdir format."""
922
943
def test_same_lockfiles_between_tree_repo_branch(self):
923
# this checks that only a single lockfiles instance is created
944
# this checks that only a single lockfiles instance is created
924
945
# for format 6 objects
925
946
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
926
947
def check_dir_components_use_same_lock(dir):
933
954
# and if we open it normally.
934
955
dir = bzrdir.BzrDir.open(self.get_url())
935
956
check_dir_components_use_same_lock(dir)
937
958
def test_can_convert(self):
938
959
# format 6 dirs are convertable
939
960
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
940
961
self.assertTrue(dir.can_convert_format())
942
963
def test_needs_conversion(self):
943
964
# format 6 dirs need an conversion if they are not the default.
944
old_format = bzrdir.BzrDirFormat.get_default_format()
945
bzrdir.BzrDirFormat._set_default_format(bzrdir.BzrDirMetaFormat1())
947
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
948
self.assertTrue(dir.needs_format_conversion())
950
bzrdir.BzrDirFormat._set_default_format(old_format)
965
dir = bzrdir.BzrDirFormat6().initialize(self.get_url())
966
self.assertTrue(dir.needs_format_conversion(
967
bzrdir.BzrDirFormat.get_default_format()))
953
970
class NotBzrDir(bzrlib.bzrdir.BzrDir):
1064
1081
workingtree.WorkingTreeFormat3)
1067
class TestHTTPRedirectionLoop(object):
1068
"""Test redirection loop between two http servers.
1084
class TestHTTPRedirections(object):
1085
"""Test redirection between two http servers.
1070
1087
This MUST be used by daughter classes that also inherit from
1071
1088
TestCaseWithTwoWebservers.
1073
1090
We can't inherit directly from TestCaseWithTwoWebservers or the
1074
1091
test framework will try to create an instance which cannot
1075
run, its implementation being incomplete.
1092
run, its implementation being incomplete.
1078
# Should be defined by daughter classes to ensure redirection
1079
# still use the same transport implementation (not currently
1080
# enforced as it's a bit tricky to get right (see the FIXME
1081
# in BzrDir.open_from_transport for the unique use case so
1085
1095
def create_transport_readonly_server(self):
1086
return HTTPServerRedirecting()
1096
return http_utils.HTTPServerRedirecting()
1088
1098
def create_transport_secondary_server(self):
1089
return HTTPServerRedirecting()
1099
return http_utils.HTTPServerRedirecting()
1091
1101
def setUp(self):
1092
# Both servers redirect to each server creating a loop
1093
super(TestHTTPRedirectionLoop, self).setUp()
1102
super(TestHTTPRedirections, self).setUp()
1094
1103
# The redirections will point to the new server
1095
1104
self.new_server = self.get_readonly_server()
1096
1105
# The requests to the old server will be redirected
1097
1106
self.old_server = self.get_secondary_server()
1098
1107
# Configure the redirections
1099
1108
self.old_server.redirect_to(self.new_server.host, self.new_server.port)
1110
def test_loop(self):
1111
# Both servers redirect to each other creating a loop
1100
1112
self.new_server.redirect_to(self.old_server.host, self.old_server.port)
1102
def _qualified_url(self, host, port):
1103
return 'http+%s://%s:%s' % (self._qualifier, host, port)
1105
def test_loop(self):
1106
1113
# Starting from either server should loop
1107
old_url = self._qualified_url(self.old_server.host,
1114
old_url = self._qualified_url(self.old_server.host,
1108
1115
self.old_server.port)
1109
1116
oldt = self._transport(old_url)
1110
1117
self.assertRaises(errors.NotBranchError,
1111
1118
bzrdir.BzrDir.open_from_transport, oldt)
1112
new_url = self._qualified_url(self.new_server.host,
1119
new_url = self._qualified_url(self.new_server.host,
1113
1120
self.new_server.port)
1114
1121
newt = self._transport(new_url)
1115
1122
self.assertRaises(errors.NotBranchError,
1116
1123
bzrdir.BzrDir.open_from_transport, newt)
1119
class TestHTTPRedirections_urllib(TestHTTPRedirectionLoop,
1120
TestCaseWithTwoWebservers):
1125
def test_qualifier_preserved(self):
1126
wt = self.make_branch_and_tree('branch')
1127
old_url = self._qualified_url(self.old_server.host,
1128
self.old_server.port)
1129
start = self._transport(old_url).clone('branch')
1130
bdir = bzrdir.BzrDir.open_from_transport(start)
1131
# Redirection should preserve the qualifier, hence the transport class
1133
self.assertIsInstance(bdir.root_transport, type(start))
1136
class TestHTTPRedirections_urllib(TestHTTPRedirections,
1137
http_utils.TestCaseWithTwoWebservers):
1121
1138
"""Tests redirections for urllib implementation"""
1123
_qualifier = 'urllib'
1124
1140
_transport = HttpTransport_urllib
1142
def _qualified_url(self, host, port):
1143
return 'http+urllib://%s:%s' % (host, port)
1128
1147
class TestHTTPRedirections_pycurl(TestWithTransport_pycurl,
1129
TestHTTPRedirectionLoop,
1130
TestCaseWithTwoWebservers):
1148
TestHTTPRedirections,
1149
http_utils.TestCaseWithTwoWebservers):
1131
1150
"""Tests redirections for pycurl implementation"""
1133
_qualifier = 'pycurl'
1152
def _qualified_url(self, host, port):
1153
return 'http+pycurl://%s:%s' % (host, port)
1156
class TestHTTPRedirections_nosmart(TestHTTPRedirections,
1157
http_utils.TestCaseWithTwoWebservers):
1158
"""Tests redirections for the nosmart decorator"""
1160
_transport = NoSmartTransportDecorator
1162
def _qualified_url(self, host, port):
1163
return 'nosmart+http://%s:%s' % (host, port)
1166
class TestHTTPRedirections_readonly(TestHTTPRedirections,
1167
http_utils.TestCaseWithTwoWebservers):
1168
"""Tests redirections for readonly decoratror"""
1170
_transport = ReadonlyTransportDecorator
1172
def _qualified_url(self, host, port):
1173
return 'readonly+http://%s:%s' % (host, port)
1136
1176
class TestDotBzrHidden(TestCaseWithTransport):