~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
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
20
from bzrlib import (
21
    tests,
22
    )
4634.131.4 by Martin Pool
test_canonical_tree_name_mismatch needs a case-sensitive filesystem
23
from bzrlib.tests import (
24
    per_tree,
25
    )
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
26
from bzrlib.mutabletree import MutableTree
5777.4.1 by Jelmer Vernooij
Split inventory-specific code out of MutableTree into MutableInventoryTree.
27
from bzrlib.tests import TestSkipped
5807.2.2 by Jelmer Vernooij
Skip tests that apply to inventory trees only when run against non-inventory trees.
28
from bzrlib.tree import InventoryTree
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
29
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.
30
from bzrlib.uncommit import uncommit
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
31
from bzrlib.tests import (
32
    features,
33
    )
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
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 TestInventoryWithSymlinks(per_tree.TestCaseWithTree):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
41
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
42
    _test_needs_features = [features.SymlinkFeature]
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
43
44
    def setUp(self):
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
45
        per_tree.TestCaseWithTree.setUp(self)
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
46
        self.tree = self.get_tree_with_subdirs_and_all_content_types()
47
        self.tree.lock_read()
48
        self.addCleanup(self.tree.unlock)
49
50
    def test_symlink_target(self):
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
51
        if isinstance(self.tree, (MutableTree, _PreviewTree)):
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
52
            raise TestSkipped(
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
53
                'symlinks not accurately represented in working trees and'
54
                ' preview trees')
55
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
56
        self.assertEqual(entry.symlink_target, 'link-target')
57
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
58
    def test_symlink_target_tree(self):
59
        self.assertEqual('link-target',
60
                         self.tree.get_symlink_target('symlink'))
61
62
    def test_kind_symlink(self):
63
        self.assertEqual('symlink', self.tree.kind('symlink'))
64
        self.assertIs(None, self.tree.get_file_size('symlink'))
65
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
66
    def test_symlink(self):
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
67
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
68
        self.assertEqual(entry.kind, 'symlink')
69
        self.assertEqual(None, entry.text_size)
3363.12.1 by Aaron Bentley
Remove new implementation of paths2ids, implement has_id
70
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
71
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
72
class TestInventory(per_tree.TestCaseWithTree):
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
73
3363.12.1 by Aaron Bentley
Remove new implementation of paths2ids, implement has_id
74
    def test_paths2ids_recursive(self):
75
        work_tree = self.make_branch_and_tree('tree')
76
        self.build_tree(['tree/dir/', 'tree/dir/file'])
77
        work_tree.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
78
        tree = self._convert_tree(work_tree)
79
        tree.lock_read()
80
        self.addCleanup(tree.unlock)
81
        self.assertEqual(set(['dir-id', 'file-id']), tree.paths2ids(['dir']))
82
83
    def test_paths2ids_forget_old(self):
84
        work_tree = self.make_branch_and_tree('tree')
85
        self.build_tree(['tree/file'])
86
        work_tree.add('file', 'first-id')
87
        work_tree.commit('commit old state')
88
        work_tree.remove('file')
89
        tree = self._convert_tree(work_tree)
90
        tree.lock_read()
91
        self.addCleanup(tree.unlock)
92
        self.assertEqual(set([]), tree.paths2ids(['file'],
93
                         require_versioned=False))
3794.5.5 by Mark Hammond
Add get_canonical_path method to the Tree class, plus tests.
94
3794.5.34 by Mark Hammond
refactor common test code into its own method
95
    def _make_canonical_test_tree(self, commit=True):
96
        # make a tree used by all the 'canonical' tests below.
97
        work_tree = self.make_branch_and_tree('tree')
98
        self.build_tree(['tree/dir/', 'tree/dir/file'])
99
        work_tree.add(['dir', 'dir/file'])
100
        if commit:
101
            work_tree.commit('commit 1')
4634.131.2 by Martin Pool
doc
102
        # XXX: this isn't actually guaranteed to return the class we want to
103
        # test -- mbp 2010-02-12
3794.5.34 by Mark Hammond
refactor common test code into its own method
104
        return work_tree
