/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
1
# Copyright (C) 2007 Canonical Ltd
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
3123.1.1 by John Arbash Meinel
Update from deprecating 0.93 to 1.0, and add a 1.1 deprecation.
26
from bzrlib.symbol_versioning import zero_ninetyone, one_zero
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
27
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.
28
from bzrlib.tests.tree_implementations import TestCaseWithTree
29
from bzrlib.uncommit import uncommit
30
31
32
class TestPreviousHeads(TestCaseWithTree):
33
34
    def setUp(self):
35
        # we want several inventories, that respectively
36
        # give use the following scenarios:
37
        # A) fileid not in any inventory (A),
38
        # B) fileid present in one inventory (B) and (A,B)
39
        # C) fileid present in two inventories, and they
40
        #   are not mutual descendents (B, C)
41
        # D) fileid present in two inventories and one is
42
        #   a descendent of the other. (B, D)
43
        super(TestPreviousHeads, self).setUp()
44
        self.wt = self.make_branch_and_tree('.')
45
        self.branch = self.wt.branch
46
        self.build_tree(['file'])
47
        self.wt.commit('new branch', allow_pointless=True, rev_id='A')
48
        self.inv_A = self.branch.repository.get_inventory('A')
49
        self.wt.add(['file'], ['fileid'])
50
        self.wt.commit('add file', rev_id='B')
51
        self.inv_B = self.branch.repository.get_inventory('B')
52
        uncommit(self.branch, tree=self.wt)
53
        self.assertEqual(self.branch.revision_history(), ['A'])
54
        self.wt.commit('another add of file', rev_id='C')
55
        self.inv_C = self.branch.repository.get_inventory('C')
56
        self.wt.add_parent_tree_id('B')
57
        self.wt.commit('merge in B', rev_id='D')
58
        self.inv_D = self.branch.repository.get_inventory('D')
59
        self.tree = self.workingtree_to_test_tree(self.wt)
60
        self.tree.lock_read()
61
        self.addCleanup(self.tree.unlock)
62
        self.file_active = self.tree.inventory['fileid']
63
        self.weave = self.branch.repository.weave_store.get_weave('fileid',
64
            self.branch.repository.get_transaction())
65
        
66
    def get_previous_heads(self, inventories):
2776.3.1 by Robert Collins
* Deprecated method ``find_previous_heads`` on
67
        return self.applyDeprecated(zero_ninetyone,
68
            self.file_active.find_previous_heads,
69
            inventories,
2338.4.6 by Marien Zwart
Move some tests that do not need a working tree from workingtree_implementations to tree_implementations.
70
            self.branch.repository.weave_store,
71
            self.branch.repository.get_transaction())
72
        
73
    def test_fileid_in_no_inventory(self):
74
        self.assertEqual({}, self.get_previous_heads([self.inv_A]))
75
76
    def test_fileid_in_one_inventory(self):
77
        self.assertEqual({'B':self.inv_B['fileid']},
78
                         self.get_previous_heads([self.inv_B]))
79
        self.assertEqual({'B':self.inv_B['fileid']},
80
                         self.get_previous_heads([self.inv_A, self.inv_B]))
81
        self.assertEqual({'B':self.inv_B['fileid']},
82
                         self.get_previous_heads([self.inv_B, self.inv_A]))
83
84
    def test_fileid_in_two_inventories_gives_both_entries(self):
85
        self.assertEqual({'B':self.inv_B['fileid'],
86
                          'C':self.inv_C['fileid']},
87
                          self.get_previous_heads([self.inv_B, self.inv_C]))
88
        self.assertEqual({'B':self.inv_B['fileid'],
89
                          'C':self.inv_C['fileid']},
90
                          self.get_previous_heads([self.inv_C, self.inv_B]))
91
92
    def test_fileid_in_two_inventories_already_merged_gives_head(self):
93
        self.assertEqual({'D':self.inv_D['fileid']},
94
                         self.get_previous_heads([self.inv_B, self.inv_D]))
95
        self.assertEqual({'D':self.inv_D['fileid']},
96
                         self.get_previous_heads([self.inv_D, self.inv_B]))
97
98
    # TODO: test two inventories with the same file revision 
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
99
100
101
class TestInventory(TestCaseWithTree):
102
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
103
    def _set_up(self):
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
104
        self.tree = self.get_tree_with_subdirs_and_all_content_types()
105
        self.tree.lock_read()
106
        self.addCleanup(self.tree.unlock)
107
        # Commenting out the following line still fails.
108
        self.inv = self.tree.inventory
109
110
    def test_symlink_target(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
111
        self.requireFeature(SymlinkFeature)
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
112
        self._set_up()
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
113
        if isinstance(self.tree, MutableTree):
114
            raise TestSkipped(
115
                'symlinks not accurately represented in working trees')
116
        entry = self.inv[self.inv.path2id('symlink')]
117
        self.assertEqual(entry.symlink_target, 'link-target')
118
119
    def test_symlink(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
120
        self.requireFeature(SymlinkFeature)
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
121
        self._set_up()
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
122
        entry = self.inv[self.inv.path2id('symlink')]
123
        self.assertEqual(entry.kind, 'symlink')
124
        self.assertEqual(None, entry.text_size)