20
from bzrlib.branch import Branch
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
27
"""Tests for Branch parent URL"""
30
class TestParent(TestCaseWithTransport):
19
from bzrlib.selftest import TestCaseInTempDir
20
from bzrlib.branch import Branch, copy_branch
24
class TestParent(TestCaseInTempDir):
32
25
def test_no_default_parent(self):
33
26
"""Branches should have no parent by default"""
34
b = self.make_branch('.')
27
b = Branch.initialize('.')
35
28
self.assertEquals(b.get_parent(), None)
37
31
def test_set_get_parent(self):
38
"""Set, re-get and reset the parent"""
39
b = self.make_branch('.')
40
url = 'http://bazaar-vcs.org/bzr/bzr.dev'
32
"""Set and then re-get the parent"""
33
b = Branch.initialize('.')
34
url = 'http://bazaar-ng.org/bzr/bzr.dev'
42
36
self.assertEquals(b.get_parent(), url)
43
self.assertEqual(b.control_files.get('parent').read().strip('\n'), url)
46
self.assertEquals(b.get_parent(), None)
48
b.set_parent('../other_branch')
51
self.assertEquals(b.get_parent(), local_path_to_url('../other_branch'))
52
path = local_path_to_url('../yanb')
54
self.assertEqual(b.control_files.get('parent').read().strip('\n'),
56
self.assertEqual(b.get_parent(), path)
59
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'),
64
self.assertEqual(b.get_parent(), b.base + '%C2%B5')
38
def test_branch_sets_parent(self):
39
"""The branch command should set the new branch's parent"""
40
from bzrlib.commands import run_bzr
43
branch_from = Branch.initialize('from')
44
file('from/foo', 'wt').write('contents of foo')
45
branch_from.add('foo')
46
branch_from.commit('initial commit')
49
copy_branch(branch_from, 'to', None)
51
branch_to = Branch.open('to')
52
abspath = os.path.abspath('from')
53
self.assertEquals(branch_to.get_parent(), abspath)