/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1149 by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it
1
# Copyright (C) 2004, 2005 by 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
1152 by Martin Pool
- add test that branching sets the parent of the new branch
18
import os
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
19
1185.65.17 by Robert Collins
Merge from integration, mode-changes are broken.
20
from bzrlib.branch import Branch
1685.1.70 by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken
21
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
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
24
from bzrlib.tests import TestCaseWithTransport
1149 by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it
25
26
1211 by Martin Pool
doc
27
"""Tests for Branch parent URL"""
28
1149 by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it
29
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
30
class TestParent(TestCaseWithTransport):
1185.65.17 by Robert Collins
Merge from integration, mode-changes are broken.
31
1149 by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it
32
    def test_no_default_parent(self):
33
        """Branches should have no parent by default"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
34
        b = self.make_branch('.')
1149 by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it
35
        self.assertEquals(b.get_parent(), None)
36
        
37
    def test_set_get_parent(self):
1614.2.14 by Olaf Conradi
Add test case for resetting parent in branch_implementations.
38
        """Set, re-get and reset the parent"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
39
        b = self.make_branch('.')
1185.50.94 by John Arbash Meinel
Updated web page url to http://bazaar-vcs.org
40
        url = 'http://bazaar-vcs.org/bzr/bzr.dev'
1150 by Martin Pool
- add new Branch.set_parent and tests
41
        b.set_parent(url)
42
        self.assertEquals(b.get_parent(), url)
1685.1.70 by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken
43
        self.assertEqual(b.control_files.get('parent').read().strip('\n'), url)
44
1614.2.14 by Olaf Conradi
Add test case for resetting parent in branch_implementations.
45
        b.set_parent(None)
46
        self.assertEquals(b.get_parent(), None)
1685.1.70 by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken
47
48
        b.set_parent('../other_branch')
49
        cwd = getcwd()
50
51
        self.assertEquals(b.get_parent(), local_path_to_url('../other_branch'))
52
        path = local_path_to_url('../yanb')
53
        b.set_parent(path)
1685.1.71 by Wouter van Heyst
change branch.{get,set}_parent to store a relative path but return full urls
54
        self.assertEqual(b.control_files.get('parent').read().strip('\n'), 
55
            '../yanb')
1685.1.70 by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken
56
        self.assertEqual(b.get_parent(), path)
57
58
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'), 
62
            '%C2%B5')
63
64
        self.assertEqual(b.get_parent(), b.base + '%C2%B5')
65