1
# Copyright (C) 2005-2010 Canonical Ltd
1
# Copyright (C) 2005, 2006 Canonical Ltd
2
2
# Authors: Robert Collins <robert.collins@canonical.com>
4
4
# This program is free software; you can redistribute it and/or modify
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
18
18
from cStringIO import StringIO
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 (
81
82
workingtree.WorkingTreeFormat.set_default_format(old_format)
82
83
self.assertEqual(old_format, workingtree.WorkingTreeFormat.get_default_format())
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)
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)
104
86
class SampleTreeFormat(workingtree.WorkingTreeFormat):
105
87
"""A sample format
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.
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")
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',
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.
208
190
def test_uses_lockdir(self):
209
191
"""WorkingTreeFormat3 uses its own LockDir:
211
193
- lock is a directory
212
194
- when the WorkingTree is locked, LockDir can see that
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())
269
251
self.assertEqual(list(tree.conflicts()), [expected])
254
class TestNonFormatSpecificCode(TestCaseWithTransport):
255
"""This class contains tests of workingtree that are not format specific."""
257
def test_gen_file_id(self):
258
file_id = self.applyDeprecated(zero_thirteen, workingtree.gen_file_id,
260
self.assertStartsWith(file_id, 'filename-')
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-')
272
267
class InstrumentedTree(object):
273
268
"""A instrumented tree to check the needs_tree_write_lock decorator."""
303
298
self.assertEqual(
304
299
'method_with_tree_write_lock',
305
300
tree.method_with_tree_write_lock.__name__)
306
self.assertDocstring(
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__)
310
305
kwargs = {'a':'b'}
311
306
result = tree.method_with_tree_write_lock(1,2,3, a='b')