/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4634.157.4 by Martin Pool
Add a basic (already passing) test for smart_add of a symlink
1
# Copyright (C) 2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""Test symlink support.
18
19
See eg <https://bugs.launchpad.net/bzr/+bug/192859>
20
"""
21
22
from bzrlib import (
4634.157.8 by Martin Pool
tree_files shouldn't dereference the first argument
23
    builtins,
4634.157.4 by Martin Pool
Add a basic (already passing) test for smart_add of a symlink
24
    tests,
4634.157.6 by Martin Pool
Add test for opening a branch through a symlink
25
    workingtree,
4634.157.4 by Martin Pool
Add a basic (already passing) test for smart_add of a symlink
26
    )
27
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
28
29
30
class TestSmartAddTree(TestCaseWithWorkingTree):
31
32
    _test_needs_features = [tests.SymlinkFeature]
33
4634.157.5 by Martin Pool
One more symlink add test
34
    def test_smart_add_symlink(self):
4634.157.4 by Martin Pool
Add a basic (already passing) test for smart_add of a symlink
35
        tree = self.make_branch_and_tree('tree')
36
        self.build_tree_contents([
37
            ('tree/link@', 'target'),
38
            ])
39
        tree.smart_add(['tree/link'])
40
        self.assertIsNot(None, tree.path2id('link'))
41
        self.assertIs(None, tree.path2id('target'))
42
        self.assertEqual('symlink',
43
            tree.kind(tree.path2id('link')))
4634.157.5 by Martin Pool
One more symlink add test
44
45
    def test_smart_add_symlink_pointing_outside(self):
46
        tree = self.make_branch_and_tree('tree')
47
        self.build_tree_contents([
48
            ('tree/link@', '../../../../target'),
49
            ])
50
        tree.smart_add(['tree/link'])
51
        self.assertIsNot(None, tree.path2id('link'))
52
        self.assertIs(None, tree.path2id('target'))
53
        self.assertEqual('symlink',
54
            tree.kind(tree.path2id('link')))
4634.157.6 by Martin Pool
Add test for opening a branch through a symlink
55
56
    def test_open_containing_through_symlink(self):
4634.157.7 by Martin Pool
Further open_containing tests
57
        self.make_test_tree()
58
        self.check_open_containing('link/content', 'tree', 'content')
59
        self.check_open_containing('link/sublink', 'tree', 'sublink')
60
        # this next one is a bit debatable, but arguably it's better that
61
        # open_containing is only concerned with opening the tree 
62
        # and then you can deal with symlinks along the way if you want
63
        self.check_open_containing('link/sublink/subcontent', 'tree',
64
            'sublink/subcontent')
65
66
    def check_open_containing(self, to_open, expected_tree_name,
67
        expected_relpath):
68
        wt, relpath = workingtree.WorkingTree.open_containing(to_open)
69
        self.assertEquals(relpath, expected_relpath)
70
        self.assertEndsWith(wt.basedir, expected_tree_name)
71
4634.157.8 by Martin Pool
tree_files shouldn't dereference the first argument
72
    def test_tree_files(self):
73
        # not strictly a WorkingTree method, but it should be
74
        # probably the root cause for
75
        # <https://bugs.launchpad.net/bzr/+bug/128562>
76
        self.make_test_tree()
77
        self.check_tree_files(['tree/outerlink'],
78
            'tree', ['outerlink'])
79
        self.check_tree_files(['link/outerlink'],
80
            'tree', ['outerlink'])
81
        self.check_tree_files(['link/sublink/subcontent'],
82
            'tree', ['subdir/subcontent'])
83
84
    def check_tree_files(self, to_open, expected_tree, expect_paths):
5346.4.5 by Martin Pool
Deprecate and avoid internal_tree_files and tree_files.
85
        tree, relpaths = workingtree.WorkingTree.open_containing_paths(to_open)
4634.157.8 by Martin Pool
tree_files shouldn't dereference the first argument
86
        self.assertEndsWith(tree.basedir, expected_tree)
87
        self.assertEquals(expect_paths, relpaths)
88
4634.157.7 by Martin Pool
Further open_containing tests
89
    def make_test_tree(self):
4634.157.6 by Martin Pool
Add test for opening a branch through a symlink
90
        tree = self.make_branch_and_tree('tree')
91
        self.build_tree_contents([
92
            ('link@', 'tree'),
4634.157.8 by Martin Pool
tree_files shouldn't dereference the first argument
93
            ('tree/outerlink@', '/not/there'),
4634.157.6 by Martin Pool
Add test for opening a branch through a symlink
94
            ('tree/content', 'hello'),
4634.157.7 by Martin Pool
Further open_containing tests
95
            ('tree/sublink@', 'subdir'),
96
            ('tree/subdir/',),
97
            ('tree/subdir/subcontent', 'subcontent stuff')
4634.157.6 by Martin Pool
Add test for opening a branch through a symlink
98
            ])