/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
21
from breezy import errors
22
from breezy.tests import TestSkipped
23
from breezy.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')
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
35
        if not tree.supports_setting_file_ids():
36
            self.skipTest('format does not support setting file ids')
1986.5.2 by Robert Collins
``WorkingTree.set_root_id(None)`` is now deprecated. Please
37
        # 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
38
        root_id = u'\xe5n-id'.encode('utf8')
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
39
        with tree.lock_write():
40
            old_id = tree.path2id('')
2294.1.10 by John Arbash Meinel
Switch all apis over to utf8 file ids. All tests pass
41
            tree.set_root_id(root_id)
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
42
            self.assertEqual(root_id, tree.path2id(''))
1986.5.3 by Robert Collins
New method ``WorkingTree.flush()`` which will write the current memory
43
            # set root id should not have triggered a flush of the tree,
44
            # so check a new tree sees the old state.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
45
            reference_tree = tree.controldir.open_workingtree()
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
46
            self.assertEqual(old_id, reference_tree.path2id(''))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
47
        # having unlocked the tree, the value should have been
1986.5.2 by Robert Collins
``WorkingTree.set_root_id(None)`` is now deprecated. Please
48
        # preserved into the next lock, which is an implicit read
49
        # lock around the get_root_id call.
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
50
        self.assertEqual(root_id, tree.path2id(''))
1986.5.2 by Robert Collins
``WorkingTree.set_root_id(None)`` is now deprecated. Please
51
        # and if we get a new working tree instance, then the value
52
        # should still be retained
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
53
        tree = tree.controldir.open_workingtree()
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
54
        self.assertEqual(root_id, tree.path2id(''))
4634.123.13 by John Arbash Meinel
_validate() the tree after running the root id tests.
55
        tree._validate()
4634.123.8 by John Arbash Meinel
Add a direct test for set_root_id behavior, which seems correct.
56
57
    def test_set_root_id(self):
58
        tree = self.make_branch_and_tree('.')
6829.2.1 by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places.
59
        if not tree.supports_setting_file_ids():
60
            self.skipTest('format does not support setting file ids')
4634.123.8 by John Arbash Meinel
Add a direct test for set_root_id behavior, which seems correct.
61
        tree.lock_write()
62
        self.addCleanup(tree.unlock)
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
63
        orig_root_id = tree.path2id('')
6855.4.1 by Jelmer Vernooij
Yet more bees.
64
        self.assertNotEqual(b'custom-root-id', orig_root_id)
4634.123.8 by John Arbash Meinel
Add a direct test for set_root_id behavior, which seems correct.
65
        self.assertEqual('', tree.id2path(orig_root_id))
66
        self.assertRaises(errors.NoSuchId, tree.id2path, 'custom-root-id')
6855.4.1 by Jelmer Vernooij
Yet more bees.
67
        tree.set_root_id(b'custom-root-id')
7358.14.1 by Jelmer Vernooij
Remove Tree.get_root_id() in favour of Tree.path2id('').
68
        self.assertEqual(b'custom-root-id', tree.path2id(''))
6855.4.1 by Jelmer Vernooij
Yet more bees.
69
        self.assertEqual(b'custom-root-id', tree.path2id(''))
70
        self.assertEqual('', tree.id2path(b'custom-root-id'))
4634.123.8 by John Arbash Meinel
Add a direct test for set_root_id behavior, which seems correct.
71
        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.
72
        tree._validate()