79
79
workingtree.format_registry.set_default(old_format)
80
80
self.assertEqual(old_format, workingtree.format_registry.get_default())
82
def test_from_string(self):
83
self.assertIsInstance(
84
SampleTreeFormat.from_string("Sample tree format."),
86
self.assertRaises(AssertionError,
87
SampleTreeFormat.from_string, "Different format string.")
82
89
def test_get_set_default_format_by_key(self):
83
90
old_format = workingtree.format_registry.get_default()
120
127
self.assertEqual('subdir', relpath)
123
class SampleTreeFormat(workingtree.WorkingTreeFormat):
130
class SampleTreeFormat(workingtree.WorkingTreeFormatMetaDir):
124
131
"""A sample format
126
133
this format is initializable, unsupported to aid in testing the
127
134
open and open_downlevel routines.
130
def get_format_string(self):
138
def get_format_string(cls):
131
139
"""See WorkingTreeFormat.get_format_string()."""
132
140
return "Sample tree format."
172
180
# is the right format object found for a working tree?
173
181
branch = self.make_branch('branch')
174
182
self.assertRaises(errors.NoWorkingTree,
175
workingtree.WorkingTreeFormat.find_format_string, branch.bzrdir)
183
workingtree.WorkingTreeFormatMetaDir.find_format_string, branch.bzrdir)
176
184
transport = branch.bzrdir.get_workingtree_transport(None)
177
185
transport.mkdir('.')
178
186
transport.put_bytes("format", "some format name")
179
187
# The format does not have to be known by Bazaar,
180
188
# find_format_string just retrieves the name
181
189
self.assertEquals("some format name",
182
workingtree.WorkingTreeFormat.find_format_string(branch.bzrdir))
190
workingtree.WorkingTreeFormatMetaDir.find_format_string(branch.bzrdir))
184
192
def test_find_format(self):
185
193
# is the right format object found for a working tree?
191
199
dir.create_branch()
192
200
format.initialize(dir)
193
201
t = transport.get_transport(url)
194
found_format = workingtree.WorkingTreeFormat.find_format(dir)
202
found_format = workingtree.WorkingTreeFormatMetaDir.find_format(dir)
195
203
self.assertIsInstance(found_format, format.__class__)
196
204
check_format(workingtree_3.WorkingTreeFormat3(), "bar")
198
206
def test_find_format_no_tree(self):
199
207
dir = bzrdir.BzrDirMetaFormat1().initialize('.')
200
208
self.assertRaises(errors.NoWorkingTree,
201
workingtree.WorkingTreeFormat.find_format,
209
workingtree.WorkingTreeFormatMetaDir.find_format,
204
212
def test_find_format_unknown_format(self):
207
215
dir.create_branch()
208
216
SampleTreeFormat().initialize(dir)
209
217
self.assertRaises(errors.UnknownFormatError,
210
workingtree.WorkingTreeFormat.find_format,
218
workingtree.WorkingTreeFormatMetaDir.find_format,
213
def test_register_unregister_format(self):
214
format = SampleTreeFormat()
216
dir = bzrdir.BzrDirMetaFormat1().initialize('.')
217
dir.create_repository()
220
format.initialize(dir)
221
# register a format for it.
222
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
223
workingtree.WorkingTreeFormat.register_format, format)
224
self.assertTrue(format in
225
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
226
workingtree.WorkingTreeFormat.get_formats))
227
# which branch.Open will refuse (not supported)
228
self.assertRaises(errors.UnsupportedFormatError, workingtree.WorkingTree.open, '.')
229
# but open_downlevel will work
230
self.assertEqual(format.open(dir), workingtree.WorkingTree.open_downlevel('.'))
231
# unregister the format
232
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
233
workingtree.WorkingTreeFormat.unregister_format, format)
234
self.assertFalse(format in
235
self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
236
workingtree.WorkingTreeFormat.get_formats))
221
def test_find_format_with_features(self):
222
tree = self.make_branch_and_tree('.', format='2a')
223
tree.update_feature_flags({"name": "necessity"})
224
found_format = workingtree.WorkingTreeFormatMetaDir.find_format(
226
self.assertIsInstance(found_format, workingtree.WorkingTreeFormat)
227
self.assertEquals(found_format.features.get("name"), "necessity")
228
self.assertRaises(errors.MissingFeature, found_format.check_support_status,
230
self.addCleanup(workingtree.WorkingTreeFormatMetaDir.unregister_feature,
232
workingtree.WorkingTreeFormatMetaDir.register_feature("name")
233
found_format.check_support_status(True)
239
236
class TestWorkingTreeIterEntriesByDir_wSubtrees(TestCaseWithTransport):
498
495
self.make_branch('qux')
499
496
trees = workingtree.WorkingTree.find_trees('.')
500
497
self.assertEqual(2, len(list(trees)))
500
class TestStoredUncommitted(TestCaseWithTransport):
502
def store_uncommitted(self):
503
tree = self.make_branch_and_tree('tree')
504
tree.commit('get root in there')
505
self.build_tree_contents([('tree/file', 'content')])
506
tree.add('file', 'file-id')
507
tree.store_uncommitted()
510
def test_store_uncommitted(self):
511
self.store_uncommitted()
512
self.assertPathDoesNotExist('tree/file')
514
def test_store_uncommitted_no_change(self):
515
tree = self.make_branch_and_tree('tree')
516
tree.commit('get root in there')
517
tree.store_uncommitted()
518
self.assertIs(None, tree.branch.get_unshelver(tree))
520
def test_restore_uncommitted(self):
521
with write_locked(self.store_uncommitted()) as tree:
522
tree.restore_uncommitted()
523
self.assertPathExists('tree/file')
524
self.assertIs(None, tree.branch.get_unshelver(tree))
526
def test_restore_uncommitted_none(self):
527
tree = self.make_branch_and_tree('tree')
528
tree.restore_uncommitted()