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) 2006, 2007, 2009, 2011, 2012, 2016 Canonical Ltd
|
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
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
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
16 |
|
17 |
"""Test the executable bit under various working tree formats."""
|
|
18 |
||
19 |
import os |
|
20 |
||
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
21 |
from breezy import ( |
|
2911.5.4
by John Arbash Meinel
Switch around to properly look up the executable bit in the basis. |
22 |
osutils, |
23 |
)
|
|
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
24 |
from breezy.tests.per_workingtree import TestCaseWithWorkingTree |
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
25 |
|
26 |
||
27 |
class TestExecutable(TestCaseWithWorkingTree): |
|
28 |
||
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
29 |
def setUp(self): |
30 |
super(TestExecutable, self).setUp() |
|
|
6963.2.4
by Jelmer Vernooij
Add bees. |
31 |
self.a_id = b"a-20051208024829-849e76f7968d7a86" |
32 |
self.b_id = b"b-20051208024829-849e76f7968d7a86" |
|
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
33 |
wt = self.make_branch_and_tree('b1') |
34 |
b = wt.branch |
|
|
7490.77.2
by Jelmer Vernooij
Split out git and bzr-specific transforms. |
35 |
tt = wt.transform() |
|
6973.9.1
by Jelmer Vernooij
More test fixes. |
36 |
tt.new_file('a', tt.root, [b'a test\n'], self.a_id, True) |
37 |
tt.new_file('b', tt.root, [b'b test\n'], self.b_id, False) |
|
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
38 |
tt.apply() |
39 |
||
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
40 |
self.wt = wt |
41 |
||
42 |
def check_exist(self, tree): |
|
43 |
"""Just check that both files have the right executable bits set""" |
|
|
2255.2.35
by Robert Collins
Remove inappropriate use of inventory in tree executability tests. The inventory is not the authoritative source of executability. |
44 |
tree.lock_read() |
|
6963.2.4
by Jelmer Vernooij
Add bees. |
45 |
self.assertTrue(tree.is_executable('a'), "'a' lost the execute bit") |
46 |
self.assertFalse(tree.is_executable('b'), "'b' gained an execute bit") |
|
|
2255.2.35
by Robert Collins
Remove inappropriate use of inventory in tree executability tests. The inventory is not the authoritative source of executability. |
47 |
tree.unlock() |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
48 |
|
49 |
def check_empty(self, tree, ignore_inv=False): |
|
50 |
"""Check that the files are truly missing |
|
51 |
:param ignore_inv: If you just delete files from a working tree
|
|
52 |
the inventory still shows them, so don't assert that
|
|
53 |
the inventory is empty, just that the tree doesn't have them
|
|
54 |
"""
|
|
|
7397.4.4
by Jelmer Vernooij
Allow has_id to be unsupported. |
55 |
with tree.lock_read(): |
56 |
if not ignore_inv and getattr(tree, 'root_inventory', None): |
|
57 |
self.assertEqual( |
|
58 |
[('', tree.root_inventory.root)], |
|
59 |
list(tree.root_inventory.iter_entries())) |
|
60 |
self.assertFalse(tree.has_filename('a')) |
|
61 |
self.assertFalse(tree.has_filename('b')) |
|
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
62 |
|
63 |
def commit_and_branch(self): |
|
64 |
"""Commit the current tree, and create a second tree""" |
|
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
65 |
r1 = self.wt.commit('adding a,b') |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
66 |
# Now make sure that 'bzr branch' also preserves the
|
67 |
# executable bit
|
|
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
68 |
dir2 = self.wt.branch.controldir.sprout('b2', revision_id=r1) |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
69 |
wt2 = dir2.open_workingtree() |
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
70 |
self.assertEqual([r1], wt2.get_parent_ids()) |
71 |
self.assertEqual(r1, wt2.branch.last_revision()) |
|
|
6876.5.3
by Jelmer Vernooij
Fix test_executable test. |
72 |
return wt2, r1 |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
73 |
|
74 |
def test_01_is_executable(self): |
|
75 |
"""Make sure that the tree was created and has the executable bit set""" |
|
76 |
self.check_exist(self.wt) |
|
77 |
||
78 |
def test_02_stays_executable(self): |
|
79 |
"""reopen the tree and ensure it stuck.""" |
|
|
6653.6.1
by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir. |
80 |
self.wt = self.wt.controldir.open_workingtree() |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
81 |
self.check_exist(self.wt) |
82 |
||
83 |
def test_03_after_commit(self): |
|
84 |
"""Commit the change, and check the history""" |
|
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
85 |
r1 = self.wt.commit('adding a,b') |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
86 |
|
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
87 |
rev_tree = self.wt.branch.repository.revision_tree(r1) |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
88 |
self.check_exist(rev_tree) |
89 |
||
90 |
def test_04_after_removed(self): |
|
91 |
"""Make sure reverting removed files brings them back correctly""" |
|
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
92 |
r1 = self.wt.commit('adding a,b') |
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
93 |
|
94 |
# Make sure the entries are gone
|
|
95 |
os.remove('b1/a') |
|
96 |
os.remove('b1/b') |
|
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
97 |
self.check_empty(self.wt, ignore_inv=True) |
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
98 |
|
99 |
# Make sure that revert is able to bring them back,
|
|
100 |
# and sets 'a' back to being executable
|
|
101 |
||
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
102 |
rev_tree = self.wt.branch.repository.revision_tree(r1) |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
103 |
|
104 |
self.wt.revert(['a', 'b'], rev_tree, backups=False) |
|
105 |
self.check_exist(self.wt) |
|
106 |
||
107 |
def test_05_removed_and_committed(self): |
|
108 |
"""Check that reverting to an earlier commit restores them""" |
|
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
109 |
r1 = self.wt.commit('adding a,b') |
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
110 |
|
111 |
# Now remove them again, and make sure that after a
|
|
112 |
# commit, they are still marked correctly
|
|
113 |
os.remove('b1/a') |
|
114 |
os.remove('b1/b') |
|
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
115 |
r2 = self.wt.commit('removed') |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
116 |
|
117 |
self.check_empty(self.wt) |
|
118 |
||
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
119 |
rev_tree = self.wt.branch.repository.revision_tree(r1) |
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
120 |
# Now revert back to the previous commit
|
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
121 |
self.wt.revert(old_tree=rev_tree, backups=False) |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
122 |
|
123 |
self.check_exist(self.wt) |
|
124 |
||
125 |
def test_06_branch(self): |
|
126 |
"""branch b1=>b2 should preserve the executable bits""" |
|
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
127 |
# TODO: Maybe this should be a blackbox test
|
|
6876.5.3
by Jelmer Vernooij
Fix test_executable test. |
128 |
wt2, r1 = self.commit_and_branch() |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
129 |
|
130 |
self.check_exist(wt2) |
|
131 |
||
132 |
def test_07_pull(self): |
|
133 |
"""Test that pull will handle bits correctly""" |
|
|
6876.5.3
by Jelmer Vernooij
Fix test_executable test. |
134 |
wt2, r1 = self.commit_and_branch() |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
135 |
|
136 |
os.remove('b1/a') |
|
137 |
os.remove('b1/b') |
|
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
138 |
r2 = self.wt.commit('removed') |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
139 |
|
140 |
# now wt2 can pull and the files should be removed
|
|
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
141 |
|
142 |
# Make sure pull will delete the files
|
|
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
143 |
wt2.pull(self.wt.branch) |
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
144 |
self.assertEqual([r2], wt2.get_parent_ids()) |
145 |
self.assertEqual(r2, wt2.branch.last_revision()) |
|
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
146 |
self.check_empty(wt2) |
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
147 |
|
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
148 |
# Now restore the files on the first branch and commit
|
|
1711.4.30
by John Arbash Meinel
Don't peak under the covers, and test all working tree implementations for executable success (suggested by Robert Collins) |
149 |
# so that the second branch can pull the changes
|
150 |
# and make sure that the executable bit has been copied
|
|
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
151 |
rev_tree = self.wt.branch.repository.revision_tree(r1) |
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
152 |
self.wt.revert(old_tree=rev_tree, backups=False) |
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
153 |
r3 = self.wt.commit('resurrected') |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
154 |
|
155 |
self.check_exist(self.wt) |
|
156 |
||
157 |
wt2.pull(self.wt.branch) |
|
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
158 |
self.assertEqual([r3], wt2.get_parent_ids()) |
159 |
self.assertEqual(r3, wt2.branch.last_revision()) |
|
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
160 |
self.check_exist(wt2) |
161 |
||
162 |
def test_08_no_op_revert(self): |
|
163 |
"""Just do a simple revert without anything changed |
|
|
3943.8.1
by Marius Kruger
remove all trailing whitespace from bzr source |
164 |
|
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
165 |
The bits shouldn't swap.
|
166 |
"""
|
|
|
6876.5.1
by Jelmer Vernooij
Avoid passing in revision ids if possible. |
167 |
r1 = self.wt.commit('adding a,b') |
168 |
rev_tree = self.wt.branch.repository.revision_tree(r1) |
|
|
2748.3.2
by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified' |
169 |
self.wt.revert(old_tree=rev_tree, backups=False) |
|
1711.4.33
by John Arbash Meinel
By Martin's suggestion, break the long test into lots of small ones. |
170 |
self.check_exist(self.wt) |
171 |
||
|
2911.5.4
by John Arbash Meinel
Switch around to properly look up the executable bit in the basis. |
172 |
def test_commit_with_exec_from_basis(self): |
173 |
self.wt._is_executable_from_path_and_stat = \ |
|
174 |
self.wt._is_executable_from_path_and_stat_from_basis |
|
175 |
rev_id1 = self.wt.commit('one') |
|
176 |
rev_tree1 = self.wt.branch.repository.revision_tree(rev_id1) |
|
|
6913.3.4
by Jelmer Vernooij
Avoid use of inventory and file ids. |
177 |
a_executable = rev_tree1.is_executable('a') |
178 |
b_executable = rev_tree1.is_executable('b') |
|
|
2911.5.4
by John Arbash Meinel
Switch around to properly look up the executable bit in the basis. |
179 |
self.assertIsNot(None, a_executable) |
180 |
self.assertTrue(a_executable) |
|
181 |
self.assertIsNot(None, b_executable) |
|
182 |
self.assertFalse(b_executable) |
|
183 |
||
184 |
def test_use_exec_from_basis(self): |
|
|
6379.7.3
by Jelmer Vernooij
Fix test_use_exec_from_basis |
185 |
self.wt._supports_executable = lambda: False |
186 |
self.addCleanup(self.wt.lock_read().unlock) |
|
|
6809.4.4
by Jelmer Vernooij
Swap arguments for Tree.is_executable. |
187 |
self.assertTrue(self.wt.is_executable('a')) |
188 |
self.assertFalse(self.wt.is_executable('b')) |