~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

Merge config-stack into config-concrete-stacks

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    symbol_versioning,
23
23
    transport,
24
24
    workingtree,
 
25
    workingtree_3,
 
26
    workingtree_4,
25
27
    )
26
28
from bzrlib.lockdir import LockDir
27
29
from bzrlib.mutabletree import needs_tree_write_lock
62
64
 
63
65
    def test_get_set_default_format(self):
64
66
        old_format = workingtree.format_registry.get_default()
65
 
        # default is 3
66
 
        self.assertTrue(isinstance(old_format, workingtree.WorkingTreeFormat3))
 
67
        # default is 6
 
68
        self.assertTrue(isinstance(old_format, workingtree_4.WorkingTreeFormat6))
67
69
        workingtree.format_registry.set_default(SampleTreeFormat())
68
70
        try:
69
71
            # the default branch format is used by the meta dir format
77
79
            workingtree.format_registry.set_default(old_format)
78
80
        self.assertEqual(old_format, workingtree.format_registry.get_default())
79
81
 
 
82
    def test_get_set_default_format_by_key(self):
 
83
        old_format = workingtree.format_registry.get_default()
 
84
        # default is 6
 
85
        format = SampleTreeFormat()
 
86
        workingtree.format_registry.register(format)
 
87
        self.addCleanup(workingtree.format_registry.remove, format)
 
88
        self.assertTrue(isinstance(old_format, workingtree_4.WorkingTreeFormat6))
 
89
        workingtree.format_registry.set_default_key(format.get_format_string())
 
90
        try:
 
91
            # the default branch format is used by the meta dir format
 
92
            # which is not the default bzrdir format at this point
 
93
            dir = bzrdir.BzrDirMetaFormat1().initialize('.')
 
94
            dir.create_repository()
 
95
            dir.create_branch()
 
96
            result = dir.create_workingtree()
 
97
            self.assertEqual(result, 'A tree')
 
98
        finally:
 
99
            workingtree.format_registry.set_default_key(
 
100
                old_format.get_format_string())
 
101
        self.assertEqual(old_format, workingtree.format_registry.get_default())
 
102
 
80
103
    def test_open(self):
81
104
        tree = self.make_branch_and_tree('.')
82
105
        open_direct = workingtree.WorkingTree.open('.')
145
168
class TestWorkingTreeFormat(TestCaseWithTransport):
146
169
    """Tests for the WorkingTreeFormat facility."""
147
170
 
 
171
    def test_find_format_string(self):
 
172
        # is the right format object found for a working tree?
 
173
        branch = self.make_branch('branch')
 
174
        self.assertRaises(errors.NoWorkingTree,
 
175
            workingtree.WorkingTreeFormat.find_format_string, branch.bzrdir)
 
176
        transport = branch.bzrdir.get_workingtree_transport(None)
 
177
        transport.mkdir('.')
 
178
        transport.put_bytes("format", "some format name")
 
179
        # The format does not have to be known by Bazaar,
 
180
        # find_format_string just retrieves the name
 
181
        self.assertEquals("some format name",
 
182
            workingtree.WorkingTreeFormat.find_format_string(branch.bzrdir))
 
183
 
148
184
    def test_find_format(self):
149
185
        # is the right format object found for a working tree?
150
186
        # create a branch with a few known format objects.
157
193
            t = transport.get_transport(url)
158
194
            found_format = workingtree.WorkingTreeFormat.find_format(dir)
159
195
            self.assertIsInstance(found_format, format.__class__)
160
 
        check_format(workingtree.WorkingTreeFormat3(), "bar")
 
196
        check_format(workingtree_3.WorkingTreeFormat3(), "bar")
161
197
 
162
198
    def test_find_format_no_tree(self):
163
199
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
241
277
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
242
278
        control.create_repository()
243
279
        control.create_branch()
244
 
        tree = workingtree.WorkingTreeFormat3().initialize(control)
 
280
        tree = workingtree_3.WorkingTreeFormat3().initialize(control)
245
281
        # we want:
246
282
        # format 'Bazaar-NG Working Tree format 3'
247
283
        # inventory = blank inventory
275
311
        repo = dir.create_repository()
276
312
        branch = dir.create_branch()
277
313
        try:
278
 
            tree = workingtree.WorkingTreeFormat3().initialize(dir)
 
314
            tree = workingtree_3.WorkingTreeFormat3().initialize(dir)
279
315
        except errors.NotLocalUrl:
280
316
            raise TestSkipped('Not a local URL')
281
317
        self.assertIsDirectory('.bzr', t)
292
328
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
293
329
        control.create_repository()
294
330
        control.create_branch()
295
 
        tree = workingtree.WorkingTreeFormat3().initialize(control)
 
331
        tree = workingtree_3.WorkingTreeFormat3().initialize(control)
296
332
        tree._transport.delete("pending-merges")
297
333
        self.assertEqual([], tree.get_parent_ids())
298
334