~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/per_workingtree/test_symlinks.py

  • Committer: Martin Pool
  • Date: 2010-07-21 09:58:42 UTC
  • mfrom: (4797.58.7 2.1)
  • mto: (5050.3.13 2.2)
  • mto: This revision was merged to the branch mainline in revision 5365.
  • Revision ID: mbp@canonical.com-20100721095842-hz0obu8gl0x05nty
merge up 2.1 to 2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 (
 
23
    builtins,
 
24
    tests,
 
25
    workingtree,
 
26
    )
 
27
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree
 
28
 
 
29
 
 
30
class TestSmartAddTree(TestCaseWithWorkingTree):
 
31
 
 
32
    _test_needs_features = [tests.SymlinkFeature]
 
33
 
 
34
    def test_smart_add_symlink(self):
 
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')))
 
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')))
 
55
 
 
56
    def test_open_containing_through_symlink(self):
 
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
 
 
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):
 
85
        tree, relpaths = builtins.tree_files(to_open)
 
86
        self.assertEndsWith(tree.basedir, expected_tree)
 
87
        self.assertEquals(expect_paths, relpaths)
 
88
 
 
89
    def make_test_tree(self):
 
90
        tree = self.make_branch_and_tree('tree')
 
91
        self.build_tree_contents([
 
92
            ('link@', 'tree'),
 
93
            ('tree/outerlink@', '/not/there'),
 
94
            ('tree/content', 'hello'),
 
95
            ('tree/sublink@', 'subdir'),
 
96
            ('tree/subdir/',),
 
97
            ('tree/subdir/subcontent', 'subcontent stuff')
 
98
            ])