~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_tree/test_inv.py

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:56:05 UTC
  • mfrom: (6615.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201195605-o7rl92wf6uyum3fk
(vila) Open trunk again as 2.8b1 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests for interface conformance of inventories of trees."""
18
18
 
19
19
 
20
 
from cStringIO import StringIO
21
 
import os
22
 
 
23
20
from bzrlib import (
24
21
    tests,
25
22
    )
26
23
from bzrlib.tests import (
27
 
    features,
28
24
    per_tree,
29
25
    )
30
26
from bzrlib.mutabletree import MutableTree
31
 
from bzrlib.tests import SymlinkFeature, TestSkipped
 
27
from bzrlib.tests import TestSkipped
 
28
from bzrlib.tree import InventoryTree
32
29
from bzrlib.transform import _PreviewTree
33
30
from bzrlib.uncommit import uncommit
 
31
from bzrlib.tests import (
 
32
    features,
 
33
    )
34
34
 
35
35
 
36
36
def get_entry(tree, file_id):
37
37
    return tree.iter_entries_by_dir([file_id]).next()[1]
38
38
 
39
39
 
40
 
class TestPreviousHeads(per_tree.TestCaseWithTree):
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)
70
 
        self.file_active = get_entry(self.tree, 'fileid')
71
 
 
72
 
    # TODO: test two inventories with the same file revision
73
 
 
74
 
 
75
40
class TestInventoryWithSymlinks(per_tree.TestCaseWithTree):
76
41
 
77
 
    _test_needs_features = [tests.SymlinkFeature]
 
42
    _test_needs_features = [features.SymlinkFeature]
78
43
 
79
44
    def setUp(self):
80
 
        per_tree.TestCaseWithTree.setUp(self)
 
45
        super(TestInventoryWithSymlinks, self).setUp()
81
46
        self.tree = self.get_tree_with_subdirs_and_all_content_types()
82
47
        self.tree.lock_read()
83
48
        self.addCleanup(self.tree.unlock)
140
105
 
141
106
    def test_canonical_path(self):
142
107
        work_tree = self._make_canonical_test_tree()
 
108
        if not isinstance(work_tree, InventoryTree):
 
109
            raise tests.TestNotApplicable(
 
110
                "test not applicable on non-inventory tests")
143
111
        self.assertEqual('dir/file',
144
112
                         work_tree.get_canonical_inventory_path('Dir/File'))
145
113
 
146
114
    def test_canonical_path_before_commit(self):
147
115
        work_tree = self._make_canonical_test_tree(False)
148
 
        # note: not committed.
 
116
        if not isinstance(work_tree, InventoryTree):
 
117
            raise tests.TestNotApplicable(
 
118
                "test not applicable on non-inventory tests")        # note: not committed.
149
119
        self.assertEqual('dir/file',
150
120
                         work_tree.get_canonical_inventory_path('Dir/File'))
151
121
 
152
122
    def test_canonical_path_dir(self):
153
123
        # check it works when asked for just the directory portion.
154
124
        work_tree = self._make_canonical_test_tree()
 
125
        if not isinstance(work_tree, InventoryTree):
 
126
            raise tests.TestNotApplicable(
 
127
                "test not applicable on non-inventory tests")
155
128
        self.assertEqual('dir', work_tree.get_canonical_inventory_path('Dir'))
156
129
 
157
130
    def test_canonical_path_root(self):
158
131
        work_tree = self._make_canonical_test_tree()
 
132
        if not isinstance(work_tree, InventoryTree):
 
133
            raise tests.TestNotApplicable(
 
134
                "test not applicable on non-inventory tests")
159
135
        self.assertEqual('', work_tree.get_canonical_inventory_path(''))
160
136
        self.assertEqual('/', work_tree.get_canonical_inventory_path('/'))
161
137
 
162
138
    def test_canonical_path_invalid_all(self):
163
139
        work_tree = self._make_canonical_test_tree()
 
140
        if not isinstance(work_tree, InventoryTree):
 
141
            raise tests.TestNotApplicable(
 
142
                "test not applicable on non-inventory tests")
164
143
        self.assertEqual('foo/bar',
165
144
                         work_tree.get_canonical_inventory_path('foo/bar'))
166
145
 
167
146
    def test_canonical_invalid_child(self):
168
147
        work_tree = self._make_canonical_test_tree()
 
148
        if not isinstance(work_tree, InventoryTree):
 
149
            raise tests.TestNotApplicable(
 
150
                "test not applicable on non-inventory tests")
169
151
        self.assertEqual('dir/None',
170
152
                         work_tree.get_canonical_inventory_path('Dir/None'))
171
153
 
174
156
        # some of the trees we want to use can only exist on a disk, not in
175
157
        # memory - therefore we can only test this if the filesystem is
176
158
        # case-sensitive.
177
 
        self.requireFeature(tests.case_sensitive_filesystem_feature)
 
159
        self.requireFeature(features.case_sensitive_filesystem_feature)
178
160
        work_tree = self.make_branch_and_tree('.')
179
161
        self.build_tree(['test/', 'test/file', 'Test'])
180
162
        work_tree.add(['test/', 'test/file', 'Test'])
181
163
 
182
164
        test_tree = self._convert_tree(work_tree)
 
165
        if not isinstance(test_tree, InventoryTree):
 
166
            raise tests.TestNotApplicable(
 
167
                "test not applicable on non-inventory tests")
183
168
        test_tree.lock_read()
184
169
        self.addCleanup(test_tree.unlock)
185
170