/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
1
# Copyright (C) 2007, 2008 Canonical Ltd
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for interface conformance of inventories of trees."""
18
19
20
from cStringIO import StringIO
21
import os
22
23
from bzrlib.diff import internal_diff
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
24
from bzrlib.mutabletree import MutableTree
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
25
from bzrlib.osutils import has_symlinks
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
26
from bzrlib.tests import SymlinkFeature, TestSkipped
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
27
from bzrlib.tests.tree_implementations import TestCaseWithTree
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
28
from bzrlib.transform import _PreviewTree
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
29
from bzrlib.uncommit import uncommit
30
31
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
32
def get_entry(tree, file_id):
33
    return tree.iter_entries_by_dir([file_id]).next()[1]
3363.2.7 by Aaron Bentley
Implement alterntative-to-inventory tests
34
35
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
36
class TestEntryDiffing(TestCaseWithTree):
37
38
    def setUp(self):
39
        super(TestEntryDiffing, self).setUp()
40
        self.wt = self.make_branch_and_tree('.')
41
        self.branch = self.wt.branch
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
42
        open('file', 'wb').write('foo\n')
43
        open('binfile', 'wb').write('foo\n')
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
44
        self.wt.add(['file'], ['fileid'])
45
        self.wt.add(['binfile'], ['binfileid'])
46
        if has_symlinks():
47
            os.symlink('target1', 'symlink')
48
            self.wt.add(['symlink'], ['linkid'])
49
        self.wt.commit('message_1', rev_id = '1')
2911.6.1 by Blake Winton
Change 'print >> f,'s to 'f.write('s.
50
        open('file', 'wb').write('bar\n')
51
        open('binfile', 'wb').write('x' * 1023 + '\x00\n')
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
52
        if has_symlinks():
53
            os.unlink('symlink')
54
            os.symlink('target2', 'symlink')
55
        self.tree_1 = self.branch.repository.revision_tree('1')
56
        self.inv_1 = self.branch.repository.get_inventory('1')
57
        self.file_1 = self.inv_1['fileid']
58
        self.file_1b = self.inv_1['binfileid']
59
        self.tree_2 = self.workingtree_to_test_tree(self.wt)
60
        self.tree_2.lock_read()
61
        self.addCleanup(self.tree_2.unlock)
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
62
        self.file_2 = get_entry(self.tree_2, 'fileid')
63
        self.file_2b = get_entry(self.tree_2, 'binfileid')
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
64
        if has_symlinks():
65
            self.link_1 = self.inv_1['linkid']
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
66
            self.link_2 = get_entry(self.tree_2, 'linkid')
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
67
68
69
class TestPreviousHeads(TestCaseWithTree):
70
71
    def setUp(self):
72
        # we want several inventories, that respectively
73
        # give use the following scenarios:
74
        # A) fileid not in any inventory (A),
75
        # B) fileid present in one inventory (B) and (A,B)
76
        # C) fileid present in two inventories, and they
77
        #   are not mutual descendents (B, C)
78
        # D) fileid present in two inventories and one is
79
        #   a descendent of the other. (B, D)
80
        super(TestPreviousHeads, self).setUp()
81
        self.wt = self.make_branch_and_tree('.')
82
        self.branch = self.wt.branch
83
        self.build_tree(['file'])
84
        self.wt.commit('new branch', allow_pointless=True, rev_id='A')
85
        self.inv_A = self.branch.repository.get_inventory('A')
86
        self.wt.add(['file'], ['fileid'])
87
        self.wt.commit('add file', rev_id='B')
88
        self.inv_B = self.branch.repository.get_inventory('B')
89
        uncommit(self.branch, tree=self.wt)
90
        self.assertEqual(self.branch.revision_history(), ['A'])
91
        self.wt.commit('another add of file', rev_id='C')
92
        self.inv_C = self.branch.repository.get_inventory('C')
93
        self.wt.add_parent_tree_id('B')
94
        self.wt.commit('merge in B', rev_id='D')
95
        self.inv_D = self.branch.repository.get_inventory('D')
96
        self.tree = self.workingtree_to_test_tree(self.wt)
97
        self.tree.lock_read()
98
        self.addCleanup(self.tree.unlock)
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
99
        self.file_active = get_entry(self.tree, 'fileid')
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
100
        self.weave = self.branch.repository.weave_store.get_weave('fileid',
101
            self.branch.repository.get_transaction())
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
102
103
    # TODO: test two inventories with the same file revision
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
104
105
106
class TestInventory(TestCaseWithTree):
107
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
108
    def _set_up(self):
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
109
        self.tree = self.get_tree_with_subdirs_and_all_content_types()
110
        self.tree.lock_read()
111
        self.addCleanup(self.tree.unlock)
112
113
    def test_symlink_target(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
114
        self.requireFeature(SymlinkFeature)
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
115
        self._set_up()
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
116
        if isinstance(self.tree, (MutableTree, _PreviewTree)):
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
117
            raise TestSkipped(
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
118
                'symlinks not accurately represented in working trees and'
119
                ' preview trees')
120
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
121
        self.assertEqual(entry.symlink_target, 'link-target')
122
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
123
    def test_symlink_target_tree(self):
124
        self.requireFeature(SymlinkFeature)
125
        self._set_up()
126
        self.assertEqual('link-target',
127
                         self.tree.get_symlink_target('symlink'))
128
129
    def test_kind_symlink(self):
130
        self.requireFeature(SymlinkFeature)
131
        self._set_up()
132
        self.assertEqual('symlink', self.tree.kind('symlink'))
133
        self.assertIs(None, self.tree.get_file_size('symlink'))
134
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
135
    def test_symlink(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
136
        self.requireFeature(SymlinkFeature)
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
137
        self._set_up()
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
138
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
139
        self.assertEqual(entry.kind, 'symlink')
140
        self.assertEqual(None, entry.text_size)