/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 TestPreviousHeads(TestCaseWithTree):
37
38
    def setUp(self):
39
        # we want several inventories, that respectively
40
        # give use the following scenarios:
41
        # A) fileid not in any inventory (A),
42
        # B) fileid present in one inventory (B) and (A,B)
43
        # C) fileid present in two inventories, and they
44
        #   are not mutual descendents (B, C)
45
        # D) fileid present in two inventories and one is
46
        #   a descendent of the other. (B, D)
47
        super(TestPreviousHeads, self).setUp()
48
        self.wt = self.make_branch_and_tree('.')
49
        self.branch = self.wt.branch
50
        self.build_tree(['file'])
51
        self.wt.commit('new branch', allow_pointless=True, rev_id='A')
52
        self.inv_A = self.branch.repository.get_inventory('A')
53
        self.wt.add(['file'], ['fileid'])
54
        self.wt.commit('add file', rev_id='B')
55
        self.inv_B = self.branch.repository.get_inventory('B')
56
        uncommit(self.branch, tree=self.wt)
57
        self.assertEqual(self.branch.revision_history(), ['A'])
58
        self.wt.commit('another add of file', rev_id='C')
59
        self.inv_C = self.branch.repository.get_inventory('C')
60
        self.wt.add_parent_tree_id('B')
61
        self.wt.commit('merge in B', rev_id='D')
62
        self.inv_D = self.branch.repository.get_inventory('D')
63
        self.tree = self.workingtree_to_test_tree(self.wt)
64
        self.tree.lock_read()
65
        self.addCleanup(self.tree.unlock)
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
66
        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.
67
        self.weave = self.branch.repository.weave_store.get_weave('fileid',
68
            self.branch.repository.get_transaction())
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
69
70
    # TODO: test two inventories with the same file revision
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
71
72
73
class TestInventory(TestCaseWithTree):
74
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
75
    def _set_up(self):
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
76
        self.tree = self.get_tree_with_subdirs_and_all_content_types()
77
        self.tree.lock_read()
78
        self.addCleanup(self.tree.unlock)
79
80
    def test_symlink_target(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
81
        self.requireFeature(SymlinkFeature)
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
82
        self._set_up()
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
83
        if isinstance(self.tree, (MutableTree, _PreviewTree)):
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
84
            raise TestSkipped(
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
85
                'symlinks not accurately represented in working trees and'
86
                ' preview trees')
87
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
88
        self.assertEqual(entry.symlink_target, 'link-target')
89
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
90
    def test_symlink_target_tree(self):
91
        self.requireFeature(SymlinkFeature)
92
        self._set_up()
93
        self.assertEqual('link-target',
94
                         self.tree.get_symlink_target('symlink'))
95
96
    def test_kind_symlink(self):
97
        self.requireFeature(SymlinkFeature)
98
        self._set_up()
99
        self.assertEqual('symlink', self.tree.kind('symlink'))
100
        self.assertIs(None, self.tree.get_file_size('symlink'))
101
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
102
    def test_symlink(self):
2949.5.1 by Alexander Belchenko
selftest: use SymlinkFeature instead of TestSkipped where appropriate
103
        self.requireFeature(SymlinkFeature)
2408.1.3 by Alexander Belchenko
tree_implementations: make usage of symlinks optional
104
        self._set_up()
3363.3.1 by Aaron Bentley
Combine test_inv_alternatives and test_inv
105
        entry = get_entry(self.tree, self.tree.path2id('symlink'))
2338.4.9 by Marien Zwart
More tests for symlinks in tree inventories.
106
        self.assertEqual(entry.kind, 'symlink')
107
        self.assertEqual(None, entry.text_size)