2052.3.2
by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical |
1 |
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
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.
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
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 |
||
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
18 |
import sys |
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
19 |
|
1685.1.70
by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken |
20 |
import bzrlib.errors |
2018.5.167
by Andrew Bennetts
Various changes in response to John's review. |
21 |
from bzrlib.osutils import getcwd |
3139.2.1
by Alexander Belchenko
bugfix #90847: fix problem with parent location on another logical drive |
22 |
from bzrlib.tests import ( |
23 |
TestCaseWithTransport, |
|
24 |
TestNotApplicable, |
|
25 |
TestSkipped, |
|
26 |
)
|
|
2414.2.1
by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch. |
27 |
from bzrlib import urlutils |
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
28 |
|
29 |
||
1211
by Martin Pool
doc |
30 |
"""Tests for Branch parent URL"""
|
31 |
||
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
32 |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
33 |
class TestParent(TestCaseWithTransport): |
1185.65.17
by Robert Collins
Merge from integration, mode-changes are broken. |
34 |
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
35 |
def test_no_default_parent(self): |
36 |
"""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. |
37 |
b = self.make_branch('.') |
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
38 |
self.assertEqual(None, b.get_parent()) |
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
39 |
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
40 |
def test_set_get_parent(self): |
1614.2.14
by Olaf Conradi
Add test case for resetting parent in branch_implementations. |
41 |
"""Set, re-get and reset the parent"""
|
2414.2.1
by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch. |
42 |
b = self.make_branch('subdir') |
1185.50.94
by John Arbash Meinel
Updated web page url to http://bazaar-vcs.org |
43 |
url = 'http://bazaar-vcs.org/bzr/bzr.dev' |
1150
by Martin Pool
- add new Branch.set_parent and tests |
44 |
b.set_parent(url) |
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
45 |
self.assertEqual(url, b.get_parent()) |
2230.3.8
by Aaron Bentley
Abstract mechanism from policy getting/setting parents |
46 |
self.assertEqual(url, b._get_parent_location()) |
1685.1.70
by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken |
47 |
|
1614.2.14
by Olaf Conradi
Add test case for resetting parent in branch_implementations. |
48 |
b.set_parent(None) |
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
49 |
self.assertEqual(None, b.get_parent()) |
1685.1.70
by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken |
50 |
|
51 |
b.set_parent('../other_branch') |
|
52 |
||
2414.2.1
by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch. |
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') |
|
1685.1.70
by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken |
57 |
b.set_parent(path) |
2230.3.8
by Aaron Bentley
Abstract mechanism from policy getting/setting parents |
58 |
self.assertEqual('../yanb', b._get_parent_location()) |
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
59 |
self.assertEqual(path, b.get_parent()) |
1685.1.70
by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken |
60 |
|
61 |
||
62 |
self.assertRaises(bzrlib.errors.InvalidURL, b.set_parent, u'\xb5') |
|
2414.2.1
by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch. |
63 |
b.set_parent(urlutils.escape(u'\xb5')) |
2230.3.8
by Aaron Bentley
Abstract mechanism from policy getting/setting parents |
64 |
self.assertEqual('%C2%B5', b._get_parent_location()) |
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
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: |
|
2230.3.8
by Aaron Bentley
Abstract mechanism from policy getting/setting parents |
74 |
b._set_parent_location('/local/abs/path') |
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
75 |
self.assertEqual('file:///local/abs/path', b.get_parent()) |
1685.1.70
by Wouter van Heyst
working on get_parent, set_parent and relative urls, broken |
76 |
|
1864.7.1
by John Arbash Meinel
Let Branch.get_parent() return None if parent is not accessible, (bug #52976) |
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' |
|
2230.3.8
by Aaron Bentley
Abstract mechanism from policy getting/setting parents |
86 |
b._set_parent_location(path) |
1864.7.1
by John Arbash Meinel
Let Branch.get_parent() return None if parent is not accessible, (bug #52976) |
87 |
|
88 |
# With an invalid branch parent, just return None
|
|
1864.7.2
by John Arbash Meinel
Test that we copy the parent across properly (if it is available) |
89 |
self.assertRaises(bzrlib.errors.InaccessibleParent, b.get_parent) |
1864.7.1
by John Arbash Meinel
Let Branch.get_parent() return None if parent is not accessible, (bug #52976) |
90 |
|
3139.2.1
by Alexander Belchenko
bugfix #90847: fix problem with parent location on another logical drive |
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()) |