~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

  • Committer: Robert Collins
  • Date: 2010-05-06 07:48:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506074822-0bsgf2j4h8jx0xkk
Added ``bzrlib.tests.matchers`` as a place to put matchers, along with
our first in-tree matcher. See the module docstring for details.
(Robert Collins)

Show diffs side-by-side

added added

removed removed

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