~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_workingtree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-16 14:01:20 UTC
  • mfrom: (3280.2.5 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080316140120-i3yq8yr1l66m11h7
Start 1.4 development

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
from cStringIO import StringIO
19
19
import os
22
22
    bzrdir,
23
23
    conflicts,
24
24
    errors,
25
 
    transport,
26
25
    workingtree,
27
26
    )
28
27
from bzrlib.branch import Branch
29
28
from bzrlib.bzrdir import BzrDir
30
29
from bzrlib.lockdir import LockDir
31
30
from bzrlib.mutabletree import needs_tree_write_lock
 
31
from bzrlib.symbol_versioning import zero_thirteen
32
32
from bzrlib.tests import TestCase, TestCaseWithTransport, TestSkipped
 
33
from bzrlib.transport import get_transport
33
34
from bzrlib.workingtree import (
34
35
    TreeEntry,
35
36
    TreeDirectory,
81
82
            workingtree.WorkingTreeFormat.set_default_format(old_format)
82
83
        self.assertEqual(old_format, workingtree.WorkingTreeFormat.get_default_format())
83
84
 
84
 
    def test_open(self):
85
 
        tree = self.make_branch_and_tree('.')
86
 
        open_direct = workingtree.WorkingTree.open('.')
87
 
        self.assertEqual(tree.basedir, open_direct.basedir)
88
 
        open_no_args = workingtree.WorkingTree.open()
89
 
        self.assertEqual(tree.basedir, open_no_args.basedir)
90
 
 
91
 
    def test_open_containing(self):
92
 
        tree = self.make_branch_and_tree('.')
93
 
        open_direct, relpath = workingtree.WorkingTree.open_containing('.')
94
 
        self.assertEqual(tree.basedir, open_direct.basedir)
95
 
        self.assertEqual('', relpath)
96
 
        open_no_args, relpath = workingtree.WorkingTree.open_containing()
97
 
        self.assertEqual(tree.basedir, open_no_args.basedir)
98
 
        self.assertEqual('', relpath)
99
 
        open_subdir, relpath = workingtree.WorkingTree.open_containing('subdir')
100
 
        self.assertEqual(tree.basedir, open_subdir.basedir)
101
 
        self.assertEqual('subdir', relpath)
102
 
 
103
85
 
104
86
class SampleTreeFormat(workingtree.WorkingTreeFormat):
105
87
    """A sample format
106
88
 
107
 
    this format is initializable, unsupported to aid in testing the
 
89
    this format is initializable, unsupported to aid in testing the 
108
90
    open and open_downlevel routines.
109
91
    """
110
92
 
138
120
            dir.create_repository()
139
121
            dir.create_branch()
140
122
            format.initialize(dir)
141
 
            t = transport.get_transport(url)
 
123
            t = get_transport(url)
142
124
            found_format = workingtree.WorkingTreeFormat.find_format(dir)
143
125
            self.failUnless(isinstance(found_format, format.__class__))
144
126
        check_format(workingtree.WorkingTreeFormat3(), "bar")
145
 
 
 
127
        
146
128
    def test_find_format_no_tree(self):
147
129
        dir = bzrdir.BzrDirMetaFormat1().initialize('.')
148
130
        self.assertRaises(errors.NoWorkingTree,
193
175
        t = control.get_workingtree_transport(None)
194
176
        self.assertEqualDiff('Bazaar-NG Working Tree format 3',
195
177
                             t.get('format').read())
196
 
        self.assertEqualDiff(t.get('inventory').read(),
 
178
        self.assertEqualDiff(t.get('inventory').read(), 
197
179
                              '<inventory format="5">\n'
198
180
                              '</inventory>\n',
199
181
                             )
202
184
        self.assertFalse(t.has('inventory.basis'))
203
185
        # no last-revision file means 'None' or 'NULLREVISION'
204
186
        self.assertFalse(t.has('last-revision'))
205
 
        # TODO RBC 20060210 do a commit, check the inventory.basis is created
 
187
        # TODO RBC 20060210 do a commit, check the inventory.basis is created 
206
188
        # correctly and last-revision file becomes present.
207
189
 
208
190
    def test_uses_lockdir(self):
209
191
        """WorkingTreeFormat3 uses its own LockDir:
210
 
 
 
192
            
211
193
            - lock is a directory
212
194
            - when the WorkingTree is locked, LockDir can see that
213
195
        """
235
217
        control.create_repository()
236
218
        control.create_branch()
237
219
        tree = workingtree.WorkingTreeFormat3().initialize(control)
238
 
        tree._transport.delete("pending-merges")
 
220
        tree._control_files._transport.delete("pending-merges")
239
221
        self.assertEqual([], tree.get_parent_ids())
240
222
 
241
223
 
269
251
        self.assertEqual(list(tree.conflicts()), [expected])
270
252
 
271
253
 
 
254
class TestNonFormatSpecificCode(TestCaseWithTransport):
 
255
    """This class contains tests of workingtree that are not format specific."""
 
256
 
 
257
    def test_gen_file_id(self):
 
258
        file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_file_id,
 
259
                                      'filename')
 
260
        self.assertStartsWith(file_id, 'filename-')
 
261
 
 
262
    def test_gen_root_id(self):
 
263
        file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_root_id)
 
264
        self.assertStartsWith(file_id, 'tree_root-')
 
265
        
 
266
 
272
267
class InstrumentedTree(object):
273
268
    """A instrumented tree to check the needs_tree_write_lock decorator."""
274
269
 
286
281
    @needs_tree_write_lock
287
282
    def method_that_raises(self):
288
283
        """This method causes an exception when called with parameters.
289
 
 
 
284
        
290
285
        This allows the decorator code to be checked - it should still call
291
286
        unlock.
292
287
        """
303
298
        self.assertEqual(
304
299
            'method_with_tree_write_lock',
305
300
            tree.method_with_tree_write_lock.__name__)
306
 
        self.assertDocstring(
 
301
        self.assertEqual(
307
302
            "A lock_tree_write decorated method that returns its arguments.",
308
 
            tree.method_with_tree_write_lock)
 
303
            tree.method_with_tree_write_lock.__doc__)
309
304
        args = (1, 2, 3)
310
305
        kwargs = {'a':'b'}
311
306
        result = tree.method_with_tree_write_lock(1,2,3, a='b')