~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_parent.py

  • Committer: Robert Collins
  • Date: 2008-08-20 02:07:36 UTC
  • mfrom: (3640 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3682.
  • Revision ID: robertc@robertcollins.net-20080820020736-g2xe4921zzxtymle
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005 by Canonical Ltd
2
 
 
 
1
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
 
import os
 
18
import sys
19
19
 
20
 
from bzrlib.branch import Branch
21
20
import bzrlib.errors
22
 
from bzrlib.osutils import abspath, realpath, getcwd
23
 
from bzrlib.urlutils import local_path_from_url, local_path_to_url, escape
24
 
from bzrlib.tests import TestCaseWithTransport
 
21
from bzrlib.osutils import getcwd
 
22
from bzrlib.tests import (
 
23
    TestCaseWithTransport,
 
24
    TestNotApplicable,
 
25
    TestSkipped,
 
26
    )
 
27
from bzrlib import urlutils
25
28
 
26
29
 
27
30
"""Tests for Branch parent URL"""
32
35
    def test_no_default_parent(self):
33
36
        """Branches should have no parent by default"""
34
37
        b = self.make_branch('.')
35
 
        self.assertEquals(b.get_parent(), None)
 
38
        self.assertEqual(None, b.get_parent())
36
39
        
37
40
    def test_set_get_parent(self):
38
41
        """Set, re-get and reset the parent"""
39
 
        b = self.make_branch('.')
 
42
        b = self.make_branch('subdir')
40
43
        url = 'http://bazaar-vcs.org/bzr/bzr.dev'
41
44
        b.set_parent(url)
42
 
        self.assertEquals(b.get_parent(), url)
43
 
        self.assertEqual(b.control_files.get('parent').read().strip('\n'), url)
 
45
        self.assertEqual(url, b.get_parent())
 
46
        self.assertEqual(url, b._get_parent_location())
44
47
 
45
48
        b.set_parent(None)
46
 
        self.assertEquals(b.get_parent(), None)
 
49
        self.assertEqual(None, b.get_parent())
47
50
 
48
51
        b.set_parent('../other_branch')
49
 
        cwd = getcwd()
50
52
 
51
 
        self.assertEquals(b.get_parent(), local_path_to_url('../other_branch'))
52
 
        path = local_path_to_url('../yanb')
 
53
        expected_parent = urlutils.join(self.get_url('subdir'),
 
54
                                        '../other_branch')
 
55
        self.assertEqual(expected_parent, b.get_parent())
 
56
        path = urlutils.join(self.get_url('subdir'), '../yanb')
53
57
        b.set_parent(path)
54
 
        self.assertEqual(b.control_files.get('parent').read().strip('\n'), 
55
 
            '../yanb')
56
 
        self.assertEqual(b.get_parent(), path)
 
58
        self.assertEqual('../yanb', b._get_parent_location())
 
59
        self.assertEqual(path, b.get_parent())
57
60
 
58
61
 
59
62
        self.assertRaises(bzrlib.errors.InvalidURL, b.set_parent, u'\xb5')
60
 
        b.set_parent(escape(u'\xb5'))
61
 
        self.assertEqual(b.control_files.get('parent').read().strip('\n'), 
62
 
            '%C2%B5')
63
 
 
64
 
        self.assertEqual(b.get_parent(), b.base + '%C2%B5')
65
 
 
 
63
        b.set_parent(urlutils.escape(u'\xb5'))
 
64
        self.assertEqual('%C2%B5', b._get_parent_location())
 
65
 
 
66
        self.assertEqual(b.base + '%C2%B5', b.get_parent())
 
67
 
 
68
        # Handle the case for older style absolute local paths
 
69
        if sys.platform == 'win32':
 
70
            # TODO: jam 20060515 Do we want to special case Windows local
 
71
            #       paths as well? Nobody has complained about it.
 
72
            pass
 
73
        else:
 
74
            b._set_parent_location('/local/abs/path')
 
75
            self.assertEqual('file:///local/abs/path', b.get_parent())
 
76
 
 
77
    def test_get_invalid_parent(self):
 
78
        b = self.make_branch('.')
 
79
 
 
80
        cwd = getcwd()
 
81
        n_dirs = len(cwd.split('/'))
 
82
 
 
83
        # Force the relative path to be something invalid
 
84
        # This should attempt to go outside the filesystem
 
85
        path = ('../'*(n_dirs+5)) + 'foo'
 
86
        b._set_parent_location(path)
 
87
 
 
88
        # With an invalid branch parent, just return None
 
89
        self.assertRaises(bzrlib.errors.InaccessibleParent, b.get_parent)
 
90
 
 
91
    def test_win32_set_parent_on_another_drive(self):
 
92
        if sys.platform != 'win32':
 
93
            raise TestSkipped('windows-specific test')
 
94
        b = self.make_branch('.')
 
95
        base_url = b.abspath('.')
 
96
        if not base_url.startswith('file:///'):
 
97
            raise TestNotApplicable('this test should be run with local base')
 
98
        base = urlutils.local_path_from_url(base_url)
 
99
        other = 'file:///B:/path'
 
100
        if base[0] != 'C':
 
101
            other = 'file:///C:/path'
 
102
        b.set_parent(other)
 
103
        self.assertEquals(other, b._get_parent_location())