~bzr-pqm/bzr/bzr.dev

3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
1
# Copyright (C) 2007, 2008 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
23
from bzrlib.diff import internal_diff
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
24
from bzrlib.mutabletree import MutableTree
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
25
from bzrlib.osutils import has_symlinks
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
26
from bzrlib.tests import SymlinkFeature, TestSkipped
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
27
from bzrlib.tests.tree_implementations import TestCaseWithTree
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
28
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.
29
from bzrlib.uncommit import uncommit
30
31
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
32
def get_entry(tree, file_id):
33
    return tree.iter_entries_by_dir([file_id]).next()[1]
3363.2.7 by Aaron Bentley
Implement alterntative-to-inventory tests
34
35
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
36
class TestPreviousHeads(TestCaseWithTree):
37
38
    def setUp(self):
39
        # we want several inventories, that respectively
40
        # give use the following scenarios:
41
        # A) fileid not in any inventory (A),
42
        # B) fileid present in one inventory (B) and (A,B)
43
        # C) fileid present in two inventories, and they
44
        #   are not mutual descendents (B, C)
45
        # D) fileid present in two inventories and one is
46
        #   a descendent of the other. (B, D)
47
        super(TestPreviousHeads, self).setUp()
48
        self.wt = self.make_branch_and_tree('.')
49
        self.branch = self.wt.branch
50
        self.build_tree(['file'])
51
        self.wt.commit('new branch', allow_pointless=True, rev_id='A')
52
        self.inv_A = self.branch.repository.get_inventory('A')
53
        self.wt.add(['file'], ['fileid'])
54
        self.wt.commit('add file', rev_id='B')
55
        self.inv_B = self.branch.repository.get_inventory('B')
56
        uncommit(self.branch, tree=self.wt)
57
        self.assertEqual(self.branch.revision_history(), ['A'])
58
        self.wt.commit('another add of file', rev_id='C')
59
        self.inv_C = self.branch.repository.get_inventory('C')
60
        self.wt.add_parent_tree_id('B')
61
        self.wt.commit('merge in B', rev_id='D')
62
        self.inv_D = self.branch.repository.get_inventory('D')
63
        self.tree = self.workingtree_to_test_tree(self.wt)
64
        self.tree.lock_read()
65
        self.addCleanup(self.tree.unlock)
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
66
        self.file_active = get_entry(self.tree, 'fileid')
67
68
    # TODO: test two inventories with the same file revision
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
69
70
71
class TestInventory(TestCaseWithTree):
72
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
73
    def _set_up(self):
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
74
        self.tree = self.get_tree_with_subdirs_and_all_content_types()
75
        self.tree.lock_read()
76
        self.addCleanup(self.tree.unlock)
