/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

  • Committer: Jelmer Vernooij
  • Date: 2011-02-08 15:41:44 UTC
  • mfrom: (5651.4.1 repo-format-registry)
  • mto: This revision was merged to the branch mainline in revision 5658.
  • Revision ID: jelmer@samba.org-20110208154144-h8mm2hrk87de4w2s
Merge repo format registry branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
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
 
from cStringIO import StringIO
19
18
import os
20
19
 
21
20
from bzrlib import (
22
21
    bzrdir,
23
22
    conflicts,
24
23
    errors,
 
24
    transport,
25
25
    workingtree,
26
26
    )
27
 
from bzrlib.branch import Branch
28
 
from bzrlib.bzrdir import BzrDir
29
27
from bzrlib.lockdir import LockDir
30
28
from bzrlib.mutabletree import needs_tree_write_lock
31
29
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
32
 
from bzrlib.transport import get_transport
33
30
from bzrlib.workingtree import (
34
31
    TreeEntry,
35
32
    TreeDirectory,
126
123
        return "opened tree."
127
124
 
128
125
 
 
126
class SampleExtraTreeFormat(workingtree.WorkingTreeFormat):
 
127
    """A sample format that does not support use in a metadir.
 
128
 
 
129
    """
 
130
 
 
131
    def get_format_string(self):
 
132
        # Not usable in a metadir, so no format string
 
133
        return None
 
134
 
 
135
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
 
136
                   accelerator_tree=None, hardlink=False):
 
137
        raise NotImplementedError(self.initialize)
 
138
 
 
139
    def is_supported(self):
 
140
        return False
 
141
 
 
142
    def open(self, transport, _found=False):
 
143
        raise NotImplementedError(self.open)
 
144
 
 
145
 
129
146
class TestWorkingTreeFormat(TestCaseWithTransport):
130
147
    """Tests for the WorkingTreeFormat facility."""
131
148
 
138
155
            dir.create_repository()
139
156
            dir.create_branch()
140
157
            format.initialize(dir)
141
 
            t = get_transport(url)
 
158
            t = transport.get_transport(url)
142
159
            found_format = workingtree.WorkingTreeFormat.find_format(dir)
143
160
            self.failUnless(isinstance(found_format, format.__class__))
144
161
        check_format(workingtree.WorkingTreeFormat3(), "bar")
168
185
        format.initialize(dir)
169
186
        # register a format for it.
170
187
        workingtree.WorkingTreeFormat.register_format(format)
 
188
        self.assertTrue(format in workingtree.WorkingTreeFormat.get_formats())
171
189
        # which branch.Open will refuse (not supported)
172
190
        self.assertRaises(errors.UnsupportedFormatError, workingtree.WorkingTree.open, '.')
173
191
        # but open_downlevel will work
174
192
        self.assertEqual(format.open(dir), workingtree.WorkingTree.open_downlevel('.'))
175
193
        # unregister the format
176
194
        workingtree.WorkingTreeFormat.unregister_format(format)
 
195
        self.assertFalse(format in workingtree.WorkingTreeFormat.get_formats())
 
196
 
 
197
    def test_register_unregister_extra_format(self):
 
198
        format = SampleExtraTreeFormat()
 
199
        workingtree.WorkingTreeFormat.register_extra_format(format)
 
200
        self.assertTrue(format in workingtree.WorkingTreeFormat.get_formats())
 
201
        workingtree.WorkingTreeFormat.unregister_extra_format(format)
 
202
        self.assertFalse(format in workingtree.WorkingTreeFormat.get_formats())
177
203
 
178
204
 
179
205
class TestWorkingTreeFormat3(TestCaseWithTransport):
349
375
        self.build_tree_contents([('this/hello', 'Hello World')])
350
376
        this.commit('Add World')
351
377
        this.merge_from_branch(other.branch)
352
 
        self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
 
378
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
353
379
                         this.conflicts())
354
380
        this.auto_resolve()
355
 
        self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
 
381
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
356
382
                         this.conflicts())
357
383
        self.build_tree_contents([('this/hello', '<<<<<<<')])
358
384
        this.auto_resolve()
359
 
        self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
 
385
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
360
386
                         this.conflicts())
361
387
        self.build_tree_contents([('this/hello', '=======')])
362
388
        this.auto_resolve()
363
 
        self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
 
389
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
364
390
                         this.conflicts())
365
391
        self.build_tree_contents([('this/hello', '\n>>>>>>>')])
366
392
        remaining, resolved = this.auto_resolve()
367
 
        self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
 
393
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
368
394
                         this.conflicts())
369
395
        self.assertEqual([], resolved)
370
396
        self.build_tree_contents([('this/hello', 'hELLO wORLD')])
371
397
        remaining, resolved = this.auto_resolve()
372
398
        self.assertEqual([], this.conflicts())
373
 
        self.assertEqual([conflicts.TextConflict('hello', None, 'hello_id')],
 
399
        self.assertEqual([conflicts.TextConflict('hello', 'hello_id')],
374
400
                         resolved)
375
401
        self.failIfExists('this/hello.BASE')
376
402
 
378
404
        tree = self.make_branch_and_tree('tree')
379
405
        self.build_tree(['tree/hello/'])
380
406
        tree.add('hello', 'hello-id')
381
 
        file_conflict = conflicts.TextConflict('file', None, 'hello-id')
 
407
        file_conflict = conflicts.TextConflict('file', 'hello-id')
382
408
        tree.set_conflicts(conflicts.ConflictList([file_conflict]))
383
409
        tree.auto_resolve()
384
410