~bzr-pqm/bzr/bzr.dev

2255.2.134 by John Arbash Meinel
Add a tree-test for get_symlink_target
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2255.2.134 by John Arbash Meinel
Add a tree-test for get_symlink_target
16
17
"""Test that all Tree's implement get_symlink_target"""
18
19
import os
20
21
from bzrlib import (
22
    osutils,
23
    tests,
24
    )
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
25
from bzrlib.tests import per_tree
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
26
from bzrlib.tests import (
27
    features,
28
    )
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
29
30
31
class TestGetSymlinkTarget(per_tree.TestCaseWithTree):
2255.2.134 by John Arbash Meinel
Add a tree-test for get_symlink_target
32
33
    def get_tree_with_symlinks(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
34
        self.requireFeature(features.SymlinkFeature)
2255.2.134 by John Arbash Meinel
Add a tree-test for get_symlink_target
35
        tree = self.make_branch_and_tree('tree')
36
        os.symlink('foo', 'tree/link')
37
        os.symlink('../bar', 'tree/rel_link')
38
        os.symlink('/baz/bing', 'tree/abs_link')
39
3949.6.6 by Jelmer Vernooij
Skip unicode symlink tests on non-unicode file systems.
40
        tree.add(['link', 'rel_link', 'abs_link'],
41
                 ['link-id', 'rel-link-id', 'abs-link-id'])
2255.2.134 by John Arbash Meinel
Add a tree-test for get_symlink_target
42
        return self._convert_tree(tree)
43
44
    def test_get_symlink_target(self):
45
        tree = self.get_tree_with_symlinks()
46
        tree.lock_read()
47
        self.addCleanup(tree.unlock)
48
        self.assertEqual('foo', tree.get_symlink_target('link-id'))
49
        self.assertEqual('../bar', tree.get_symlink_target('rel-link-id'))
50
        self.assertEqual('/baz/bing', tree.get_symlink_target('abs-link-id'))
5858.1.1 by Jelmer Vernooij
Support optional path argument to Tree.get_symlink_target.
51
        self.assertEqual('foo', tree.get_symlink_target('link-id', 'link'))
3949.6.6 by Jelmer Vernooij
Skip unicode symlink tests on non-unicode file systems.
52
53
    def test_get_unicode_symlink_target(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
54
        self.requireFeature(features.SymlinkFeature)
55
        self.requireFeature(features.UnicodeFilenameFeature)
3949.6.6 by Jelmer Vernooij
Skip unicode symlink tests on non-unicode file systems.
56
        tree = self.make_branch_and_tree('tree')
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
57
        target = u'targ\N{Euro Sign}t'
58
        os.symlink(target,  u'tree/\u03b2_link'.encode(osutils._fs_enc))
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
59
        tree.add([u'\u03b2_link'], ['link-id'])
3949.6.6 by Jelmer Vernooij
Skip unicode symlink tests on non-unicode file systems.
60
        tree.lock_read()
61
        self.addCleanup(tree.unlock)
4241.14.12 by Vincent Ladeuil
Far too many modifications for a single commit, need to restart.
62
        actual = tree.get_symlink_target('link-id')
4285.2.1 by Vincent Ladeuil
Cleanup test imports and use features to better track skipped tests.
63
        self.assertEqual(target, actual)
3949.6.1 by Jelmer Vernooij
Support symlinks with non-ascii characters in the symlink filename.
64