~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

  • Committer: Jelmer Vernooij
  • Date: 2016-04-03 16:32:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6617.
  • Revision ID: jelmer@jelmer.uk-20160403163231-h72bo0uyek2gikw0
Don't put French text in doc/en/user-reference when LANGUAGE=fr_CH.UTF_8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
2
2
# Authors:  Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
19
19
    bzrdir,
20
20
    conflicts,
21
21
    errors,
22
 
    symbol_versioning,
23
22
    transport,
24
23
    workingtree,
25
24
    workingtree_3,
26
25
    workingtree_4,
27
26
    )
 
27
from bzrlib.lock import write_locked
28
28
from bzrlib.lockdir import LockDir
29
29
from bzrlib.mutabletree import needs_tree_write_lock
30
30
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
79
79
            workingtree.format_registry.set_default(old_format)
80
80
        self.assertEqual(old_format, workingtree.format_registry.get_default())
81
81
 
 
82
    def test_from_string(self):
 
83
        self.assertIsInstance(
 
84
            SampleTreeFormat.from_string("Sample tree format."),
 
85
            SampleTreeFormat)
 
86
        self.assertRaises(AssertionError,
 
87
            SampleTreeFormat.from_string, "Different format string.")
 
88
 
82
89
    def test_get_set_default_format_by_key(self):
83
90
        old_format = workingtree.format_registry.get_default()
84
91
        # default is 6
120
127
        self.assertEqual('subdir', relpath)
121
128
 
122
129
 
123
 
class SampleTreeFormat(workingtree.WorkingTreeFormat):
 
130
class SampleTreeFormat(workingtree.WorkingTreeFormatMetaDir):
124
131
    """A sample format
125
132
 
126
133
    this format is initializable, unsupported to aid in testing the
127
134
    open and open_downlevel routines.
128
135
    """
129
136
 
130
 
    def get_format_string(self):
 
137
    @classmethod
 
138
    def get_format_string(cls):
131
139
        """See WorkingTreeFormat.get_format_string()."""
132
140
        return "Sample tree format."
133
141
 
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
 
        self.assertEquals("some format name",
182
 
            workingtree.WorkingTreeFormat.find_format_string(branch.bzrdir))
 
189
        self.assertEqual("some format name",
 
190
            workingtree.WorkingTreeFormatMetaDir.find_format_string(branch.bzrdir))
183
191
 
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")
197
205
 
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,
202
210
                          dir)
203
211
 
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,
211
219
                          dir)
212
220
 
213
 
    def test_register_unregister_format(self):
214
 
        format = SampleTreeFormat()
215
 
        # make a control dir
216
 
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
217
 
        dir.create_repository()
218
 
        dir.create_branch()
219
 
        # make a branch
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(
 
225
            tree.bzrdir)
 
226
        self.assertIsInstance(found_format, workingtree.WorkingTreeFormat)
 
227
        self.assertEqual(found_format.features.get("name"), "necessity")
 
228
        self.assertRaises(errors.MissingFeature, found_format.check_support_status,
 
229
            True)
 
230
        self.addCleanup(workingtree.WorkingTreeFormatMetaDir.unregister_feature,
 
231
            "name")
 
232
        workingtree.WorkingTreeFormatMetaDir.register_feature("name")
 
233
        found_format.check_support_status(True)
237
234
 
238
235
 
239
236
class TestWorkingTreeIterEntriesByDir_wSubtrees(TestCaseWithTransport):
286
283
    def test_register_unregister_format(self):
287
284
        format = SampleTreeFormat()
288
285
        self.registry.register(format)
289
 
        self.assertEquals(format, self.registry.get("Sample tree format."))
 
286
        self.assertEqual(format, self.registry.get("Sample tree format."))
290
287
        self.registry.remove(format)
291
288
        self.assertRaises(KeyError, self.registry.get, "Sample tree format.")
292
289
 
293
290
    def test_get_all(self):
294
291
        format = SampleTreeFormat()
295
 
        self.assertEquals([], self.registry._get_all())
 
292
        self.assertEqual([], self.registry._get_all())
296
293
        self.registry.register(format)
297
 
        self.assertEquals([format], self.registry._get_all())
 
294
        self.assertEqual([format], self.registry._get_all())
298
295
 
299
296
    def test_register_extra(self):
300
297
        format = SampleExtraTreeFormat()
301
 
        self.assertEquals([], self.registry._get_all())
 
298
        self.assertEqual([], self.registry._get_all())
302
299
        self.registry.register_extra(format)
303
 
        self.assertEquals([format], self.registry._get_all())
 
300
        self.assertEqual([format], self.registry._get_all())
304
301
 
305
302
    def test_register_extra_lazy(self):
306
 
        self.assertEquals([], self.registry._get_all())
 
303
        self.assertEqual([], self.registry._get_all())
307
304
        self.registry.register_extra_lazy("bzrlib.tests.test_workingtree",
308
305
            "SampleExtraTreeFormat")
309
306
        formats = self.registry._get_all()
310
 
        self.assertEquals(1, len(formats))
 
307
        self.assertEqual(1, len(formats))
311
308
        self.assertIsInstance(formats[0], SampleExtraTreeFormat)
312
309
 
313
310
 
359
356
        self.assertIsDirectory('.bzr/checkout', t)
360
357
        self.assertIsDirectory('.bzr/checkout/lock', t)
361
358
        our_lock = LockDir(t, '.bzr/checkout/lock')
362
 
        self.assertEquals(our_lock.peek(), None)
 
359
        self.assertEqual(our_lock.peek(), None)
363
360
        tree.lock_write()
364
361
        self.assertTrue(our_lock.peek())
365
362
        tree.unlock()
366
 
        self.assertEquals(our_lock.peek(), None)
 
363
        self.assertEqual(our_lock.peek(), None)
367
364
 
368
365
    def test_missing_pending_merges(self):
369
366
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
498
495
        self.make_branch('qux')
499
496
        trees = workingtree.WorkingTree.find_trees('.')
500
497
        self.assertEqual(2, len(list(trees)))
 
498
 
 
499
 
 
500
class TestStoredUncommitted(TestCaseWithTransport):
 
501
 
 
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()
 
508
        return tree
 
509
 
 
510
    def test_store_uncommitted(self):
 
511
        self.store_uncommitted()
 
512
        self.assertPathDoesNotExist('tree/file')
 
513
 
 
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))
 
519
 
 
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))
 
525
 
 
526
    def test_restore_uncommitted_none(self):
 
527
        tree = self.make_branch_and_tree('tree')
 
528
        tree.restore_uncommitted()