~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Robert J. Tanner
  • Date: 2009-04-20 08:37:32 UTC
  • mfrom: (4299 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4300.
  • Revision ID: tanner@real-time.com-20090420083732-bzx919oo7wpmqc2u
[merge] 1.14rc2 back into bzr.dev (Bob Tanner)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from cStringIO import StringIO
21
21
import os
22
22
 
23
 
from bzrlib.diff import internal_diff
 
23
from bzrlib import (
 
24
    tests,
 
25
    )
 
26
from bzrlib.tests import tree_implementations
24
27
from bzrlib.mutabletree import MutableTree
25
 
from bzrlib.osutils import has_symlinks
26
28
from bzrlib.tests import SymlinkFeature, TestSkipped
27
 
from bzrlib.tests.tree_implementations import TestCaseWithTree
28
29
from bzrlib.transform import _PreviewTree
29
30
from bzrlib.uncommit import uncommit
30
31
 
33
34
    return tree.iter_entries_by_dir([file_id]).next()[1]
34
35
 
35
36
 
36
 
class TestPreviousHeads(TestCaseWithTree):
 
37
class TestPreviousHeads(tree_implementations.TestCaseWithTree):
37
38
 
38
39
    def setUp(self):
39
40
        # we want several inventories, that respectively
68
69
    # TODO: test two inventories with the same file revision
69
70
 
70
71
 
71
 
class TestInventory(TestCaseWithTree):
72
 
 
73
 
    def _set_up(self):
 
72
class TestInventoryWithSymlinks(tree_implementations.TestCaseWithTree):
 
73
 
 
74
    _test_needs_features = [tests.SymlinkFeature]
 
75
 
 
76
    def setUp(self):
 
77
        tree_implementations.TestCaseWithTree.setUp(self)
74
78
        self.tree = self.get_tree_with_subdirs_and_all_content_types()
75
79
        self.tree.lock_read()
76
80
        self.addCleanup(self.tree.unlock)
77
81
 
78
82
    def test_symlink_target(self):
79
 
        self.requireFeature(SymlinkFeature)
80
 
        self._set_up()
81
83
        if isinstance(self.tree, (MutableTree, _PreviewTree)):
82
84
            raise TestSkipped(
83
85
                'symlinks not accurately represented in working trees and'
86
88
        self.assertEqual(entry.symlink_target, 'link-target')
87
89
 
88
90
    def test_symlink_target_tree(self):
89
 
        self.requireFeature(SymlinkFeature)
90
 
        self._set_up()
91
91
        self.assertEqual('link-target',
92
92
                         self.tree.get_symlink_target('symlink'))
93
93
 
94
94
    def test_kind_symlink(self):
95
 
        self.requireFeature(SymlinkFeature)
96
 
        self._set_up()
97
95
        self.assertEqual('symlink', self.tree.kind('symlink'))
98
96
        self.assertIs(None, self.tree.get_file_size('symlink'))
99
97
 
100
98
    def test_symlink(self):
101
 
        self.requireFeature(SymlinkFeature)
102
 
        self._set_up()
103
99
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
104
100
        self.assertEqual(entry.kind, 'symlink')
105
101
        self.assertEqual(None, entry.text_size)
106
102
 
 
103
 
 
104
class TestInventory(tree_implementations.TestCaseWithTree):
 
105
 
107
106
    def test_paths2ids_recursive(self):
108
107
        work_tree = self.make_branch_and_tree('tree')
109
108
        self.build_tree(['tree/dir/', 'tree/dir/file'])
136
135
 
137
136
    def test_canonical_path(self):
138
137
        work_tree = self._make_canonical_test_tree()
139
 
        self.assertEqual(work_tree.get_canonical_inventory_path('Dir/File'), 'dir/file')
 
138
        self.assertEqual('dir/file',
 
139
                         work_tree.get_canonical_inventory_path('Dir/File'))
140
140
 
141
141
    def test_canonical_path_before_commit(self):
142
142
        work_tree = self._make_canonical_test_tree(False)
143
143
        # note: not committed.
144
 
        self.assertEqual(work_tree.get_canonical_inventory_path('Dir/File'), 'dir/file')
 
144
        self.assertEqual('dir/file',
 
145
                         work_tree.get_canonical_inventory_path('Dir/File'))
145
146
 
146
147
    def test_canonical_path_dir(self):
147
148
        # check it works when asked for just the directory portion.
148
149
        work_tree = self._make_canonical_test_tree()
149
 
        self.assertEqual(work_tree.get_canonical_inventory_path('Dir'), 'dir')
 
150
        self.assertEqual('dir', work_tree.get_canonical_inventory_path('Dir'))
150
151
 
151
152
    def test_canonical_path_root(self):
152
153
        work_tree = self._make_canonical_test_tree()
153
 
        self.assertEqual(work_tree.get_canonical_inventory_path(''), '')
154
 
        self.assertEqual(work_tree.get_canonical_inventory_path('/'), '/')
 
154
        self.assertEqual('', work_tree.get_canonical_inventory_path(''))
 
155
        self.assertEqual('/', work_tree.get_canonical_inventory_path('/'))
155
156
 
156
157
    def test_canonical_path_invalid_all(self):
157
158
        work_tree = self._make_canonical_test_tree()
158
 
        self.assertEqual(work_tree.get_canonical_inventory_path('foo/bar'), 'foo/bar')
 
159
        self.assertEqual('foo/bar',
 
160
                         work_tree.get_canonical_inventory_path('foo/bar'))
159
161
 
160
162
    def test_canonical_invalid_child(self):
161
163
        work_tree = self._make_canonical_test_tree()
162
 
        self.assertEqual(work_tree.get_canonical_inventory_path('Dir/None'), 'dir/None')
 
164
        self.assertEqual('dir/None',
 
165
                         work_tree.get_canonical_inventory_path('Dir/None'))