/brz/remove-bazaar

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