~bzr-pqm/bzr/bzr.dev

4797.19.2 by John Arbash Meinel
bring in the latest 2.1 changes
1
# Copyright (C) 2007-2010 Canonical Ltd
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
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.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
16
17
"""Tests for interface conformance of inventories of trees."""
18
19
20
from cStringIO import StringIO
21
import os
22
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
23
from bzrlib import (
24
    tests,
25
    )
4634.131.4 by Martin Pool
test_canonical_tree_name_mismatch needs a case-sensitive filesystem
26
from bzrlib.tests import (
27
    features,
28
    per_tree,
29
    )
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
30
from bzrlib.mutabletree import MutableTree
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
31
from bzrlib.tests import SymlinkFeature, TestSkipped
32
from bzrlib.transform import _PreviewTree
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
33
from bzrlib.uncommit import uncommit
34
35
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
36
def get_entry(tree, file_id):
37
    return tree.iter_entries_by_dir([file_id]).next()[1]
3363.2.7 by Aaron Bentley
Implement alterntative-to-inventory tests
38
39
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
40
class TestPreviousHeads(per_tree.TestCaseWithTree):
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
41
42
    def setUp(self):
43
        # we want several inventories, that respectively
44
        # give use the following scenarios:
45
        # A) fileid not in any inventory (A),
46
        # B) fileid present in one inventory (B) and (A,B)
47
        # C) fileid present in two inventories, and they
48
        #   are not mutual descendents (B, C)
49
        # D) fileid present in two inventories and one is
50
        #   a descendent of the other. (B, D)
51
        super(TestPreviousHeads, self).setUp()
52
        self.wt = self.make_branch_and_tree('.')
53
        self.branch = self.wt.branch
54
        self.build_tree(['file'])
55
        self.wt.commit('new branch', allow_pointless=True, rev_id='A')
56
        self.inv_A = self.branch.repository.get_inventory('A')
57
        self.wt.add(['file'], ['fileid'])
58
        self.wt.commit('add file', rev_id='B')
59
        self.inv_B = self.branch.repository.get_inventory('B')
60
        uncommit(self.branch, tree=self.wt)
61
        self.assertEqual(self.branch.revision_history(), ['A'])
62
        self.wt.commit('another add of file', rev_id='C')
63
        self.inv_C = self.branch.repository.get_inventory('C')
64
        self.wt.add_parent_tree_id('B')
65
        self.wt.commit('merge in B', rev_id='D')
66
        self.inv_D = self.branch.repository.get_inventory('D')
67
        self.tree = self.workingtree_to_test_tree(self.wt)
68
        self.tree.lock_read()
69
        self.addCleanup(self.tree.unlock)
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
70
        self.file_active = get_entry(self.tree, 'fileid')
71
72
    # TODO: test two inventories with the same file revision
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
73
74
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
75
class TestInventoryWithSymlinks(per_tree.TestCaseWithTree):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
76
77
    _test_needs_features = [tests.SymlinkFeature]
78
79
    def setUp(self):
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
80
        per_tree.TestCaseWithTree.setUp(self)
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
81
        self.tree = self.get_tree_with_subdirs_and_all_content_types()
82
        self.tree.lock_read()
83
        self.addCleanup(self.tree.unlock)
84
85
    def test_symlink_target(self):
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
86
        if isinstance(self.tree, (MutableTree, _PreviewTree)):
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
87
            raise TestSkipped(
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
88
                'symlinks not accurately represented in working trees and'
89
                ' preview trees')
90
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
91
        self.assertEqual(entry.symlink_target, 'link-target')
92
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
93
    def test_symlink_target_tree(self):
94
        self.assertEqual('link-target',
95
                         self.tree.get_symlink_target('symlink'))
96
97
    def test_kind_symlink(self):
98
        self.assertEqual('symlink', self.tree.kind('symlink'))
99
        self.assertIs(None, self.tree.get_file_size('symlink'))
100
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
101
    def test_symlink(self):
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
102
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
103
        self.assertEqual(entry.kind, 'symlink')
104
        self.assertEqual(None, entry.text_size)
3363.12.1 by Aaron Bentley
Remove new implementation of paths2ids, implement has_id
105
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
106
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
107
class TestInventory(per_tree.TestCaseWithTree):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
108
3363.12.1 by Aaron Bentley
Remove new implementation of paths2ids, implement has_id
109
    def test_paths2ids_recursive(self):
110
        work_tree = self.make_branch_and_tree('tree')
111
        self.build_tree(['tree/dir/', 'tree/dir/file'])
112
        work_tree.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
113
        tree = self._convert_tree(work_tree)
114
        tree.lock_read()
115
        self.addCleanup(tree.unlock)
116
        self.assertEqual(set(['dir-id', 'file-id']), tree.paths2ids(['dir']))
117
118
    def test_paths2ids_forget_old(self):
119
        work_tree = self.make_branch_and_tree('tree')
120
        self.build_tree(['tree/file'])
121
        work_tree.add('file', 'first-id')
