/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2338.4.2 by Marien Zwart
Move the workingtree-related inventory tests to a separate file.
1
# Copyright (C) 2007 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
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
17
"""Tests for interface conformance of inventories of working trees."""
18
19
2338.4.2 by Marien Zwart
Move the workingtree-related inventory tests to a separate file.
20
import os
21
import time
22
23
from bzrlib import (
24
    errors,
25
    inventory,
26
    )
2338.4.3 by Marien Zwart
Make the workingtree inventory tests actually use the different workingtree implementations.
27
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
2338.4.2 by Marien Zwart
Move the workingtree-related inventory tests to a separate file.
28
29
2338.4.3 by Marien Zwart
Make the workingtree inventory tests actually use the different workingtree implementations.
30
class TestRevert(TestCaseWithWorkingTree):
2338.4.2 by Marien Zwart
Move the workingtree-related inventory tests to a separate file.
31
32
    def test_dangling_id(self):
33
        wt = self.make_branch_and_tree('b1')
34
        wt.lock_tree_write()
35
        self.addCleanup(wt.unlock)
36
        self.assertEqual(len(wt.inventory), 1)
37
        open('b1/a', 'wb').write('a test\n')
38
        wt.add('a')
39
        self.assertEqual(len(wt.inventory), 2)
40
        wt.flush() # workaround revert doing wt._write_inventory for now.
41
        os.unlink('b1/a')
2748.3.2 by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified'
42
        wt.revert()
2338.4.2 by Marien Zwart
Move the workingtree-related inventory tests to a separate file.
43
        self.assertEqual(len(wt.inventory), 1)
44
45
2376.2.1 by Aaron Bentley
Implement MutableTree.apply_inventory_delta
46
class TestApplyInventoryDelta(TestCaseWithWorkingTree):
47
48
    def test_add(self):
49
        wt = self.make_branch_and_tree('.')
50
        wt.lock_write()
51
        self.addCleanup(wt.unlock)
52
        root_id = wt.get_root_id()
53
        wt.apply_inventory_delta([(None, 'bar/foo', 'foo-id',
54
            inventory.InventoryFile('foo-id', 'foo', parent_id='bar-id')),
55
            (None, 'bar', 'bar-id', inventory.InventoryDirectory('bar-id',
56
            'bar', parent_id=root_id))])
57
        self.assertEqual('bar/foo', wt.inventory.id2path('foo-id'))
58
        self.assertEqual('bar', wt.inventory.id2path('bar-id'))
59
60
    def test_remove(self):
61
        wt = self.make_branch_and_tree('.')
62
        wt.lock_write()
63
        self.addCleanup(wt.unlock)
64
        self.build_tree(['foo/', 'foo/bar'])
65
        wt.add(['foo', 'foo/bar'], ['foo-id', 'bar-id'])
66
        wt.apply_inventory_delta([('foo', None, 'foo-id', None),
67
                                  ('foo/bar', None, 'bar-id', None)])
68
        self.assertIs(None, wt.path2id('foo'))
69
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
70
    def test_rename_dir_with_children(self):
71
        wt = self.make_branch_and_tree('.')
72
        wt.lock_write()
73
        root_id = wt.get_root_id()
74
        self.addCleanup(wt.unlock)
75
        self.build_tree(['foo/', 'foo/bar'])
76
        wt.add(['foo', 'foo/bar'],
77
               ['foo-id', 'bar-id'])
78
        wt.apply_inventory_delta([('foo', 'baz', 'foo-id',
79
            inventory.InventoryDirectory('foo-id', 'baz', root_id))])
80
        # foo/bar should have been followed the rename of its parent to baz/bar
81
        self.assertEqual('baz/bar', wt.id2path('bar-id'))
82
83
    def test_rename_dir_with_children_with_children(self):
84
        wt = self.make_branch_and_tree('.')
85
        wt.lock_write()
86
        root_id = wt.get_root_id()
87
        self.addCleanup(wt.unlock)
88
        self.build_tree(['foo/', 'foo/bar/', 'foo/bar/baz'])
