bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
2052.3.2
by John Arbash Meinel
 Change Copyright .. by Canonical to Copyright ... Canonical  | 
1  | 
# Copyright (C) 2006 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
 | 
|
15  | 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
|
16  | 
||
17  | 
"""Test the executable bit under various working tree formats."""
 | 
|
18  | 
||
19  | 
import os  | 
|
20  | 
||
| 
1852.6.6
by Robert Collins
 Finish updating iter_entries change to make all tests pass.  | 
21  | 
from bzrlib.inventory import InventoryFile  | 
| 
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)  | 
22  | 
from bzrlib.transform import TreeTransform  | 
23  | 
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree  | 
|
24  | 
||
25  | 
||
26  | 
class TestExecutable(TestCaseWithWorkingTree):  | 
|
27  | 
||
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
28  | 
def setUp(self):  | 
29  | 
super(TestExecutable, self).setUp()  | 
|
30  | 
||
31  | 
self.a_id = "a-20051208024829-849e76f7968d7a86"  | 
|
32  | 
self.b_id = "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  | 
|
35  | 
tt = TreeTransform(wt)  | 
|
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
36  | 
tt.new_file('a', tt.root, 'a test\n', self.a_id, True)  | 
37  | 
tt.new_file('b', tt.root, '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()  | 
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
45  | 
self.failUnless(tree.is_executable(self.a_id),  | 
46  | 
"'a' lost the execute bit")  | 
|
47  | 
self.failIf(tree.is_executable(self.b_id),  | 
|
48  | 
"'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.  | 
49  | 
tree.unlock()  | 
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
50  | 
|
51  | 
def check_empty(self, tree, ignore_inv=False):  | 
|
52  | 
"""Check that the files are truly missing  | 
|
53  | 
        :param ignore_inv: If you just delete files from a working tree
 | 
|
54  | 
                the inventory still shows them, so don't assert that
 | 
|
55  | 
                the inventory is empty, just that the tree doesn't have them
 | 
|
56  | 
        """
 | 
|
| 
2255.2.36
by Robert Collins
 Fix Dirstate unversioning of entries which are in a parent.  | 
57  | 
tree.lock_read()  | 
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
58  | 
if not ignore_inv:  | 
| 
1852.6.6
by Robert Collins
 Finish updating iter_entries change to make all tests pass.  | 
59  | 
self.assertEqual(  | 
60  | 
[('', tree.inventory.root)],  | 
|
61  | 
list(tree.inventory.iter_entries()))  | 
|
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
62  | 
self.failIf(tree.has_id(self.a_id))  | 
63  | 
self.failIf(tree.has_filename('a'))  | 
|
64  | 
self.failIf(tree.has_id(self.b_id))  | 
|
65  | 
self.failIf(tree.has_filename('b'))  | 
|
| 
2255.2.36
by Robert Collins
 Fix Dirstate unversioning of entries which are in a parent.  | 
66  | 
tree.unlock()  | 
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
67  | 
|
68  | 
def commit_and_branch(self):  | 
|
69  | 
"""Commit the current tree, and create a second tree"""  | 
|
70  | 
self.wt.commit('adding a,b', rev_id='r1')  | 
|
71  | 
        # Now make sure that 'bzr branch' also preserves the
 | 
|
72  | 
        # executable bit
 | 
|
73  | 
        # TODO: Maybe this should be a blackbox test
 | 
|
74  | 
dir2 = self.wt.branch.bzrdir.clone('b2', revision_id='r1')  | 
|
75  | 
wt2 = dir2.open_workingtree()  | 
|
| 
1908.7.6
by Robert Collins
 Deprecate WorkingTree.last_revision.  | 
76  | 
self.assertEqual(['r1'], wt2.get_parent_ids())  | 
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
77  | 
self.assertEqual('r1', wt2.branch.last_revision())  | 
78  | 
return wt2  | 
|
79  | 
||
80  | 
def test_01_is_executable(self):  | 
|
81  | 
"""Make sure that the tree was created and has the executable bit set"""  | 
|
82  | 
self.check_exist(self.wt)  | 
|
83  | 
||
84  | 
def test_02_stays_executable(self):  | 
|
85  | 
"""reopen the tree and ensure it stuck."""  | 
|
86  | 
self.wt = self.wt.bzrdir.open_workingtree()  | 
|
87  | 
self.check_exist(self.wt)  | 
|
88  | 
||
89  | 
def test_03_after_commit(self):  | 
|
90  | 
"""Commit the change, and check the history"""  | 
|
91  | 
self.wt.commit('adding a,b', rev_id='r1')  | 
|
92  | 
||
93  | 
rev_tree = self.wt.branch.repository.revision_tree('r1')  | 
|
94  | 
self.check_exist(rev_tree)  | 
|
95  | 
||
96  | 
def test_04_after_removed(self):  | 
|
97  | 
"""Make sure reverting removed files brings them back correctly"""  | 
|
98  | 
self.wt.commit('adding a,b', rev_id='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)  | 
99  | 
|
100  | 
        # Make sure the entries are gone
 | 
|
101  | 
os.remove('b1/a')  | 
|
102  | 
os.remove('b1/b')  | 
|
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
103  | 
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)  | 
104  | 
|
105  | 
        # Make sure that revert is able to bring them back,
 | 
|
106  | 
        # and sets 'a' back to being executable
 | 
|
107  | 
||
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
108  | 
rev_tree = self.wt.branch.repository.revision_tree('r1')  | 
109  | 
||
110  | 
self.wt.revert(['a', 'b'], rev_tree, backups=False)  | 
|
111  | 
self.check_exist(self.wt)  | 
|
112  | 
||
113  | 
def test_05_removed_and_committed(self):  | 
|
114  | 
"""Check that reverting to an earlier commit restores them"""  | 
|
115  | 
self.wt.commit('adding a,b', rev_id='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)  | 
116  | 
|
117  | 
        # Now remove them again, and make sure that after a
 | 
|
118  | 
        # commit, they are still marked correctly
 | 
|
119  | 
os.remove('b1/a')  | 
|
120  | 
os.remove('b1/b')  | 
|
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
121  | 
self.wt.commit('removed', rev_id='r2')  | 
122  | 
||
123  | 
self.check_empty(self.wt)  | 
|
124  | 
||
125  | 
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)  | 
126  | 
        # 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'  | 
127  | 
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.  | 
128  | 
|
129  | 
self.check_exist(self.wt)  | 
|
130  | 
||
131  | 
def test_06_branch(self):  | 
|
132  | 
"""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)  | 
133  | 
        # TODO: Maybe this should be a blackbox test
 | 
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
134  | 
wt2 = self.commit_and_branch()  | 
135  | 
||
136  | 
self.check_exist(wt2)  | 
|
137  | 
||
138  | 
def test_07_pull(self):  | 
|
139  | 
"""Test that pull will handle bits correctly"""  | 
|
140  | 
wt2 = self.commit_and_branch()  | 
|
141  | 
||
142  | 
os.remove('b1/a')  | 
|
143  | 
os.remove('b1/b')  | 
|
144  | 
self.wt.commit('removed', rev_id='r2')  | 
|
145  | 
||
146  | 
        # 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)  | 
147  | 
|
148  | 
        # 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.  | 
149  | 
wt2.pull(self.wt.branch)  | 
| 
1908.7.6
by Robert Collins
 Deprecate WorkingTree.last_revision.  | 
150  | 
self.assertEquals(['r2'], wt2.get_parent_ids())  | 
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
151  | 
self.assertEquals('r2', wt2.branch.last_revision())  | 
152  | 
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)  | 
153  | 
|
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
154  | 
        # 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)  | 
155  | 
        # so that the second branch can pull the changes
 | 
156  | 
        # and make sure that the executable bit has been copied
 | 
|
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
157  | 
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'  | 
158  | 
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.  | 
159  | 
self.wt.commit('resurrected', rev_id='r3')  | 
160  | 
||
161  | 
self.check_exist(self.wt)  | 
|
162  | 
||
163  | 
wt2.pull(self.wt.branch)  | 
|
| 
1908.7.6
by Robert Collins
 Deprecate WorkingTree.last_revision.  | 
164  | 
self.assertEquals(['r3'], wt2.get_parent_ids())  | 
| 
1711.4.33
by John Arbash Meinel
 By Martin's suggestion, break the long test into lots of small ones.  | 
165  | 
self.assertEquals('r3', wt2.branch.last_revision())  | 
166  | 
self.check_exist(wt2)  | 
|
167  | 
||
168  | 
def test_08_no_op_revert(self):  | 
|
169  | 
"""Just do a simple revert without anything changed  | 
|
170  | 
        
 | 
|
171  | 
        The bits shouldn't swap.
 | 
|
172  | 
        """
 | 
|
173  | 
self.wt.commit('adding a,b', rev_id='r1')  | 
|
174  | 
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'  | 
175  | 
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.  | 
176  | 
self.check_exist(self.wt)  | 
177  |