/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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2338.4.2 by Marien Zwart
Move the workingtree-related inventory tests to a separate file.
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
6670.4.3 by Jelmer Vernooij
Fix more imports.
22
from breezy import tests
23
from breezy.bzr import inventory
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
24
from breezy.tests.per_workingtree import TestCaseWithWorkingTree
2338.4.2 by Marien Zwart
Move the workingtree-related inventory tests to a separate file.
25
26
2338.4.3 by Marien Zwart
Make the workingtree inventory tests actually use the different workingtree implementations.
27
class TestRevert(TestCaseWithWorkingTree):
2338.4.2 by Marien Zwart
Move the workingtree-related inventory tests to a separate file.
28
29
    def test_dangling_id(self):
30
        wt = self.make_branch_and_tree('b1')
31
        wt.lock_tree_write()
32
        self.addCleanup(wt.unlock)
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
33
        self.assertEqual(len(list(wt.all_versioned_paths())), 1)
6973.7.5 by Jelmer Vernooij
s/file/open.
34
        with open('b1/a', 'wb') as f: f.write(b'a test\n')
2338.4.2 by Marien Zwart
Move the workingtree-related inventory tests to a separate file.
35
        wt.add('a')
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
36
        self.assertEqual(len(list(wt.all_versioned_paths())), 2)
2338.4.2 by Marien Zwart
Move the workingtree-related inventory tests to a separate file.
37
        wt.flush() # workaround revert doing wt._write_inventory for now.
38
        os.unlink('b1/a')
2748.3.2 by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified'
39
        wt.revert()
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
40
        self.assertEqual(len(list(wt.all_versioned_paths())), 1)
2338.4.2 by Marien Zwart
Move the workingtree-related inventory tests to a separate file.
41
42
2376.2.1 by Aaron Bentley
Implement MutableTree.apply_inventory_delta
43
class TestApplyInventoryDelta(TestCaseWithWorkingTree):
44
5858.3.3 by Jelmer Vernooij
Skip tests early, before creating a tree.
45
    def setUp(self):
46
        super(TestApplyInventoryDelta, self).setUp()
47
        if not self.bzrdir_format.repository_format.supports_full_versioned_files:
48
            raise tests.TestNotApplicable(
49
                "format does not support inventory deltas")
50
2376.2.1 by Aaron Bentley
Implement MutableTree.apply_inventory_delta
51
    def test_add(self):
52
        wt = self.make_branch_and_tree('.')
53
        wt.lock_write()
54
        self.addCleanup(wt.unlock)
55
        root_id = wt.get_root_id()
6855.4.1 by Jelmer Vernooij
Yet more bees.
56
        wt.apply_inventory_delta([(None, 'bar/foo', b'foo-id',
57
            inventory.InventoryFile(b'foo-id', 'foo', parent_id=b'bar-id')),
58
            (None, 'bar', b'bar-id', inventory.InventoryDirectory(b'bar-id',
2376.2.1 by Aaron Bentley
Implement MutableTree.apply_inventory_delta
59
            'bar', parent_id=root_id))])
6855.4.1 by Jelmer Vernooij
Yet more bees.
60
        self.assertEqual('bar/foo', wt.id2path(b'foo-id'))
61
        self.assertEqual('bar', wt.id2path(b'bar-id'))
2376.2.1 by Aaron Bentley
Implement MutableTree.apply_inventory_delta
62
63
    def test_remove(self):
64
        wt = self.make_branch_and_tree('.')
65
        wt.lock_write()
66
        self.addCleanup(wt.unlock)
