~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_set_root_id.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 Canonical Ltd
 
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Tests for WorkingTree.set_root_id"""
 
18
 
 
19
from bzrlib import inventory
 
20
from bzrlib.symbol_versioning import zero_twelve
 
21
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
 
22
 
 
23
 
 
24
class TestSetRootId(TestCaseWithWorkingTree):
 
25
 
 
26
    def test_set_None(self):
 
27
        # setting the root_id to None is equivalent to setting it
 
28
        # to inventory.ROOT_ID
 
29
        tree = self.make_branch_and_tree('a-tree')
 
30
        self.callDeprecated([
 
31
            'WorkingTree.set_root_id with fileid=None was deprecated in version'
 
32
            ' 0.12.'],
 
33
            tree.set_root_id, None)
 
34
        self.assertEqual(inventory.ROOT_ID, tree.get_root_id())
 
35
 
 
36
    def test_set_and_read_unicode(self):
 
37
        tree = self.make_branch_and_tree('a-tree')
 
38
        # setting the root id allows it to be read via get_root_id.
 
39
        root_id = u'\xe5n-id'.encode('utf8')
 
40
        tree.lock_write()
 
41
        try:
 
42
            old_id = tree.get_root_id()
 
43
            tree.set_root_id(root_id)
 
44
            self.assertEqual(root_id, tree.get_root_id())
 
45
            # set root id should not have triggered a flush of the tree,
 
46
            # so check a new tree sees the old state.
 
47
            reference_tree = tree.bzrdir.open_workingtree()
 
48
            self.assertEqual(old_id, reference_tree.get_root_id())
 
49
        finally:
 
50
            tree.unlock()
 
51
        # having unlocked the tree, the value should have been 
 
52
        # preserved into the next lock, which is an implicit read
 
53
        # lock around the get_root_id call.
 
54
        self.assertEqual(root_id, tree.get_root_id())
 
55
        # and if we get a new working tree instance, then the value
 
56
        # should still be retained
 
57
        tree = tree.bzrdir.open_workingtree()
 
58
        self.assertEqual(root_id, tree.get_root_id())