~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

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
34
31
 
37
34
    return tree.iter_entries_by_dir([file_id]).next()[1]
38
35
 
39
36
 
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
37
class TestInventoryWithSymlinks(per_tree.TestCaseWithTree):
76
38
 
77
39
    _test_needs_features = [tests.SymlinkFeature]
140
102
 
141
103
    def test_canonical_path(self):
142
104
        work_tree = self._make_canonical_test_tree()
 
105
        if not isinstance(work_tree, InventoryTree):
 
106
            raise tests.TestNotApplicable(
 
107
                "test not applicable on non-inventory tests")
143
108
        self.assertEqual('dir/file',
144
109
                         work_tree.get_canonical_inventory_path('Dir/File'))
145
110
 
146
111
    def test_canonical_path_before_commit(self):
147
112
        work_tree = self._make_canonical_test_tree(False)
148
 
        # note: not committed.
 
113
        if not isinstance(work_tree, InventoryTree):
 
114
            raise tests.TestNotApplicable(
 
115
                "test not applicable on non-inventory tests")        # note: not committed.
149
116
        self.assertEqual('dir/file',
150
117
                         work_tree.get_canonical_inventory_path('Dir/File'))
151
118
 
152
119
    def test_canonical_path_dir(self):
153
120
        # check it works when asked for just the directory portion.
154
121
        work_tree = self._make_canonical_test_tree()
 
122
        if not isinstance(work_tree, InventoryTree):
 
123
            raise tests.TestNotApplicable(
 
124
                "test not applicable on non-inventory tests")
155
125
        self.assertEqual('dir', work_tree.get_canonical_inventory_path('Dir'))
156
126
 
157
127
    def test_canonical_path_root(self):
158
128
        work_tree = self._make_canonical_test_tree()
 
129
        if not isinstance(work_tree, InventoryTree):
 
130
            raise tests.TestNotApplicable(
 
131
                "test not applicable on non-inventory tests")
159
132
        self.assertEqual('', work_tree.get_canonical_inventory_path(''))
160
133
        self.assertEqual('/', work_tree.get_canonical_inventory_path('/'))
161
134
 
162
135
    def test_canonical_path_invalid_all(self):
163
136
        work_tree = self._make_canonical_test_tree()
 
137
        if not isinstance(work_tree, InventoryTree):
 
138
            raise tests.TestNotApplicable(
 
139
                "test not applicable on non-inventory tests")
164
140
        self.assertEqual('foo/bar',
165
141
                         work_tree.get_canonical_inventory_path('foo/bar'))
166
142
 
167
143
    def test_canonical_invalid_child(self):
168
144
        work_tree = self._make_canonical_test_tree()
 
145
        if not isinstance(work_tree, InventoryTree):
 
146
            raise tests.TestNotApplicable(
 
147
                "test not applicable on non-inventory tests")
169
148
        self.assertEqual('dir/None',
170
149
                         work_tree.get_canonical_inventory_path('Dir/None'))
171
150
 
180
159
        work_tree.add(['test/', 'test/file', 'Test'])
181
160
 
182
161
        test_tree = self._convert_tree(work_tree)
 
162
        if not isinstance(test_tree, InventoryTree):
 
163
            raise tests.TestNotApplicable(
 
164
                "test not applicable on non-inventory tests")
183
165
        test_tree.lock_read()
184
166
        self.addCleanup(test_tree.unlock)
185
167