77
78
    def test_symlink_target(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
79
        self.requireFeature(SymlinkFeature)
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
80
        self._set_up()
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
81
        if isinstance(self.tree, (MutableTree, _PreviewTree)):
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
82
            raise TestSkipped(
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
83
                'symlinks not accurately represented in working trees and'
84
                ' preview trees')
85
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
86
        self.assertEqual(entry.symlink_target, 'link-target')
87
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
88
    def test_symlink_target_tree(self):
89
        self.requireFeature(SymlinkFeature)
90
        self._set_up()
91
        self.assertEqual('link-target',
92
                         self.tree.get_symlink_target('symlink'))
93
94
    def test_kind_symlink(self):
95
        self.requireFeature(SymlinkFeature)
96
        self._set_up()
97
        self.assertEqual('symlink', self.tree.kind('symlink'))
98
        self.assertIs(None, self.tree.get_file_size('symlink'))
99
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
100
    def test_symlink(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
101
        self.requireFeature(SymlinkFeature)
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
102
        self._set_up()
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
103
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
104
        self.assertEqual(entry.kind, 'symlink')
105
        self.assertEqual(None, entry.text_size)
3363.12.1 by Aaron Bentley
Remove new implementation of paths2ids, implement has_id
106
107
    def test_paths2ids_recursive(self):
108
        work_tree = self.make_branch_and_tree('tree')
109
        self.build_tree(['tree/dir/', 'tree/dir/file'])
110
        work_tree.add(['dir', 'dir/file'], ['dir-id', 'file-id'])
111
        tree = self._convert_tree(work_tree)
112
        tree.lock_read()
113
        self.addCleanup(tree.unlock)
114
        self.assertEqual(set(['dir-id', 'file-id']), tree.paths2ids(['dir']))
115
116
    def test_paths2ids_forget_old(self):
117
        work_tree = self.make_branch_and_tree('tree')
118
        self.build_tree(['tree/file'])
119
        work_tree.add('file', 'first-id')
120
        work_tree.commit('commit old state')
121
        work_tree.remove('file')
122
        tree = self._convert_tree(work_tree)
123
        tree.lock_read()
124
        self.addCleanup(tree.unlock)
125
        self.assertEqual(set([]), tree.paths2ids(['file'],
126
                         require_versioned=False))
3794.5.5 by Mark Hammond
Add get_canonical_path method to the Tree class, plus tests.
127
3794.5.34 by Mark Hammond
refactor common test code into its own method
128
    def _make_canonical_test_tree(self, commit=True):
129
        # make a tree used by all the 'canonical' tests below.
130
        work_tree = self.make_branch_and_tree('tree')
131
        self.build_tree(['tree/dir/', 'tree/dir/file'])
132
        work_tree.add(['dir', 'dir/file'])
133
        if commit:
134
            work_tree.commit('commit 1')
135
        return work_tree
136
3794.5.5 by Mark Hammond
Add get_canonical_path method to the Tree class, plus tests.
137
    def test_canonical_path(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
138
        work_tree = self._make_canonical_test_tree()
3794.5.21 by Mark Hammond
More cicp-filesystem tests
139
        self.assertEqual(work_tree.get_canonical_inventory_path('Dir/File'), 'dir/file')
140
141
    def test_canonical_path_before_commit(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
142
        work_tree = self._make_canonical_test_tree(False)
3794.5.21 by Mark Hammond
More cicp-filesystem tests
143
        # note: not committed.
144
        self.assertEqual(work_tree.get_canonical_inventory_path('Dir/File'), 'dir/file')
145
146
    def test_canonical_path_dir(self):
147
        # check it works when asked for just the directory portion.
3794.5.34 by Mark Hammond
refactor common test code into its own method
148
        work_tree = self._make_canonical_test_tree()
3794.5.21 by Mark Hammond
More cicp-filesystem tests
149
        self.assertEqual(work_tree.get_canonical_inventory_path('Dir'), 'dir')
3794.5.5 by Mark Hammond
Add get_canonical_path method to the Tree class, plus tests.
150
151
    def test_canonical_path_root(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
152
        work_tree = self._make_canonical_test_tree()
3794.5.21 by Mark Hammond
More cicp-filesystem tests
153
        self.assertEqual(work_tree.get_canonical_inventory_path(''), '')
154
        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.
155
156
    def test_canonical_path_invalid_all(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
157
        work_tree = self._make_canonical_test_tree()
3794.5.21 by Mark Hammond
More cicp-filesystem tests
158
        self.assertEqual(work_tree.get_canonical_inventory_path('foo/bar'), 'foo/bar')
3794.5.5 by Mark Hammond
Add get_canonical_path method to the Tree class, plus tests.
159
160
    def test_canonical_invalid_child(self):
3794.5.34 by Mark Hammond
refactor common test code into its own method
161
        work_tree = self._make_canonical_test_tree()
3794.5.21 by Mark Hammond
More cicp-filesystem tests
162
        self.assertEqual(work_tree.get_canonical_inventory_path('Dir/None'), 'dir/None')