89
        wt.add(['foo', 'foo/bar', 'foo/bar/baz'],
90
               ['foo-id', 'bar-id', 'baz-id'])
91
        wt.apply_inventory_delta([('foo', 'quux', 'foo-id',
92
            inventory.InventoryDirectory('foo-id', 'quux', root_id))])
93
        # foo/bar/baz should have been followed the rename of its parent's
94
        # parent to quux/bar/baz
95
        self.assertEqual('quux/bar/baz', wt.id2path('baz-id'))
96
2376.2.1 by Aaron Bentley
Implement MutableTree.apply_inventory_delta
97
    def test_rename_file(self):
98
        wt = self.make_branch_and_tree('.')
99
        wt.lock_write()
100
        self.addCleanup(wt.unlock)
101
        self.build_tree(['foo/', 'foo/bar', 'baz/'])
102
        wt.add(['foo', 'foo/bar', 'baz'],
103
               ['foo-id', 'bar-id', 'baz-id'])
104
        wt.apply_inventory_delta([('foo/bar', 'baz/bar', 'bar-id',
105
            inventory.InventoryFile('bar-id', 'bar', 'baz-id'))])
106
        self.assertEqual('baz/bar', wt.id2path('bar-id'))
107
108
    def test_rename_swap(self):
109
        """Test the swap-names edge case.
110
111
        foo and bar should swap names, but retain their children.  If this
112
        works, any simpler rename ought to work.
113
        """
114
        wt = self.make_branch_and_tree('.')
115
        wt.lock_write()
116
        root_id = wt.get_root_id()
117
        self.addCleanup(wt.unlock)
118
        self.build_tree(['foo/', 'foo/bar', 'baz/', 'baz/qux'])
119
        wt.add(['foo', 'foo/bar', 'baz', 'baz/qux'],
120
               ['foo-id', 'bar-id', 'baz-id', 'qux-id'])
121
        wt.apply_inventory_delta([('foo', 'baz', 'foo-id',
122
            inventory.InventoryDirectory('foo-id', 'baz', root_id)),
123
            ('baz', 'foo', 'baz-id',
124
            inventory.InventoryDirectory('baz-id', 'foo', root_id))])
125
        self.assertEqual('baz/bar', wt.id2path('bar-id'))
126
        self.assertEqual('foo/qux', wt.id2path('qux-id'))
2376.2.3 by Aaron Bentley
Fix root replacement for apply_inventory_delta
127
2376.2.7 by Aaron Bentley
Add another test case (suggested by John Meinel)
128
    def test_child_rename_ordering(self):
129
        """Test the rename-parent, move child edge case.
130
131
        (A naive implementation may move the parent first, and then be
132
         unable to find the child.)
133
        """
134
        wt = self.make_branch_and_tree('.')
135
        root_id = wt.get_root_id()
136
        self.build_tree(['dir/', 'dir/child', 'other/'])
137
        wt.add(['dir', 'dir/child', 'other'],
138
               ['dir-id', 'child-id', 'other-id'])
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
139
        # this delta moves dir-id to dir2 and reparents 
2865.1.3 by Robert Collins
Review feedback.
140
        # child-id to a parent of other-id
2376.2.7 by Aaron Bentley
Add another test case (suggested by John Meinel)
141
        wt.apply_inventory_delta([('dir', 'dir2', 'dir-id',
142
            inventory.InventoryDirectory('dir-id', 'dir2', root_id)),
143
            ('dir/child', 'other/child', 'child-id',
144
             inventory.InventoryFile('child-id', 'child', 'other-id'))])
145
        self.assertEqual('dir2', wt.id2path('dir-id'))
146
        self.assertEqual('other/child', wt.id2path('child-id'))
147
2376.2.3 by Aaron Bentley
Fix root replacement for apply_inventory_delta
148
    def test_replace_root(self):
149
        wt = self.make_branch_and_tree('.')
150
        wt.lock_write()
151
        self.addCleanup(wt.unlock)
152
153
        root_id = wt.get_root_id()
154
        wt.apply_inventory_delta([('', None, root_id, None),
155
            (None, '', 'root-id',
156
             inventory.InventoryDirectory('root-id', '', None))])