122
        work_tree.commit('commit old state')
123
        work_tree.remove('file')
124
        tree = self._convert_tree(work_tree)
125
        tree.lock_read()
126
        self.addCleanup(tree.unlock)
127
        self.assertEqual(set([]), tree.paths2ids(['file'],
128
                         require_versioned=False))
3794.5.5 by Mark Hammond
Add get_canonical_path method to the Tree class, plus tests.
129
3794.5.34 by Mark Hammond
refactor common test code into its own method
130
    def _make_canonical_test_tree(self, commit=True):
131
        # make a tree used by all the 'canonical' tests below.
132
        work_tree = self.make_branch_and_tree('tree')
133
        self.build_tree(['tree/dir/', 'tree/dir/file'])
134
        work_tree.add(['dir', 'dir/file'])
135
        if commit:
136
            work_tree.commit('commit 1')
4634.131.2 by Martin Pool
doc
137
        # XXX: this isn't actually guaranteed to return the class we want to
138
        # test -- mbp 2010-02-12
3794.5.34 by Mark Hammond
refactor common test code into its own method
139
        return work_tree
140
3794.5.5 by Mark Hammond
Add get_canonical_path method to the Tree class, plus tests.
141
    def test_canonical_path(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
142
        work_tree = self._make_canonical_test_tree()
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
143
        self.assertEqual('dir/file',
144
                         work_tree.get_canonical_inventory_path('Dir/File'))
3794.5.21 by Mark Hammond
More cicp-filesystem tests
145
146
    def test_canonical_path_before_commit(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
147
        work_tree = self._make_canonical_test_tree(False)
3794.5.21 by Mark Hammond
More cicp-filesystem tests
148
        # note: not committed.
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
149
        self.assertEqual('dir/file',
150
                         work_tree.get_canonical_inventory_path('Dir/File'))
3794.5.21 by Mark Hammond
More cicp-filesystem tests
151
152
    def test_canonical_path_dir(self):
153
        # check it works when asked for just the directory portion.
3794.5.34 by Mark Hammond
refactor common test code into its own method
154
        work_tree = self._make_canonical_test_tree()
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
155
        self.assertEqual('dir', work_tree.get_canonical_inventory_path('Dir'))
3794.5.5 by Mark Hammond
Add get_canonical_path method to the Tree class, plus tests.
156
157
    def test_canonical_path_root(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
158
        work_tree = self._make_canonical_test_tree()
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
159
        self.assertEqual('', work_tree.get_canonical_inventory_path(''))
160
        self.assertEqual('/', work_tree.get_canonical_inventory_path('/'))
3794.5.5 by Mark Hammond
Add get_canonical_path method to the Tree class, plus tests.
161
162
    def test_canonical_path_invalid_all(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
163
        work_tree = self._make_canonical_test_tree()
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
164
        self.assertEqual('foo/bar',
165
                         work_tree.get_canonical_inventory_path('foo/bar'))
3794.5.5 by Mark Hammond
Add get_canonical_path method to the Tree class, plus tests.
166
167
    def test_canonical_invalid_child(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
168
        work_tree = self._make_canonical_test_tree()
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
169
        self.assertEqual('dir/None',
170
                         work_tree.get_canonical_inventory_path('Dir/None'))
4634.131.1 by Martin Pool
_yield_canonical_inventory_paths copes better with case sensitivity.
171
172
    def test_canonical_tree_name_mismatch(self):
5243.1.2 by Martin
Point launchpad links in comments at production server rather than edge
173
        # see <https://bugs.launchpad.net/bzr/+bug/368931>
4634.131.2 by Martin Pool
doc
174
        # some of the trees we want to use can only exist on a disk, not in
175
        # memory - therefore we can only test this if the filesystem is
176
        # case-sensitive.
4634.131.5 by Martin Pool
feature moved back to bzrlib.tests with its friends
177
        self.requireFeature(tests.case_sensitive_filesystem_feature)
4634.131.1 by Martin Pool
_yield_canonical_inventory_paths copes better with case sensitivity.
178
        work_tree = self.make_branch_and_tree('.')
179
        self.build_tree(['test/', 'test/file', 'Test'])
180
        work_tree.add(['test/', 'test/file', 'Test'])
4634.131.6 by Martin Pool
Actually test the right tree class in per_tree
181
182
        test_tree = self._convert_tree(work_tree)
183
        test_tree.lock_read()
184
        self.addCleanup(test_tree.unlock)
185
4634.131.1 by Martin Pool
_yield_canonical_inventory_paths copes better with case sensitivity.
186
        self.assertEqual(['test', 'test/file', 'Test', 'test/foo', 'Test/foo'],
4634.131.6 by Martin Pool
Actually test the right tree class in per_tree
187
            test_tree.get_canonical_inventory_paths(
4634.131.1 by Martin Pool
_yield_canonical_inventory_paths copes better with case sensitivity.
188
                ['test', 'test/file', 'Test', 'test/foo', 'Test/foo']))