~bzr-pqm/bzr/bzr.dev

4634.123.8 by John Arbash Meinel
Add a direct test for set_root_id behavior, which seems correct.
1
# Copyright (C) 2006-2010 Canonical Ltd
1986.5.2 by Robert Collins
``WorkingTree.set_root_id(None)`` is now deprecated. Please
2
#
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.
7
#
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.
12
#
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1986.5.2 by Robert Collins
``WorkingTree.set_root_id(None)`` is now deprecated. Please
16
17
"""Tests for WorkingTree.set_root_id"""
18
4648.1.3 by Robert Collins
Improve behaviour of tests that have a reasonable excuse for causing locking issues on windows selftest.
19
import sys
20
5807.2.1 by Jelmer Vernooij
Remove unused imports.
21
from bzrlib import errors
4648.1.3 by Robert Collins
Improve behaviour of tests that have a reasonable excuse for causing locking issues on windows selftest.
22
from bzrlib.tests import TestSkipped
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
23
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
1986.5.2 by Robert Collins
``WorkingTree.set_root_id(None)`` is now deprecated. Please
24
25
26
class TestSetRootId(TestCaseWithWorkingTree):
27
28
    def test_set_and_read_unicode(self):
4648.1.3 by Robert Collins
Improve behaviour of tests that have a reasonable excuse for causing locking issues on windows selftest.
29
        if sys.platform == "win32":
30
            raise TestSkipped("don't use oslocks on win32 in unix manner")
4595.13.1 by Alexander Belchenko
[cherrypick revno.4635 from bzr.dev] (robertc) Fix many locking errors on windows due to a small bug in merge.transform_tree. (Robert Collins)
31
        # This test tests that setting the root doesn't flush, so it
32
        # deliberately tests concurrent access that isn't possible on windows.
4627.2.4 by Robert Collins
Put back a test that needs unix relaxed behaviour.
33
        self.thisFailsStrictLockCheck()
1986.5.2 by Robert Collins
``WorkingTree.set_root_id(None)`` is now deprecated. Please
34
        tree = self.make_branch_and_tree('a-tree')
35
        # setting the root id allows it to be read via get_root_id.
2294.1.10 by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass
36
        root_id = u'\xe5n-id'.encode('utf8')
1986.5.2 by Robert Collins
``WorkingTree.set_root_id(None)`` is now deprecated. Please
37
        tree.lock_write()
38
        try:
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
39
            old_id = tree.get_root_id()
2294.1.10 by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass
40
            tree.set_root_id(root_id)
41
            self.assertEqual(root_id, tree.get_root_id())
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
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())
1986.5.2 by Robert Collins
``WorkingTree.set_root_id(None)`` is now deprecated. Please
46
        finally:
47
            tree.unlock()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
48
        # having unlocked the tree, the value should have been
1986.5.2 by Robert Collins
``WorkingTree.set_root_id(None)`` is now deprecated. Please
49
        # preserved into the next lock, which is an implicit read
50
        # lock around the get_root_id call.
2294.1.10 by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass
51
        self.assertEqual(root_id, tree.get_root_id())
1986.5.2 by Robert Collins
``WorkingTree.set_root_id(None)`` is now deprecated. Please
52
        # and if we get a new working tree instance, then the value
53
        # should still be retained
54
        tree = tree.bzrdir.open_workingtree()
2294.1.10 by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass
55
        self.assertEqual(root_id, tree.get_root_id())
4634.123.13 by John Arbash Meinel
_validate() the tree after running the root id tests.
56
        tree._validate()
4634.123.8 by John Arbash Meinel
Add a direct test for set_root_id behavior, which seems correct.
57
58
    def test_set_root_id(self):
59
        tree = self.make_branch_and_tree('.')
60
        tree.lock_write()
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)
4634.123.13 by John Arbash Meinel
_validate() the tree after running the root id tests.
71
        tree._validate()