/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

  • Committer: John Arbash Meinel
  • Date: 2008-05-06 20:54:31 UTC
  • mfrom: (3407 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3443.
  • Revision ID: john@arbash-meinel.com-20080506205431-sr3y667ytc6t1pdu
Merge in the bzr.dev changes

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
26
26
from bzrlib.symbol_versioning import zero_ninetyone, one_zero
27
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
 
 
33
def get_entry(tree, file_id):
 
34
    return tree.iter_entries_by_dir([file_id]).next()[1]
 
35
 
 
36
 
32
37
class TestEntryDiffing(TestCaseWithTree):
33
38
 
34
39
    def setUp(self):
55
60
        self.tree_2 = self.workingtree_to_test_tree(self.wt)
56
61
        self.tree_2.lock_read()
57
62
        self.addCleanup(self.tree_2.unlock)
58
 
        self.inv_2 = self.tree_2.inventory
59
 
        self.file_2 = self.inv_2['fileid']
60
 
        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')
61
65
        if has_symlinks():
62
66
            self.link_1 = self.inv_1['linkid']
63
 
            self.link_2 = self.inv_2['linkid']
 
67
            self.link_2 = get_entry(self.tree_2, 'linkid')
64
68
 
65
69
    def test_file_diff_deleted(self):
66
70
        output = StringIO()
104
108
                                            "-foo\n"
105
109
                                            "+bar\n"
106
110
                                            "\n")
107
 
        
 
111
 
108
112
    def test_file_diff_binary(self):
109
113
        output = StringIO()
110
114
        self.applyDeprecated(one_zero,
113
117
                             "/dev/null", self.tree_1,
114
118
                             "new_label", self.file_2b, self.tree_2,
115
119
                             output)
116
 
        self.assertEqual(output.getvalue(), 
 
120
        self.assertEqual(output.getvalue(),
117
121
                         "Binary files /dev/null and new_label differ\n")
118
122
 
119
123
    def test_link_diff_deleted(self):
182
186
        self.tree = self.workingtree_to_test_tree(self.wt)
183
187
        self.tree.lock_read()
184
188
        self.addCleanup(self.tree.unlock)
185
 
        self.file_active = self.tree.inventory['fileid']
 
189
        self.file_active = get_entry(self.tree, 'fileid')
186
190
        self.weave = self.branch.repository.weave_store.get_weave('fileid',
187
191
            self.branch.repository.get_transaction())
188
 
        
 
192
 
189
193
    def get_previous_heads(self, inventories):
190
194
        return self.applyDeprecated(zero_ninetyone,
191
195
            self.file_active.find_previous_heads,
192
196
            inventories,
193
197
            self.branch.repository.weave_store,
194
198
            self.branch.repository.get_transaction())
195
 
        
 
199
 
196
200
    def test_fileid_in_no_inventory(self):
197
201
        self.assertEqual({}, self.get_previous_heads([self.inv_A]))
198
202
 
218
222
        self.assertEqual({'D':self.inv_D['fileid']},
219
223
                         self.get_previous_heads([self.inv_D, self.inv_B]))
220
224
 
221
 
    # TODO: test two inventories with the same file revision 
 
225
    # TODO: test two inventories with the same file revision
222
226
 
223
227
 
224
228
class TestInventory(TestCaseWithTree):
227
231
        self.tree = self.get_tree_with_subdirs_and_all_content_types()
228
232
        self.tree.lock_read()
229
233
        self.addCleanup(self.tree.unlock)
230
 
        # Commenting out the following line still fails.
231
 
        self.inv = self.tree.inventory
232
234
 
233
235
    def test_symlink_target(self):
234
236
        self.requireFeature(SymlinkFeature)
235
237
        self._set_up()
236
 
        if isinstance(self.tree, MutableTree):
 
238
        if isinstance(self.tree, (MutableTree, _PreviewTree)):
237
239
            raise TestSkipped(
238
 
                'symlinks not accurately represented in working trees')
239
 
        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'))
240
243
        self.assertEqual(entry.symlink_target, 'link-target')
241
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
 
242
257
    def test_symlink(self):
243
258
        self.requireFeature(SymlinkFeature)
244
259
        self._set_up()
245
 
        entry = self.inv[self.inv.path2id('symlink')]
 
260
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
246
261
        self.assertEqual(entry.kind, 'symlink')
247
262
        self.assertEqual(None, entry.text_size)