~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

(gz) Fix test failure on alpha by correcting format string for
 gc_chk_sha1_record (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
 
 
18
import os
 
19
 
18
20
from bzrlib import (
19
21
    bzrdir,
20
22
    conflicts,
22
24
    symbol_versioning,
23
25
    transport,
24
26
    workingtree,
25
 
    workingtree_3,
26
 
    workingtree_4,
27
27
    )
28
28
from bzrlib.lockdir import LockDir
29
29
from bzrlib.mutabletree import needs_tree_write_lock
64
64
 
65
65
    def test_get_set_default_format(self):
66
66
        old_format = workingtree.format_registry.get_default()
67
 
        # default is 6
68
 
        self.assertTrue(isinstance(old_format, workingtree_4.WorkingTreeFormat6))
 
67
        # default is 3
 
68
        self.assertTrue(isinstance(old_format, workingtree.WorkingTreeFormat3))
69
69
        workingtree.format_registry.set_default(SampleTreeFormat())
70
70
        try:
71
71
            # the default branch format is used by the meta dir format
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_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
 
 
103
82
    def test_open(self):
104
83
        tree = self.make_branch_and_tree('.')
105
84
        open_direct = workingtree.WorkingTree.open('.')
168
147
class TestWorkingTreeFormat(TestCaseWithTransport):
169
148
    """Tests for the WorkingTreeFormat facility."""
170
149
 
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
 
 
184
150
    def test_find_format(self):
185
151
        # is the right format object found for a working tree?
186
152
        # create a branch with a few known format objects.
192
158
            format.initialize(dir)
193
159
            t = transport.get_transport(url)
194
160
            found_format = workingtree.WorkingTreeFormat.find_format(dir)
195
 
            self.assertIsInstance(found_format, format.__class__)
196
 
        check_format(workingtree_3.WorkingTreeFormat3(), "bar")
 
161
            self.failUnless(isinstance(found_format, format.__class__))
 
162
        check_format(workingtree.WorkingTreeFormat3(), "bar")
197
163
 
198
164
    def test_find_format_no_tree(self):
199
165
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
236
202
                workingtree.WorkingTreeFormat.get_formats))
237
203
 
238
204
 
239
 
class TestWorkingTreeIterEntriesByDir_wSubtrees(TestCaseWithTransport):
240
 
 
241
 
    def make_simple_tree(self):
242
 
        tree = self.make_branch_and_tree('tree', format='development-subtree')
243
 
        self.build_tree(['tree/a/', 'tree/a/b/', 'tree/a/b/c'])
244
 
        tree.set_root_id('root-id')
245
 
        tree.add(['a', 'a/b', 'a/b/c'], ['a-id', 'b-id', 'c-id'])
246
 
        tree.commit('initial')
247
 
        return tree
248
 
 
249
 
    def test_just_directory(self):
250
 
        tree = self.make_simple_tree()
251
 
        self.assertEqual([('directory', 'root-id'),
252
 
                          ('directory', 'a-id'),
253
 
                          ('directory', 'b-id'),
254
 
                          ('file', 'c-id')],
255
 
                         [(ie.kind, ie.file_id)
256
 
                          for path, ie in tree.iter_entries_by_dir()])
257
 
        subtree = self.make_branch_and_tree('tree/a/b')
258
 
        self.assertEqual([('tree-reference', 'b-id')],
259
 
                         [(ie.kind, ie.file_id)
260
 
                          for path, ie in tree.iter_entries_by_dir(['b-id'])])
261
 
 
262
 
    def test_direct_subtree(self):
263
 
        tree = self.make_simple_tree()
264
 
        subtree = self.make_branch_and_tree('tree/a/b')
265
 
        self.assertEqual([('directory', 'root-id'),
266
 
                          ('directory', 'a-id'),
267
 
                          ('tree-reference', 'b-id')],
268
 
                         [(ie.kind, ie.file_id)
269
 
                          for path, ie in tree.iter_entries_by_dir()])
270
 
 
271
 
    def test_indirect_subtree(self):
272
 
        tree = self.make_simple_tree()
273
 
        subtree = self.make_branch_and_tree('tree/a')
