bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
601
by Martin Pool
- whitebox tests for branch path handling |
1 |
#! /usr/bin/python
|
2 |
||
|
768
by Martin Pool
- start some tests for directory renames |
3 |
import os |
4 |
import unittest |
|
5 |
||
6 |
from bzrlib.selftest import InTempDir, TestBase |
|
7 |
from bzrlib.branch import ScratchBranch, Branch |
|
|
778
by Martin Pool
- simple revert of text files |
8 |
from bzrlib.errors import NotBranchError, NotVersionedError |
9 |
||
10 |
||
|
781
by Martin Pool
- start of simple test for unknown-file reporting |
11 |
class Unknowns(InTempDir): |
12 |
def runTest(self): |
|
13 |
b = Branch('.', init=True) |
|
14 |
||
15 |
self.build_tree(['hello.txt', |
|
16 |
'hello.txt~']) |
|
17 |
||
18 |
self.assertEquals(list(b.unknowns()), |
|
19 |
['hello.txt']) |
|
20 |
||
21 |
||
|
811
by Martin Pool
- Test case for validate_revision_id |
22 |
|
|
882
by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this. |
23 |
class NoChanges(InTempDir): |
24 |
def runTest(self): |
|
25 |
from bzrlib.errors import EmptyCommit |
|
26 |
||
27 |
b = Branch('.', init=True) |
|
28 |
||
29 |
self.build_tree(['hello.txt']) |
|
30 |
||
31 |
self.assertRaises(EmptyCommit, |
|
32 |
b.commit, |
|
33 |
'commit without adding', |
|
34 |
allow_empty=False) |
|
35 |
||
36 |
||
37 |
||
38 |
||
|
811
by Martin Pool
- Test case for validate_revision_id |
39 |
class ValidateRevisionId(TestBase): |
40 |
def runTest(self): |
|
41 |
from bzrlib.revision import validate_revision_id |
|
42 |
validate_revision_id('mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe') |
|
43 |
||
44 |
self.assertRaises(ValueError, |
|
45 |
validate_revision_id, |
|
46 |
' asdkjas') |
|
47 |
||
48 |
||
49 |
self.assertRaises(ValueError, |
|
50 |
validate_revision_id, |
|
51 |
'mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe\n') |
|
52 |
||
53 |
||
54 |
self.assertRaises(ValueError, |
|
55 |
validate_revision_id, |
|
56 |
' mbp@sourcefrog.net-20050311061123-96a255005c7c9dbe') |
|
57 |
||
58 |
self.assertRaises(ValueError, |
|
59 |
validate_revision_id, |
|
60 |
'Martin Pool <mbp@sourcefrog.net>-20050311061123-96a255005c7c9dbe') |
|
61 |
||
62 |
||
63 |
||
|
815
by Martin Pool
- track pending-merges |
64 |
class PendingMerges(InTempDir): |
65 |
"""Tracking pending-merged revisions.""" |
|
66 |
def runTest(self): |
|
67 |
b = Branch('.', init=True) |
|
68 |
||
69 |
self.assertEquals(b.pending_merges(), []) |
|
70 |
||
71 |
b.add_pending_merge('foo@azkhazan-123123-abcabc') |
|
72 |
||
73 |
self.assertEquals(b.pending_merges(), ['foo@azkhazan-123123-abcabc']) |
|
74 |
||
75 |
b.add_pending_merge('foo@azkhazan-123123-abcabc') |
|
76 |
||
77 |
self.assertEquals(b.pending_merges(), ['foo@azkhazan-123123-abcabc']) |
|
78 |
||
79 |
b.add_pending_merge('wibble@fofof--20050401--1928390812') |
|
80 |
self.assertEquals(b.pending_merges(), |
|
81 |
['foo@azkhazan-123123-abcabc', |
|
82 |
'wibble@fofof--20050401--1928390812']) |
|
|
816
by Martin Pool
- don't write precursor field in new revision xml |
83 |
|
84 |
b.commit("commit from base with two merges") |
|
85 |
||
86 |
rev = b.get_revision(b.revision_history()[0]) |
|
87 |
self.assertEquals(len(rev.parents), 2) |
|
88 |
self.assertEquals(rev.parents[0].revision_id, |
|
89 |
'foo@azkhazan-123123-abcabc') |
|
90 |
self.assertEquals(rev.parents[1].revision_id, |
|
91 |
'wibble@fofof--20050401--1928390812') |
|
|
818
by Martin Pool
- Clear pending-merge list when committing. |
92 |
|
93 |
# list should be cleared when we do a commit
|
|
94 |
self.assertEquals(b.pending_merges(), []) |
|
95 |
||
|
816
by Martin Pool
- don't write precursor field in new revision xml |
96 |
|
|
815
by Martin Pool
- track pending-merges |
97 |
|
98 |
||
|
778
by Martin Pool
- simple revert of text files |
99 |
class Revert(InTempDir): |
100 |
"""Test selected-file revert""" |
|
101 |
def runTest(self): |
|
102 |
b = Branch('.', init=True) |
|
103 |
||
104 |
self.build_tree(['hello.txt']) |
|
105 |
file('hello.txt', 'w').write('initial hello') |
|
106 |
||
107 |
self.assertRaises(NotVersionedError, |
|
108 |
b.revert, ['hello.txt']) |
|
109 |
||
110 |
b.add(['hello.txt']) |
|
111 |
b.commit('create initial hello.txt') |
|
112 |
||
113 |
self.check_file_contents('hello.txt', 'initial hello') |
|
114 |
file('hello.txt', 'w').write('new hello') |
|
115 |
self.check_file_contents('hello.txt', 'new hello') |
|
116 |
||
117 |
# revert file modified since last revision
|
|
118 |
b.revert(['hello.txt']) |
|
119 |
self.check_file_contents('hello.txt', 'initial hello') |
|
|
782
by Martin Pool
- Branch.revert copies files to backups before reverting them |
120 |
self.check_file_contents('hello.txt~', 'new hello') |
|
778
by Martin Pool
- simple revert of text files |
121 |
|
|
782
by Martin Pool
- Branch.revert copies files to backups before reverting them |
122 |
# reverting again clobbers the backup
|
|
778
by Martin Pool
- simple revert of text files |
123 |
b.revert(['hello.txt']) |
124 |
self.check_file_contents('hello.txt', 'initial hello') |
|
|
782
by Martin Pool
- Branch.revert copies files to backups before reverting them |
125 |
self.check_file_contents('hello.txt~', 'initial hello') |
|
778
by Martin Pool
- simple revert of text files |
126 |
|
|
768
by Martin Pool
- start some tests for directory renames |
127 |
|
128 |
||
129 |
class RenameDirs(InTempDir): |
|
130 |
"""Test renaming directories and the files within them.""" |
|
131 |
def runTest(self): |
|
132 |
b = Branch('.', init=True) |
|
133 |
self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file']) |
|
134 |
b.add(['dir', 'dir/sub', 'dir/sub/file']) |
|
135 |
||
136 |
b.commit('create initial state') |
|
137 |
||
138 |
# TODO: lift out to a test helper that checks the shape of
|
|
139 |
# an inventory
|
|
140 |
||
141 |
revid = b.revision_history()[0] |
|
142 |
self.log('first revision_id is {%s}' % revid) |
|
143 |
||
144 |
inv = b.get_revision_inventory(revid) |
|
145 |
self.log('contents of inventory: %r' % inv.entries()) |
|
146 |
||
147 |
self.check_inventory_shape(inv, |
|
148 |
['dir', 'dir/sub', 'dir/sub/file']) |
|
149 |
||
|
771
by Martin Pool
- more tests of directory renames |
150 |
b.rename_one('dir', 'newdir') |
151 |
||
152 |
self.check_inventory_shape(b.inventory, |
|
153 |
['newdir', 'newdir/sub', 'newdir/sub/file']) |
|
154 |
||
155 |
b.rename_one('newdir/sub', 'newdir/newsub') |
|
156 |
self.check_inventory_shape(b.inventory, |
|
157 |
['newdir', 'newdir/newsub', |
|
158 |
'newdir/newsub/file']) |
|
159 |
||
|
768
by Martin Pool
- start some tests for directory renames |
160 |
|
161 |
||
162 |
||
163 |
class BranchPathTestCase(TestBase): |
|
|
601
by Martin Pool
- whitebox tests for branch path handling |
164 |
"""test for branch path lookups |
165 |
||
166 |
Branch.relpath and bzrlib.branch._relpath do a simple but subtle
|
|
167 |
job: given a path (either relative to cwd or absolute), work out
|
|
168 |
if it is inside a branch and return the path relative to the base.
|
|
169 |
"""
|
|
|
768
by Martin Pool
- start some tests for directory renames |
170 |
|
|
601
by Martin Pool
- whitebox tests for branch path handling |
171 |
def runTest(self): |
172 |
from bzrlib.branch import _relpath |
|
173 |
import tempfile, shutil |
|
174 |
||
175 |
savedir = os.getcwdu() |
|
176 |
dtmp = tempfile.mkdtemp() |
|
177 |
||
178 |
def rp(p): |
|
179 |
return _relpath(dtmp, p) |
|
180 |
||
181 |
try: |
|
182 |
# check paths inside dtmp while standing outside it
|
|
183 |
self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo') |
|
184 |
||
185 |
# root = nothing
|
|
186 |
self.assertEqual(rp(dtmp), '') |
|
187 |
||
188 |
self.assertRaises(NotBranchError, |
|
189 |
rp, |
|
190 |
'/etc') |
|
191 |
||
192 |
# now some near-miss operations -- note that
|
|
193 |
# os.path.commonprefix gets these wrong!
|
|
194 |
self.assertRaises(NotBranchError, |
|
195 |
rp, |
|
196 |
dtmp.rstrip('\\/') + '2') |
|
197 |
||
198 |
self.assertRaises(NotBranchError, |
|
199 |
rp, |
|
200 |
dtmp.rstrip('\\/') + '2/foo') |
|
201 |
||
202 |
# now operations based on relpath of files in current
|
|
203 |
# directory, or nearby
|
|
204 |
os.chdir(dtmp) |
|
205 |
||
206 |
self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux') |
|
207 |
||
208 |
self.assertEqual(rp('foo'), 'foo') |
|
209 |
||
210 |
self.assertEqual(rp('./foo'), 'foo') |
|
211 |
||
212 |
self.assertEqual(rp(os.path.abspath('foo')), 'foo') |
|
213 |
||
214 |
self.assertRaises(NotBranchError, |
|
215 |
rp, '../foo') |
|
216 |
||
217 |
finally: |
|
218 |
os.chdir(savedir) |
|
219 |
shutil.rmtree(dtmp) |
|
|
843
by Martin Pool
- workaround for flaky TestLoader in python2.3 |
220 |
|
221 |
||
222 |
||
223 |
||
224 |
TEST_CLASSES = [Unknowns, |
|
225 |
ValidateRevisionId, |
|
226 |
PendingMerges, |
|
227 |
Revert, |
|
228 |
RenameDirs, |
|
229 |
BranchPathTestCase, |
|
230 |
]
|