/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006 by Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
2
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
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
18
 
import cStringIO
19
 
import os
20
18
import sys
21
19
 
22
 
from bzrlib.branch import Branch
23
20
import bzrlib.errors
24
 
from bzrlib.osutils import abspath, realpath, getcwd
25
 
from bzrlib.urlutils import local_path_from_url, local_path_to_url, escape
 
21
from bzrlib.osutils import getcwd
26
22
from bzrlib.tests import TestCaseWithTransport
 
23
from bzrlib import urlutils
27
24
 
28
25
 
29
26
"""Tests for Branch parent URL"""
38
35
        
39
36
    def test_set_get_parent(self):
40
37
        """Set, re-get and reset the parent"""
41
 
        b = self.make_branch('.')
 
38
        b = self.make_branch('subdir')
42
39
        url = 'http://bazaar-vcs.org/bzr/bzr.dev'
43
40
        b.set_parent(url)
44
41
        self.assertEqual(url, b.get_parent())
45
 
        self.assertEqual(url, b.control_files.get('parent').read().strip('\n'))
 
42
        self.assertEqual(url, b._get_parent_location())
46
43
 
47
44
        b.set_parent(None)
48
45
        self.assertEqual(None, b.get_parent())
49
46
 
50
47
        b.set_parent('../other_branch')
51
48
 
52
 
        self.assertEqual(local_path_to_url('../other_branch'), b.get_parent())
53
 
        path = local_path_to_url('../yanb')
 
49
        expected_parent = urlutils.join(self.get_url('subdir'),
 
50
                                        '../other_branch')
 
51
        self.assertEqual(expected_parent, b.get_parent())
 
52
        path = urlutils.join(self.get_url('subdir'), '../yanb')
54
53
        b.set_parent(path)
55
 
        self.assertEqual('../yanb',
56
 
            b.control_files.get('parent').read().strip('\n'))
 
54
        self.assertEqual('../yanb', b._get_parent_location())
57
55
        self.assertEqual(path, b.get_parent())
58
56
 
59
57
 
60
58
        self.assertRaises(bzrlib.errors.InvalidURL, b.set_parent, u'\xb5')
61
 
        b.set_parent(escape(u'\xb5'))
62
 
        self.assertEqual('%C2%B5',
63
 
            b.control_files.get('parent').read().strip('\n'))
 
59
        b.set_parent(urlutils.escape(u'\xb5'))
 
60
        self.assertEqual('%C2%B5', b._get_parent_location())
64
61
 
65
62
        self.assertEqual(b.base + '%C2%B5', b.get_parent())
66
63
 
70
67
            #       paths as well? Nobody has complained about it.
71
68
            pass
72
69
        else:
73
 
            b.control_files.put('parent', cStringIO.StringIO('/local/abs/path'))
 
70
            b._set_parent_location('/local/abs/path')
74
71
            self.assertEqual('file:///local/abs/path', b.get_parent())
75
72
 
76
73
    def test_get_invalid_parent(self):
82
79
        # Force the relative path to be something invalid
83
80
        # This should attempt to go outside the filesystem
84
81
        path = ('../'*(n_dirs+5)) + 'foo'
85
 
        b.control_files.put('parent', cStringIO.StringIO(path))
 
82
        b._set_parent_location(path)
86
83
 
87
84
        # With an invalid branch parent, just return None
88
85
        self.assertRaises(bzrlib.errors.InaccessibleParent, b.get_parent)