5557.1.7
by John Arbash Meinel
Merge in the bzr.dev 5582 |
1 |
# Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011 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
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
1149
by Martin Pool
- make get_parent() be a method of Branch; add simple tests for it |
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') |
5560.2.1
by Vincent Ladeuil
Fix the remaining references to http://bazaar-vcs.org (except the explicitly historical ones). |
43 |
url = 'http://example.com/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: |
|
4288.1.9
by Robert Collins
Fix up test usable of _set_parent_location on unlocked branches. |
74 |
b.lock_write() |
2230.3.8
by Aaron Bentley
Abstract mechanism from policy getting/setting parents |
75 |
b._set_parent_location('/local/abs/path') |
4288.1.9
by Robert Collins
Fix up test usable of _set_parent_location on unlocked branches. |
76 |
b.unlock() |
1711.2.46
by John Arbash Meinel
Allow backwards compatibility with absolute local paths in parent |
77 |
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 |
78 |
|
1864.7.1
by John Arbash Meinel
Let Branch.get_parent() return None if parent is not accessible, (bug #52976) |
79 |
def test_get_invalid_parent(self): |
80 |
b = self.make_branch('.') |
|
81 |
||
82 |
cwd = getcwd() |
|
83 |
n_dirs = len(cwd.split('/')) |
|
84 |
||
85 |
# Force the relative path to be something invalid
|
|
86 |
# This should attempt to go outside the filesystem
|
|
87 |
path = ('../'*(n_dirs+5)) + 'foo' |
|
4288.1.9
by Robert Collins
Fix up test usable of _set_parent_location on unlocked branches. |
88 |
b.lock_write() |
2230.3.8
by Aaron Bentley
Abstract mechanism from policy getting/setting parents |
89 |
b._set_parent_location(path) |
4288.1.9
by Robert Collins
Fix up test usable of _set_parent_location on unlocked branches. |
90 |
b.unlock() |
1864.7.1
by John Arbash Meinel
Let Branch.get_parent() return None if parent is not accessible, (bug #52976) |
91 |
|
92 |
# 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) |
93 |
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) |
94 |
|
3139.2.1
by Alexander Belchenko
bugfix #90847: fix problem with parent location on another logical drive |
95 |
def test_win32_set_parent_on_another_drive(self): |
96 |
if sys.platform != 'win32': |
|
97 |
raise TestSkipped('windows-specific test') |
|
98 |
b = self.make_branch('.') |
|
4789.9.1
by John Arbash Meinel
Simple attribute fix for a win32 test |
99 |
base_url = b.bzrdir.transport.abspath('.') |
3139.2.1
by Alexander Belchenko
bugfix #90847: fix problem with parent location on another logical drive |
100 |
if not base_url.startswith('file:///'): |
101 |
raise TestNotApplicable('this test should be run with local base') |
|
102 |
base = urlutils.local_path_from_url(base_url) |
|
4789.9.1
by John Arbash Meinel
Simple attribute fix for a win32 test |
103 |
other = 'file:///D:/path' |
3139.2.1
by Alexander Belchenko
bugfix #90847: fix problem with parent location on another logical drive |
104 |
if base[0] != 'C': |
105 |
other = 'file:///C:/path' |
|
106 |
b.set_parent(other) |
|
107 |
self.assertEquals(other, b._get_parent_location()) |