274
 
        self.assertEqual([('directory', 'root-id'),
275
 
                          ('tree-reference', 'a-id')],
276
 
                         [(ie.kind, ie.file_id)
277
 
                          for path, ie in tree.iter_entries_by_dir()])
278
 
 
279
 
 
280
205
class TestWorkingTreeFormatRegistry(TestCase):
281
206
 
282
207
    def setUp(self):
318
243
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
319
244
        control.create_repository()
320
245
        control.create_branch()
321
 
        tree = workingtree_3.WorkingTreeFormat3().initialize(control)
 
246
        tree = workingtree.WorkingTreeFormat3().initialize(control)
322
247
        # we want:
323
248
        # format 'Bazaar-NG Working Tree format 3'
324
249
        # inventory = blank inventory
352
277
        repo = dir.create_repository()
353
278
        branch = dir.create_branch()
354
279
        try:
355
 
            tree = workingtree_3.WorkingTreeFormat3().initialize(dir)
 
280
            tree = workingtree.WorkingTreeFormat3().initialize(dir)
356
281
        except errors.NotLocalUrl:
357
282
            raise TestSkipped('Not a local URL')
358
283
        self.assertIsDirectory('.bzr', t)
369
294
        control = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
370
295
        control.create_repository()
371
296
        control.create_branch()
372
 
        tree = workingtree_3.WorkingTreeFormat3().initialize(control)
 
297
        tree = workingtree.WorkingTreeFormat3().initialize(control)
373
298
        tree._transport.delete("pending-merges")
374
299
        self.assertEqual([], tree.get_parent_ids())
375
300
 
376
301
 
 
302
class TestFormat2WorkingTree(TestCaseWithTransport):
 
303
    """Tests that are specific to format 2 trees."""
 
304
 
 
305
    def create_format2_tree(self, url):
 
306
        return self.make_branch_and_tree(
 
307
            url, format=bzrdir.BzrDirFormat6())
 
308
 
 
309
    def test_conflicts(self):
 
310
        # test backwards compatability
 
311
        tree = self.create_format2_tree('.')
 
312
        self.assertRaises(errors.UnsupportedOperation, tree.set_conflicts,
 
313
                          None)
 
314
        file('lala.BASE', 'wb').write('labase')
 
315
        expected = conflicts.ContentsConflict('lala')
 
316
        self.assertEqual(list(tree.conflicts()), [expected])
 
317
        file('lala', 'wb').write('la')
 
318
        tree.add('lala', 'lala-id')
 
319
        expected = conflicts.ContentsConflict('lala', file_id='lala-id')
 
320
        self.assertEqual(list(tree.conflicts()), [expected])
 
321
        file('lala.THIS', 'wb').write('lathis')
 
322
        file('lala.OTHER', 'wb').write('laother')
 
323
        # When "text conflict"s happen, stem, THIS and OTHER are text
 
324
        expected = conflicts.TextConflict('lala', file_id='lala-id')
 
325
        self.assertEqual(list(tree.conflicts()), [expected])
 
326
        os.unlink('lala.OTHER')
 
327
        os.mkdir('lala.OTHER')
 
328
        expected = conflicts.ContentsConflict('lala', file_id='lala-id')
 
329
        self.assertEqual(list(tree.conflicts()), [expected])
 
330
 
 
331
 
377
332
class InstrumentedTree(object):
378
333
    """A instrumented tree to check the needs_tree_write_lock decorator."""
379
334
 
450
405
        self.build_tree_contents([('other/hello', 'hELLO')])
451
406
        other.commit('Case switch')
452
407
        this = base.bzrdir.sprout('this').open_workingtree()
453
 
        self.assertPathExists('this/hello')
 
408
        self.failUnlessExists('this/hello')
454
409
        self.build_tree_contents([('this/hello', 'Hello World')])
455
410
        this.commit('Add World')
456
411
        this.merge_from_branch(other.branch)
477
432
        self.assertEqual([], this.conflicts())
478
433
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
479
434
                         resolved)
480
 
        self.assertPathDoesNotExist('this/hello.BASE')
 
435
        self.failIfExists('this/hello.BASE')
481
436
 
482
437
    def test_auto_resolve_dir(self):
483
438
        tree = self.make_branch_and_tree('tree')