105
3794.5.5 by Mark Hammond
Add get_canonical_path method to the Tree class, plus tests.
106
    def test_canonical_path(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
107
        work_tree = self._make_canonical_test_tree()
5807.2.2 by Jelmer Vernooij
Skip tests that apply to inventory trees only when run against non-inventory trees.
108
        if not isinstance(work_tree, InventoryTree):
109
            raise tests.TestNotApplicable(
110
                "test not applicable on non-inventory tests")
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
111
        self.assertEqual('dir/file',
112
                         work_tree.get_canonical_inventory_path('Dir/File'))
3794.5.21 by Mark Hammond
More cicp-filesystem tests
113
114
    def test_canonical_path_before_commit(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
115
        work_tree = self._make_canonical_test_tree(False)
5807.2.2 by Jelmer Vernooij
Skip tests that apply to inventory trees only when run against non-inventory trees.
116
        if not isinstance(work_tree, InventoryTree):
117
            raise tests.TestNotApplicable(
118
                "test not applicable on non-inventory tests")        # note: not committed.
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
119
        self.assertEqual('dir/file',
120
                         work_tree.get_canonical_inventory_path('Dir/File'))
3794.5.21 by Mark Hammond
More cicp-filesystem tests
121
122
    def test_canonical_path_dir(self):
123
        # check it works when asked for just the directory portion.
3794.5.34 by Mark Hammond
refactor common test code into its own method
124
        work_tree = self._make_canonical_test_tree()
5807.2.2 by Jelmer Vernooij
Skip tests that apply to inventory trees only when run against non-inventory trees.
125
        if not isinstance(work_tree, InventoryTree):
126
            raise tests.TestNotApplicable(
127
                "test not applicable on non-inventory tests")
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
128
        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.
129
130
    def test_canonical_path_root(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
131
        work_tree = self._make_canonical_test_tree()
5807.2.2 by Jelmer Vernooij
Skip tests that apply to inventory trees only when run against non-inventory trees.
132
        if not isinstance(work_tree, InventoryTree):
133
            raise tests.TestNotApplicable(
134
                "test not applicable on non-inventory tests")
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
135
        self.assertEqual('', work_tree.get_canonical_inventory_path(''))
136
        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.
137
138
    def test_canonical_path_invalid_all(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
139
        work_tree = self._make_canonical_test_tree()
5807.2.2 by Jelmer Vernooij
Skip tests that apply to inventory trees only when run against non-inventory trees.
140
        if not isinstance(work_tree, InventoryTree):
141
            raise tests.TestNotApplicable(
142
                "test not applicable on non-inventory tests")
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
143
        self.assertEqual('foo/bar',
144
                         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.
145
146
    def test_canonical_invalid_child(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
147
        work_tree = self._make_canonical_test_tree()
5807.2.2 by Jelmer Vernooij
Skip tests that apply to inventory trees only when run against non-inventory trees.
148
        if not isinstance(work_tree, InventoryTree):
149
            raise tests.TestNotApplicable(
150
                "test not applicable on non-inventory tests")
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
151
        self.assertEqual('dir/None',
152
                         work_tree.get_canonical_inventory_path('Dir/None'))
4634.131.1 by Martin Pool
_yield_canonical_inventory_paths copes better with case sensitivity.
153
154
    def test_canonical_tree_name_mismatch(self):
5243.1.2 by Martin
Point launchpad links in comments at production server rather than edge
155
        # see <https://bugs.launchpad.net/bzr/+bug/368931>
4634.131.2 by Martin Pool
doc
156
        # some of the trees we want to use can only exist on a disk, not in
157
        # memory - therefore we can only test this if the filesystem is
158
        # case-sensitive.
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
159
        self.requireFeature(features.case_sensitive_filesystem_feature)
4634.131.1 by Martin Pool
_yield_canonical_inventory_paths copes better with case sensitivity.
160
        work_tree = self.make_branch_and_tree('.')
161
        self.build_tree(['test/', 'test/file', 'Test'])
162
        work_tree.add(['test/', 'test/file', 'Test'])
4634.131.6 by Martin Pool
Actually test the right tree class in per_tree
163
164
        test_tree = self._convert_tree(work_tree)
5807.2.2 by Jelmer Vernooij
Skip tests that apply to inventory trees only when run against non-inventory trees.
165
        if not isinstance(test_tree, InventoryTree):
166
            raise tests.TestNotApplicable(
167
                "test not applicable on non-inventory tests")
4634.131.6 by Martin Pool
Actually test the right tree class in per_tree
168
        test_tree.lock_read()
169
        self.addCleanup(test_tree.unlock)
170
4634.131.1 by Martin Pool
_yield_canonical_inventory_paths copes better with case sensitivity.
171
        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
172
            test_tree.get_canonical_inventory_paths(
4634.131.1 by Martin Pool
_yield_canonical_inventory_paths copes better with case sensitivity.
173
                ['test', 'test/file', 'Test', 'test/foo', 'Test/foo']))