67
        self.build_tree(['foo/', 'foo/bar'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
68
        wt.add(['foo', 'foo/bar'], [b'foo-id', b'bar-id'])
69
        wt.apply_inventory_delta([('foo', None, b'foo-id', None),
70
                                  ('foo/bar', None, b'bar-id', None)])
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
71
        self.assertFalse(wt.is_versioned('foo'))
2376.2.1 by Aaron Bentley
Implement MutableTree.apply_inventory_delta
72
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
73
    def test_rename_dir_with_children(self):
74
        wt = self.make_branch_and_tree('.')
75
        wt.lock_write()
76
        root_id = wt.get_root_id()
77
        self.addCleanup(wt.unlock)
78
        self.build_tree(['foo/', 'foo/bar'])
79
        wt.add(['foo', 'foo/bar'],
6855.4.1 by Jelmer Vernooij
Yet more bees.
80
               [b'foo-id', b'bar-id'])
81
        wt.apply_inventory_delta([('foo', 'baz', b'foo-id',
82
            inventory.InventoryDirectory(b'foo-id', 'baz', root_id))])
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
83
        # foo/bar should have been followed the rename of its parent to baz/bar
6855.4.1 by Jelmer Vernooij
Yet more bees.
84
        self.assertEqual('baz', wt.id2path(b'foo-id'))
85
        self.assertEqual('baz/bar', wt.id2path(b'bar-id'))
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
86
87
    def test_rename_dir_with_children_with_children(self):
88
        wt = self.make_branch_and_tree('.')
89
        wt.lock_write()
90
        root_id = wt.get_root_id()
91
        self.addCleanup(wt.unlock)
92
        self.build_tree(['foo/', 'foo/bar/', 'foo/bar/baz'])
93
        wt.add(['foo', 'foo/bar', 'foo/bar/baz'],
6855.4.1 by Jelmer Vernooij
Yet more bees.
94
               [b'foo-id', b'bar-id', b'baz-id'])
95
        wt.apply_inventory_delta([('foo', 'quux', b'foo-id',
96
            inventory.InventoryDirectory(b'foo-id', 'quux', root_id))])
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
97
        # foo/bar/baz should have been followed the rename of its parent's
98
        # parent to quux/bar/baz
6855.4.1 by Jelmer Vernooij
Yet more bees.
99
        self.assertEqual('quux/bar/baz', wt.id2path(b'baz-id'))
2865.1.1 by Robert Collins
Create new mutable tree method update_to_one_parent_via_delta for eventual use by commit.
100
2376.2.1 by Aaron Bentley
Implement MutableTree.apply_inventory_delta
101
    def test_rename_file(self):
102
        wt = self.make_branch_and_tree('.')
103
        wt.lock_write()
104
        self.addCleanup(wt.unlock)
105
        self.build_tree(['foo/', 'foo/bar', 'baz/'])
106
        wt.add(['foo', 'foo/bar', 'baz'],
6855.4.1 by Jelmer Vernooij
Yet more bees.
107
               [b'foo-id', b'bar-id', b'baz-id'])
108
        wt.apply_inventory_delta([('foo/bar', 'baz/bar', b'bar-id',
109
            inventory.InventoryFile(b'bar-id', 'bar', b'baz-id'))])
110
        self.assertEqual('baz/bar', wt.id2path(b'bar-id'))
2376.2.1 by Aaron Bentley
Implement MutableTree.apply_inventory_delta
111
112
    def test_rename_swap(self):
113
        """Test the swap-names edge case.
114
115
        foo and bar should swap names, but retain their children.  If this
116
        works, any simpler rename ought to work.
117
        """
118
        wt = self.make_branch_and_tree('.')
119
        wt.lock_write()
120
        root_id = wt.get_root_id()
121
        self.addCleanup(wt.unlock)
122
        self.build_tree(['foo/', 'foo/bar', 'baz/', 'baz/qux'])
123
        wt.add(['foo', 'foo/bar', 'baz', 'baz/qux'],
6855.4.1 by Jelmer Vernooij
Yet more bees.
124
               [b'foo-id', b'bar-id', b'baz-id', b'qux-id'])
125
        wt.apply_inventory_delta([('foo', 'baz', b'foo-id',
126
            inventory.InventoryDirectory(b'foo-id', 'baz', root_id)),
127
            ('baz', 'foo', b'baz-id',
128
            inventory.InventoryDirectory(b'baz-id', 'foo', root_id))])
129
        self.assertEqual('baz/bar', wt.id2path(b'bar-id'))
130
        self.assertEqual('foo/qux', wt.id2path(b'qux-id'))
2376.2.3 by Aaron Bentley
Fix root replacement for apply_inventory_delta
131
2376.2.7 by Aaron Bentley
Add another test case (suggested by John Meinel)
132
    def test_child_rename_ordering(self):
133
        """Test the rename-parent, move child edge case.
134
135
        (A naive implementation may move the parent first, and then be
136
         unable to find the child.)
137
        """
138
        wt = self.make_branch_and_tree('.')
139
        root_id = wt.get_root_id()
140
        self.build_tree(['dir/', 'dir/child', 'other/'])
141
        wt.add(['dir', 'dir/child', 'other'],
6855.4.1 by Jelmer Vernooij
Yet more bees.
142
               [b'dir-id', b'child-id', b'other-id'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
143
        # this delta moves dir-id to dir2 and reparents
2865.1.3 by Robert Collins
Review feedback.
144
        # child-id to a parent of other-id
6855.4.1 by Jelmer Vernooij
Yet more bees.
145
        wt.apply_inventory_delta([('dir', 'dir2', b'dir-id',
146
            inventory.InventoryDirectory(b'dir-id', 'dir2', root_id)),
147
            ('dir/child', 'other/child', b'child-id',
148
             inventory.InventoryFile(b'child-id', 'child', b'other-id'))])
149
        self.assertEqual('dir2', wt.id2path(b'dir-id'))
150
        self.assertEqual('other/child', wt.id2path(b'child-id'))
2376.2.7 by Aaron Bentley
Add another test case (suggested by John Meinel)
151
2376.2.3 by Aaron Bentley
Fix root replacement for apply_inventory_delta
152
    def test_replace_root(self):
153
        wt = self.make_branch_and_tree('.')
154
        wt.lock_write()
155
        self.addCleanup(wt.unlock)
156
157
        root_id = wt.get_root_id()
158
        wt.apply_inventory_delta([('', None, root_id, None),
6973.13.2 by Jelmer Vernooij
Fix some more tests.
159
            (None, '', b'root-id',
160
             inventory.InventoryDirectory(b'root-id', '', None))])
5786.1.1 by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference
161
162
163
class TestTreeReference(TestCaseWithWorkingTree):
164
165
    def test_tree_reference_matches_inv(self):
5858.3.2 by Jelmer Vernooij
Fix spacing.
166
        base = self.make_branch_and_tree('base')
5858.3.1 by Jelmer Vernooij
Raise TestNotApplicable for things that don't have an inventory delta.
167
        if base.branch.repository._format.supports_full_versioned_files:
168
            raise tests.TestNotApplicable(
169
                "format does not support inventory deltas")
5786.1.6 by John Arbash Meinel
Clean up some of the old tests that I had updated.
170
        if not base.supports_tree_reference():
171
            raise tests.TestNotApplicable("wt doesn't support nested trees")
6926.2.8 by Jelmer Vernooij
Fix some more tests.
172
        if base.has_versioned_directories():
173
            # We add it as a directory, but it becomes a tree-reference
174
            base.add(['subdir'], [None], ['directory'])
175
            subdir = self.make_branch_and_tree('base/subdir')
176
        else:
177
            subdir = self.make_branch_and_tree('base/subdir')
178
            subdir.commit('')
179
            # We add it as a directory, but it becomes a tree-reference
180
            base.add(['subdir'], [None], ['tree-reference'])
5786.1.1 by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference
181
        self.addCleanup(base.lock_read().unlock)
5786.1.6 by John Arbash Meinel
Clean up some of the old tests that I had updated.
182
        # Note: we aren't strict about ie.kind being 'directory' here, what we
183
        # are strict about is that wt.inventory should match
184
        # wt.current_dirstate()'s idea about what files are where.
6885.6.1 by Jelmer Vernooij
Support specific_files argument to Tree.iter_entries_by_dir.
185
        path, ie = next(base.iter_entries_by_dir(specific_files=['subdir']))
5786.1.1 by John Arbash Meinel
Fix bug #764677. WT.inventory should correctly return TreeReference
186
        self.assertEqual('subdir', path)
187
        self.assertEqual('tree-reference', ie.kind)