/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

Merge with preview-tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
24
24
from bzrlib.mutabletree import MutableTree
25
25
from bzrlib.osutils import has_symlinks
26
26
from bzrlib.symbol_versioning import zero_ninetyone, one_zero
27
 
from bzrlib.tests import SymlinkFeature, TestSkipped, TestNotApplicable
 
27
from bzrlib.tests import SymlinkFeature, TestSkipped
28
28
from bzrlib.tests.tree_implementations import TestCaseWithTree
 
29
from bzrlib.transform import _PreviewTree
29
30
from bzrlib.uncommit import uncommit
30
31
 
31
32
 
32
 
def get_inventory_if_applicable(tree):
33
 
    try:
34
 
        return tree.inventory
35
 
    except NotImplementedError:
36
 
        raise TestNotApplicable('Tree does not implement inventory')
 
33
def get_entry(tree, file_id):
 
34
    return tree.iter_entries_by_dir([file_id]).next()[1]
37
35
 
38
36
 
39
37
class TestEntryDiffing(TestCaseWithTree):
62
60
        self.tree_2 = self.workingtree_to_test_tree(self.wt)
63
61
        self.tree_2.lock_read()
64
62
        self.addCleanup(self.tree_2.unlock)
65
 
        self.inv_2 = get_inventory_if_applicable(self.tree_2)
66
 
        self.file_2 = self.inv_2['fileid']
67
 
        self.file_2b = self.inv_2['binfileid']
 
63
        self.file_2 = get_entry(self.tree_2, 'fileid')
 
64
        self.file_2b = get_entry(self.tree_2, 'binfileid')
68
65
        if has_symlinks():
69
66
            self.link_1 = self.inv_1['linkid']
70
 
            self.link_2 = self.inv_2['linkid']
 
67
            self.link_2 = get_entry(self.tree_2, 'linkid')
71
68
 
72
69
    def test_file_diff_deleted(self):
73
70
        output = StringIO()
111
108
                                            "-foo\n"
112
109
                                            "+bar\n"
113
110
                                            "\n")
114
 
        
 
111
 
115
112
    def test_file_diff_binary(self):
116
113
        output = StringIO()
117
114
        self.applyDeprecated(one_zero,
120
117
                             "/dev/null", self.tree_1,
121
118
                             "new_label", self.file_2b, self.tree_2,
122
119
                             output)
123
 
        self.assertEqual(output.getvalue(), 
 
120
        self.assertEqual(output.getvalue(),
124
121
                         "Binary files /dev/null and new_label differ\n")
125
122
 
126
123
    def test_link_diff_deleted(self):
189
186
        self.tree = self.workingtree_to_test_tree(self.wt)
190
187
        self.tree.lock_read()
191
188
        self.addCleanup(self.tree.unlock)
192
 
        self.file_active = get_inventory_if_applicable(self.tree)['fileid']
 
189
        self.file_active = get_entry(self.tree, 'fileid')
193
190
        self.weave = self.branch.repository.weave_store.get_weave('fileid',
194
191
            self.branch.repository.get_transaction())
195
 
        
 
192
 
196
193
    def get_previous_heads(self, inventories):
197
194
        return self.applyDeprecated(zero_ninetyone,
198
195
            self.file_active.find_previous_heads,
199
196
            inventories,
200
197
            self.branch.repository.weave_store,
201
198
            self.branch.repository.get_transaction())
202
 
        
 
199
 
203
200
    def test_fileid_in_no_inventory(self):
204
201
        self.assertEqual({}, self.get_previous_heads([self.inv_A]))
205
202
 
225
222
        self.assertEqual({'D':self.inv_D['fileid']},
226
223
                         self.get_previous_heads([self.inv_D, self.inv_B]))
227
224
 
228
 
    # TODO: test two inventories with the same file revision 
 
225
    # TODO: test two inventories with the same file revision
229
226
 
230
227
 
231
228
class TestInventory(TestCaseWithTree):
234
231
        self.tree = self.get_tree_with_subdirs_and_all_content_types()
235
232
        self.tree.lock_read()
236
233
        self.addCleanup(self.tree.unlock)
237
 
        # Commenting out the following line still fails.
238
 
        self.inv = get_inventory_if_applicable(self.tree)
239
234
 
240
235
    def test_symlink_target(self):
241
236
        self.requireFeature(SymlinkFeature)
242
237
        self._set_up()
243
 
        if isinstance(self.tree, MutableTree):
 
238
        if isinstance(self.tree, (MutableTree, _PreviewTree)):
244
239
            raise TestSkipped(
245
 
                'symlinks not accurately represented in working trees')
246
 
        entry = self.inv[self.inv.path2id('symlink')]
 
240
                'symlinks not accurately represented in working trees and'
 
241
                ' preview trees')
 
242
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
247
243
        self.assertEqual(entry.symlink_target, 'link-target')
248
244
 
 
245
    def test_symlink_target_tree(self):
 
246
        self.requireFeature(SymlinkFeature)
 
247
        self._set_up()
 
248
        self.assertEqual('link-target',
 
249
                         self.tree.get_symlink_target('symlink'))
 
250
 
 
251
    def test_kind_symlink(self):
 
252
        self.requireFeature(SymlinkFeature)
 
253
        self._set_up()
 
254
        self.assertEqual('symlink', self.tree.kind('symlink'))
 
255
        self.assertIs(None, self.tree.get_file_size('symlink'))
 
256
 
249
257
    def test_symlink(self):
250
258
        self.requireFeature(SymlinkFeature)
251
259
        self._set_up()
252
 
        entry = self.inv[self.inv.path2id('symlink')]
 
260
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
253
261
        self.assertEqual(entry.kind, 'symlink')
254
262
        self.assertEqual(None, entry.text_size)