1
# Copyright (C) 2006-2010 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Tests for WorkingTree.set_root_id"""
21
from bzrlib import errors, inventory
22
from bzrlib.tests import TestSkipped
23
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
26
class TestSetRootId(TestCaseWithWorkingTree):
28
def test_set_and_read_unicode(self):
29
if sys.platform == "win32":
30
raise TestSkipped("don't use oslocks on win32 in unix manner")
31
# This test tests that setting the root doesn't flush, so it
32
# deliberately tests concurrent access that isn't possible on windows.
33
self.thisFailsStrictLockCheck()
34
tree = self.make_branch_and_tree('a-tree')
35
# setting the root id allows it to be read via get_root_id.
36
root_id = u'\xe5n-id'.encode('utf8')
39
old_id = tree.get_root_id()
40
tree.set_root_id(root_id)
41
self.assertEqual(root_id, tree.get_root_id())
42
# set root id should not have triggered a flush of the tree,
43
# so check a new tree sees the old state.
44
reference_tree = tree.bzrdir.open_workingtree()
45
self.assertEqual(old_id, reference_tree.get_root_id())
48
# having unlocked the tree, the value should have been
49
# preserved into the next lock, which is an implicit read
50
# lock around the get_root_id call.
51
self.assertEqual(root_id, tree.get_root_id())
52
# and if we get a new working tree instance, then the value
53
# should still be retained
54
tree = tree.bzrdir.open_workingtree()
55
self.assertEqual(root_id, tree.get_root_id())
58
def test_set_root_id(self):
59
tree = self.make_branch_and_tree('.')
61
self.addCleanup(tree.unlock)
62
orig_root_id = tree.get_root_id()
63
self.assertNotEqual('custom-root-id', orig_root_id)
64
self.assertEqual('', tree.id2path(orig_root_id))
65
self.assertRaises(errors.NoSuchId, tree.id2path, 'custom-root-id')
66
tree.set_root_id('custom-root-id')
67
self.assertEqual('custom-root-id', tree.get_root_id())
68
self.assertEqual('custom-root-id', tree.path2id(''))
69
self.assertEqual('', tree.id2path('custom-root-id'))
70
self.assertRaises(errors.NoSuchId, tree.id2path, orig_root_id)