bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
1 |
# Copyright (C) 2010, 2011, 2016 Canonical Ltd
|
|
4634.157.4
by Martin Pool
Add a basic (already passing) test for smart_add of a symlink |
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
16 |
||
17 |
"""Test symlink support.
|
|
18 |
"""
|
|
19 |
||
|
4634.159.2
by Martin Pool
Add reproduction for bug 192859 |
20 |
import os |
21 |
||
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
22 |
from breezy import ( |
|
4634.160.2
by Martin Pool
Add test (already passing) for symlink changing to dir |
23 |
osutils, |
|
4634.157.4
by Martin Pool
Add a basic (already passing) test for smart_add of a symlink |
24 |
tests, |
|
4634.157.6
by Martin Pool
Add test for opening a branch through a symlink |
25 |
workingtree, |
|
4634.157.4
by Martin Pool
Add a basic (already passing) test for smart_add of a symlink |
26 |
)
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
27 |
from breezy.tests.per_workingtree import TestCaseWithWorkingTree |
28 |
from breezy.tests import ( |
|
|
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
29 |
features, |
30 |
)
|
|
|
4634.157.4
by Martin Pool
Add a basic (already passing) test for smart_add of a symlink |
31 |
|
32 |
||
33 |
class TestSmartAddTree(TestCaseWithWorkingTree): |
|
34 |
||
|
4634.159.1
by Martin Pool
Move tests into a class that describes their function |
35 |
# See eg <https://bugs.launchpad.net/bzr/+bug/192859>
|
36 |
||
|
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
37 |
_test_needs_features = [features.SymlinkFeature] |
|
4634.157.4
by Martin Pool
Add a basic (already passing) test for smart_add of a symlink |
38 |
|
|
4634.157.5
by Martin Pool
One more symlink add test |
39 |
def test_smart_add_symlink(self): |
|
4634.157.4
by Martin Pool
Add a basic (already passing) test for smart_add of a symlink |
40 |
tree = self.make_branch_and_tree('tree') |
41 |
self.build_tree_contents([ |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
42 |
('tree/link@', b'target'), |
|
4634.157.4
by Martin Pool
Add a basic (already passing) test for smart_add of a symlink |
43 |
])
|
44 |
tree.smart_add(['tree/link']) |
|
|
6852.3.1
by Jelmer Vernooij
add Tree.is_versioned. |
45 |
self.assertTrue(tree.is_versioned('link')) |
46 |
self.assertFalse(tree.is_versioned('target')) |
|
|
6809.4.7
by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind. |
47 |
self.assertEqual('symlink', tree.kind('link')) |
|
4634.157.5
by Martin Pool
One more symlink add test |
48 |
|
49 |
def test_smart_add_symlink_pointing_outside(self): |
|
50 |
tree = self.make_branch_and_tree('tree') |
|
51 |
self.build_tree_contents([ |
|
52 |
('tree/link@', '../../../../target'), |
|
53 |
])
|
|
54 |
tree.smart_add(['tree/link']) |
|
|
6852.3.1
by Jelmer Vernooij
add Tree.is_versioned. |
55 |
self.assertTrue(tree.is_versioned('link')) |
56 |
self.assertFalse(tree.is_versioned('target')) |
|
|
6809.4.7
by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind. |
57 |
self.assertEqual('symlink', tree.kind('link')) |
|
4634.157.6
by Martin Pool
Add test for opening a branch through a symlink |
58 |
|
|
4634.159.8
by Martin Pool
Handle adding a file under a symlink whose real parent is not yet versioned |
59 |
def test_add_file_under_symlink(self): |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
60 |
# similar to
|
|
4634.159.8
by Martin Pool
Handle adding a file under a symlink whose real parent is not yet versioned |
61 |
# https://bugs.launchpad.net/bzr/+bug/192859/comments/3
|
62 |
tree = self.make_branch_and_tree('tree') |
|
63 |
self.build_tree_contents([ |
|
64 |
('tree/link@', 'dir'), |
|
65 |
('tree/dir/',), |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
66 |
('tree/dir/file', b'content'), |
|
4634.159.8
by Martin Pool
Handle adding a file under a symlink whose real parent is not yet versioned |
67 |
])
|
|
6861.5.2
by Jelmer Vernooij
Fix some more foreign branch tests. |
68 |
if tree.has_versioned_directories(): |
69 |
self.assertEqual( |
|
70 |
tree.smart_add(['tree/link/file']), |
|
71 |
([u'dir', u'dir/file'], {})) |
|
72 |
else: |
|
73 |
self.assertEqual( |
|
74 |
tree.smart_add(['tree/link/file']), |
|
75 |
([u'dir/file'], {})) |
|
76 |
||
|
4634.159.8
by Martin Pool
Handle adding a file under a symlink whose real parent is not yet versioned |
77 |
# should add the actual parent directory, not the apparent parent
|
78 |
# (which is actually a symlink)
|
|
|
6852.3.1
by Jelmer Vernooij
add Tree.is_versioned. |
79 |
self.assertTrue(tree.is_versioned('dir/file')) |
80 |
self.assertTrue(tree.is_versioned('dir')) |
|
81 |
self.assertFalse(tree.is_versioned('link')) |
|
82 |
self.assertFalse(tree.is_versioned('link/file')) |
|
|
4634.159.8
by Martin Pool
Handle adding a file under a symlink whose real parent is not yet versioned |
83 |
|
|
4634.159.1
by Martin Pool
Move tests into a class that describes their function |
84 |
|
|
4634.159.2
by Martin Pool
Add reproduction for bug 192859 |
85 |
class TestKindChanges(TestCaseWithWorkingTree): |
86 |
||
|
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
87 |
_test_needs_features = [features.SymlinkFeature] |
|
4634.159.7
by Martin Pool
Add symlink test dependency |
88 |
|
|
4634.160.1
by Martin Pool
The test now actually passes on all wt formats |
89 |
def test_symlink_changes_to_dir(self): |
|
4634.159.4
by Martin Pool
comment |
90 |
# <https://bugs.launchpad.net/bzr/+bug/192859>:
|
91 |
# we had some past problems with the workingtree remembering for too
|
|
92 |
# long what kind of object was at a particular name; we really
|
|
93 |
# shouldn't do that. Operating on the dirstate through passing
|
|
94 |
# inventory deltas rather than mutating the inventory largely avoids
|
|
95 |
# that.
|
|
|
4634.159.2
by Martin Pool
Add reproduction for bug 192859 |
96 |
tree = self.make_branch_and_tree('tree') |
97 |
self.build_tree_contents([ |
|
98 |
('tree/a@', 'target')]) |
|
99 |
tree.smart_add(['tree/a']) |
|
100 |
tree.commit('add symlink') |
|
101 |
os.unlink('tree/a') |
|
102 |
self.build_tree_contents([ |
|
103 |
('tree/a/',), |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
104 |
('tree/a/f', b'content'), |
|
4634.159.2
by Martin Pool
Add reproduction for bug 192859 |
105 |
])
|
|
4634.159.3
by Martin Pool
Better, now failing, test for symlink kind changes |
106 |
tree.smart_add(['tree/a/f']) |
|
4634.159.2
by Martin Pool
Add reproduction for bug 192859 |
107 |
tree.commit('change to dir') |
|
4634.160.3
by Martin Pool
Check tree after commit of kind change |
108 |
tree.lock_read() |
109 |
self.addCleanup(tree.unlock) |
|
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
110 |
self.assertEqual([], list(tree.iter_changes(tree.basis_tree()))) |
|
6861.1.1
by Jelmer Vernooij
More foreign branch test fixes. |
111 |
self.assertEqual( |
112 |
['a', 'a/f'], sorted(info[0] for info in tree.list_files())) |
|
|
4634.159.2
by Martin Pool
Add reproduction for bug 192859 |
113 |
|
|
4634.160.2
by Martin Pool
Add test (already passing) for symlink changing to dir |
114 |
def test_dir_changes_to_symlink(self): |
115 |
# <https://bugs.launchpad.net/bzr/+bug/192859>:
|
|
116 |
# we had some past problems with the workingtree remembering for too
|
|
117 |
# long what kind of object was at a particular name; we really
|
|
118 |
# shouldn't do that. Operating on the dirstate through passing
|
|
119 |
# inventory deltas rather than mutating the inventory largely avoids
|
|
120 |
# that.
|
|
121 |
tree = self.make_branch_and_tree('tree') |
|
122 |
self.build_tree_contents([ |
|
123 |
('tree/a/',), |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
124 |
('tree/a/file', b'content'), |
|
4634.160.2
by Martin Pool
Add test (already passing) for symlink changing to dir |
125 |
])
|
126 |
tree.smart_add(['tree/a']) |
|
127 |
tree.commit('add dir') |
|
128 |
osutils.rmtree('tree/a') |
|
129 |
self.build_tree_contents([ |
|
130 |
('tree/a@', 'target'), |
|
131 |
])
|
|
132 |
tree.commit('change to symlink') |
|
133 |
||
|
4634.159.2
by Martin Pool
Add reproduction for bug 192859 |
134 |
|
|
4634.159.1
by Martin Pool
Move tests into a class that describes their function |
135 |
class TestOpenTree(TestCaseWithWorkingTree): |
136 |
||
|
5967.12.1
by Martin Pool
Move all test features into bzrlib.tests.features |
137 |
_test_needs_features = [features.SymlinkFeature] |
|
4634.159.1
by Martin Pool
Move tests into a class that describes their function |
138 |
|
|
4634.157.6
by Martin Pool
Add test for opening a branch through a symlink |
139 |
def test_open_containing_through_symlink(self): |
|
4634.157.7
by Martin Pool
Further open_containing tests |
140 |
self.make_test_tree() |
141 |
self.check_open_containing('link/content', 'tree', 'content') |
|
142 |
self.check_open_containing('link/sublink', 'tree', 'sublink') |
|
143 |
# this next one is a bit debatable, but arguably it's better that
|
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
144 |
# open_containing is only concerned with opening the tree
|
|
4634.157.7
by Martin Pool
Further open_containing tests |
145 |
# and then you can deal with symlinks along the way if you want
|
146 |
self.check_open_containing('link/sublink/subcontent', 'tree', |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
147 |
'sublink/subcontent') |
|
4634.157.7
by Martin Pool
Further open_containing tests |
148 |
|
149 |
def check_open_containing(self, to_open, expected_tree_name, |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
150 |
expected_relpath): |
|
4634.157.7
by Martin Pool
Further open_containing tests |
151 |
wt, relpath = workingtree.WorkingTree.open_containing(to_open) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
152 |
self.assertEqual(relpath, expected_relpath) |
|
4634.157.7
by Martin Pool
Further open_containing tests |
153 |
self.assertEndsWith(wt.basedir, expected_tree_name) |
154 |
||
|
4634.157.8
by Martin Pool
tree_files shouldn't dereference the first argument |
155 |
def test_tree_files(self): |
156 |
# not strictly a WorkingTree method, but it should be
|
|
157 |
# probably the root cause for
|
|
158 |
# <https://bugs.launchpad.net/bzr/+bug/128562>
|
|
159 |
self.make_test_tree() |
|
160 |
self.check_tree_files(['tree/outerlink'], |
|
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
161 |
'tree', ['outerlink']) |
|
4634.157.8
by Martin Pool
tree_files shouldn't dereference the first argument |
162 |
self.check_tree_files(['link/outerlink'], |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
163 |
'tree', ['outerlink']) |
|
4634.157.8
by Martin Pool
tree_files shouldn't dereference the first argument |
164 |
self.check_tree_files(['link/sublink/subcontent'], |
|
7143.15.2
by Jelmer Vernooij
Run autopep8. |
165 |
'tree', ['subdir/subcontent']) |
|
4634.157.8
by Martin Pool
tree_files shouldn't dereference the first argument |
166 |
|
167 |
def check_tree_files(self, to_open, expected_tree, expect_paths): |
|
|
5346.4.5
by Martin Pool
Deprecate and avoid internal_tree_files and tree_files. |
168 |
tree, relpaths = workingtree.WorkingTree.open_containing_paths(to_open) |
|
4634.157.8
by Martin Pool
tree_files shouldn't dereference the first argument |
169 |
self.assertEndsWith(tree.basedir, expected_tree) |
|
6614.1.3
by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual. |
170 |
self.assertEqual(expect_paths, relpaths) |
|
4634.157.8
by Martin Pool
tree_files shouldn't dereference the first argument |
171 |
|
|
4634.157.7
by Martin Pool
Further open_containing tests |
172 |
def make_test_tree(self): |
|
4634.157.6
by Martin Pool
Add test for opening a branch through a symlink |
173 |
tree = self.make_branch_and_tree('tree') |
174 |
self.build_tree_contents([ |
|
175 |
('link@', 'tree'), |
|
|
4634.157.8
by Martin Pool
tree_files shouldn't dereference the first argument |
176 |
('tree/outerlink@', '/not/there'), |
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
177 |
('tree/content', b'hello'), |
|
4634.157.7
by Martin Pool
Further open_containing tests |
178 |
('tree/sublink@', 'subdir'), |
179 |
('tree/subdir/',), |
|
|
6855.4.1
by Jelmer Vernooij
Yet more bees. |
180 |
('tree/subdir/subcontent', b'subcontent stuff') |
|
4634.157.6
by Martin Pool
Add test for opening a branch through a symlink |
181 |
])
|