0.5.66
by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None) |
1 |
import bzrlib |
2 |
import unittest |
|
3 |
from StringIO import StringIO |
|
4 |
||
5 |
from bzrlib.selftest import InTempDir |
|
0.5.78
by John Arbash Meinel
Working on test cases, starting with the empty project issues. |
6 |
|
7 |
from bzrlib.diff import internal_diff |
|
0.5.66
by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None) |
8 |
from read_changeset import ChangesetTree |
9 |
||
10 |
class MockTree(object): |
|
11 |
def __init__(self): |
|
12 |
from bzrlib.inventory import RootEntry, ROOT_ID |
|
0.6.1
by Aaron Bentley
Fleshed out MockTree, fixed all test failures |
13 |
object.__init__(self) |
0.5.66
by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None) |
14 |
self.paths = {ROOT_ID: ""} |
0.6.1
by Aaron Bentley
Fleshed out MockTree, fixed all test failures |
15 |
self.ids = {"": ROOT_ID} |
16 |
self.contents = {} |
|
0.5.66
by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None) |
17 |
self.root = RootEntry(ROOT_ID) |
0.6.1
by Aaron Bentley
Fleshed out MockTree, fixed all test failures |
18 |
|
19 |
inventory = property(lambda x:x) |
|
20 |
||
0.5.66
by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None) |
21 |
def __iter__(self): |
22 |
return self.paths.iterkeys() |
|
23 |
||
24 |
def __getitem__(self, file_id): |
|
0.6.1
by Aaron Bentley
Fleshed out MockTree, fixed all test failures |
25 |
if file_id == self.root.file_id: |
26 |
return self.root |
|
27 |
else: |
|
28 |
return self.make_entry(file_id, self.paths[file_id]) |
|
29 |
||
30 |
def parent_id(self, file_id): |
|
31 |
from os.path import dirname |
|
32 |
parent_dir = dirname(self.paths[file_id]) |
|
33 |
if parent_dir == "": |
|
34 |
return None |
|
35 |
return self.ids[parent_dir] |
|
36 |
||
37 |
def iter_entries(self): |
|
38 |
for path, file_id in self.ids.iteritems(): |
|
39 |
yield path, self[file_id] |
|
40 |
||
41 |
def get_file_kind(self, file_id): |
|
42 |
if file_id in self.contents: |
|
43 |
kind = 'file' |
|
44 |
else: |
|
45 |
kind = 'directory' |
|
46 |
return kind |
|
47 |
||
48 |
def make_entry(self, file_id, path): |
|
49 |
from os.path import basename |
|
50 |
from bzrlib.inventory import InventoryEntry |
|
51 |
name = basename(path) |
|
52 |
kind = self.get_file_kind(file_id) |
|
53 |
parent_id = self.parent_id(file_id) |
|
54 |
text_sha_1, text_size = self.contents_stats(file_id) |
|
55 |
ie = InventoryEntry(file_id, name, kind, parent_id) |
|
56 |
ie.text_sha_1 = text_sha_1 |
|
57 |
ie.text_size = text_size |
|
58 |
return ie |
|
59 |
||
60 |
def add_dir(self, file_id, path): |
|
0.5.66
by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None) |
61 |
self.paths[file_id] = path |
62 |
self.ids[path] = file_id |
|
63 |
||
64 |
def add_file(self, file_id, path, contents): |
|
65 |
self.add_dir(file_id, path) |
|
66 |
self.contents[file_id] = contents |
|
67 |
||
68 |
def path2id(self, path): |
|
69 |
return self.ids.get(path) |
|
70 |
||
71 |
def id2path(self, file_id): |
|
72 |
return self.paths.get(file_id) |
|
73 |
||
74 |
def has_id(self, file_id): |
|
75 |
return self.id2path(file_id) is not None |
|
76 |
||
77 |
def get_file(self, file_id): |
|
78 |
result = StringIO() |
|
79 |
result.write(self.contents[file_id]) |
|
80 |
result.seek(0,0) |
|
81 |
return result |
|
82 |
||
83 |
def contents_stats(self, file_id): |
|
0.6.1
by Aaron Bentley
Fleshed out MockTree, fixed all test failures |
84 |
from bzrlib.osutils import sha_file |
85 |
if file_id not in self.contents: |
|
86 |
return None, None |
|
87 |
text_sha1 = sha_file(self.get_file(file_id)) |
|
88 |
return text_sha1, len(self.contents[file_id]) |
|
89 |
||
90 |
||
91 |
class CTreeTester(unittest.TestCase): |
|
0.5.66
by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None) |
92 |
"""A simple unittest tester for the ChangesetTree class."""
|
93 |
||
94 |
def make_tree_1(self): |
|
95 |
mtree = MockTree() |
|
96 |
mtree.add_dir("a", "grandparent") |
|
97 |
mtree.add_dir("b", "grandparent/parent") |
|
98 |
mtree.add_file("c", "grandparent/parent/file", "Hello\n") |
|
99 |
mtree.add_dir("d", "grandparent/alt_parent") |
|
100 |
return ChangesetTree(mtree), mtree |
|
101 |
||
102 |
def test_renames(self): |
|
103 |
"""Ensure that file renames have the proper effect on children"""
|
|
104 |
ctree = self.make_tree_1()[0] |
|
105 |
self.assertEqual(ctree.old_path("grandparent"), "grandparent") |
|
106 |
self.assertEqual(ctree.old_path("grandparent/parent"), "grandparent/parent") |
|
107 |
self.assertEqual(ctree.old_path("grandparent/parent/file"), |
|
108 |
"grandparent/parent/file") |
|
109 |
||
110 |
self.assertEqual(ctree.id2path("a"), "grandparent") |
|
111 |
self.assertEqual(ctree.id2path("b"), "grandparent/parent") |
|
112 |
self.assertEqual(ctree.id2path("c"), "grandparent/parent/file") |
|
113 |
||
114 |
self.assertEqual(ctree.path2id("grandparent"), "a") |
|
115 |
self.assertEqual(ctree.path2id("grandparent/parent"), "b") |
|
116 |
self.assertEqual(ctree.path2id("grandparent/parent/file"), "c") |
|
117 |
||
118 |
assert ctree.path2id("grandparent2") is None |
|
119 |
assert ctree.path2id("grandparent2/parent") is None |
|
120 |
assert ctree.path2id("grandparent2/parent/file") is None |
|
121 |
||
122 |
ctree.note_rename("grandparent", "grandparent2") |
|
123 |
assert ctree.old_path("grandparent") is None |
|
124 |
assert ctree.old_path("grandparent/parent") is None |
|
125 |
assert ctree.old_path("grandparent/parent/file") is None |
|
126 |
||
127 |
self.assertEqual(ctree.id2path("a"), "grandparent2") |
|
128 |
self.assertEqual(ctree.id2path("b"), "grandparent2/parent") |
|
129 |
self.assertEqual(ctree.id2path("c"), "grandparent2/parent/file") |
|
130 |
||
131 |
self.assertEqual(ctree.path2id("grandparent2"), "a") |
|
132 |
self.assertEqual(ctree.path2id("grandparent2/parent"), "b") |
|
133 |
self.assertEqual(ctree.path2id("grandparent2/parent/file"), "c") |
|
134 |
||
135 |
assert ctree.path2id("grandparent") is None |
|
136 |
assert ctree.path2id("grandparent/parent") is None |
|
137 |
assert ctree.path2id("grandparent/parent/file") is None |
|
138 |
||
139 |
ctree.note_rename("grandparent/parent", "grandparent2/parent2") |
|
140 |
self.assertEqual(ctree.id2path("a"), "grandparent2") |
|
141 |
self.assertEqual(ctree.id2path("b"), "grandparent2/parent2") |
|
142 |
self.assertEqual(ctree.id2path("c"), "grandparent2/parent2/file") |
|
143 |
||
144 |
self.assertEqual(ctree.path2id("grandparent2"), "a") |
|
145 |
self.assertEqual(ctree.path2id("grandparent2/parent2"), "b") |
|
146 |
self.assertEqual(ctree.path2id("grandparent2/parent2/file"), "c") |
|
147 |
||
148 |
assert ctree.path2id("grandparent2/parent") is None |
|
149 |
assert ctree.path2id("grandparent2/parent/file") is None |
|
150 |
||
151 |
ctree.note_rename("grandparent/parent/file", |
|
152 |
"grandparent2/parent2/file2") |
|
153 |
self.assertEqual(ctree.id2path("a"), "grandparent2") |
|
154 |
self.assertEqual(ctree.id2path("b"), "grandparent2/parent2") |
|
155 |
self.assertEqual(ctree.id2path("c"), "grandparent2/parent2/file2") |
|
156 |
||
157 |
self.assertEqual(ctree.path2id("grandparent2"), "a") |
|
158 |
self.assertEqual(ctree.path2id("grandparent2/parent2"), "b") |
|
159 |
self.assertEqual(ctree.path2id("grandparent2/parent2/file2"), "c") |
|
160 |
||
161 |
assert ctree.path2id("grandparent2/parent2/file") is None |
|
162 |
||
163 |
def test_moves(self): |
|
164 |
"""Ensure that file moves have the proper effect on children"""
|
|
165 |
ctree = self.make_tree_1()[0] |
|
166 |
ctree.note_rename("grandparent/parent/file", |
|
167 |
"grandparent/alt_parent/file") |
|
168 |
self.assertEqual(ctree.id2path("c"), "grandparent/alt_parent/file") |
|
169 |
self.assertEqual(ctree.path2id("grandparent/alt_parent/file"), "c") |
|
170 |
assert ctree.path2id("grandparent/parent/file") is None |
|
171 |
||
172 |
def unified_diff(self, old, new): |
|
173 |
out = StringIO() |
|
174 |
internal_diff("old", old, "new", new, out) |
|
175 |
out.seek(0,0) |
|
176 |
return out.read() |
|
177 |
||
178 |
def make_tree_2(self): |
|
179 |
ctree = self.make_tree_1()[0] |
|
180 |
ctree.note_rename("grandparent/parent/file", |
|
181 |
"grandparent/alt_parent/file") |
|
182 |
assert ctree.id2path("e") is None |
|
183 |
assert ctree.path2id("grandparent/parent/file") is None |
|
184 |
ctree.note_id("e", "grandparent/parent/file") |
|
185 |
return ctree |
|
186 |
||
187 |
def test_adds(self): |
|
188 |
"""File/inventory adds"""
|
|
189 |
ctree = self.make_tree_2() |
|
190 |
add_patch = self.unified_diff([], ["Extra cheese\n"]) |
|
191 |
ctree.note_patch("grandparent/parent/file", add_patch) |
|
192 |
self.adds_test(ctree) |
|
193 |
||
194 |
def adds_test(self, ctree): |
|
195 |
self.assertEqual(ctree.id2path("e"), "grandparent/parent/file") |
|
196 |
self.assertEqual(ctree.path2id("grandparent/parent/file"), "e") |
|
197 |
self.assertEqual(ctree.get_file("e").read(), "Extra cheese\n") |
|
198 |
||
199 |
def test_adds2(self): |
|
200 |
"""File/inventory adds, with patch-compatibile renames"""
|
|
201 |
ctree = self.make_tree_2() |
|
202 |
ctree.contents_by_id = False |
|
203 |
add_patch = self.unified_diff(["Hello\n"], ["Extra cheese\n"]) |
|
204 |
ctree.note_patch("grandparent/parent/file", add_patch) |
|
205 |
self.adds_test(ctree) |
|
206 |
||
207 |
def make_tree_3(self): |
|
208 |
ctree, mtree = self.make_tree_1() |
|
209 |
mtree.add_file("e", "grandparent/parent/topping", "Anchovies\n") |
|
210 |
ctree.note_rename("grandparent/parent/file", |
|
211 |
"grandparent/alt_parent/file") |
|
212 |
ctree.note_rename("grandparent/parent/topping", |
|
213 |
"grandparent/alt_parent/stopping") |
|
214 |
return ctree |
|
215 |
||
216 |
def get_file_test(self, ctree): |
|
217 |
self.assertEqual(ctree.get_file("e").read(), "Lemon\n") |
|
218 |
self.assertEqual(ctree.get_file("c").read(), "Hello\n") |
|
219 |
||
220 |
def test_get_file(self): |
|
221 |
"""Get file contents"""
|
|
222 |
ctree = self.make_tree_3() |
|
223 |
mod_patch = self.unified_diff(["Anchovies\n"], ["Lemon\n"]) |
|
224 |
ctree.note_patch("grandparent/alt_parent/stopping", mod_patch) |
|
225 |
self.get_file_test(ctree) |
|
226 |
||
227 |
def test_get_file2(self): |
|
228 |
"""Get file contents, with patch-compatibile renames"""
|
|
229 |
ctree = self.make_tree_3() |
|
230 |
ctree.contents_by_id = False |
|
231 |
mod_patch = self.unified_diff([], ["Lemon\n"]) |
|
232 |
ctree.note_patch("grandparent/alt_parent/stopping", mod_patch) |
|
233 |
mod_patch = self.unified_diff([], ["Hello\n"]) |
|
234 |
ctree.note_patch("grandparent/alt_parent/file", mod_patch) |
|
235 |
self.get_file_test(ctree) |
|
236 |
||
237 |
def test_delete(self): |
|
238 |
"Deletion by changeset"
|
|
239 |
ctree = self.make_tree_1()[0] |
|
240 |
self.assertEqual(ctree.get_file("c").read(), "Hello\n") |
|
241 |
ctree.note_deletion("grandparent/parent/file") |
|
242 |
assert ctree.id2path("c") is None |
|
243 |
assert ctree.path2id("grandparent/parent/file") is None |
|
244 |
||
245 |
def sorted_ids(self, tree): |
|
246 |
ids = list(tree) |
|
247 |
ids.sort() |
|
248 |
return ids |
|
249 |
||
250 |
def test_iteration(self): |
|
251 |
"""Ensure that iteration through ids works properly"""
|
|
252 |
ctree = self.make_tree_1()[0] |
|
253 |
self.assertEqual(self.sorted_ids(ctree), ['a', 'b', 'c', 'd']) |
|
254 |
ctree.note_deletion("grandparent/parent/file") |
|
255 |
ctree.note_id("e", "grandparent/alt_parent/fool", kind="directory") |
|
0.6.1
by Aaron Bentley
Fleshed out MockTree, fixed all test failures |
256 |
self.assertEqual(self.sorted_ids(ctree), ['a', 'b', 'd', 'e']) |
0.5.66
by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None) |
257 |
|
258 |
class CSetTester(InTempDir): |
|
0.5.78
by John Arbash Meinel
Working on test cases, starting with the empty project issues. |
259 |
|
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
260 |
def get_valid_cset(self, base_rev_id, rev_id, auto_commit=False, checkout_dir=None): |
0.5.88
by John Arbash Meinel
Fixed a bug in the rename code, added more tests. |
261 |
"""Create a changeset from base_rev_id -> rev_id in built-in branch.
|
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
262 |
Make sure that the text generated is valid, and that it
|
263 |
can be applied against the base, and generate the same information.
|
|
264 |
|
|
265 |
:return: The in-memory changeset
|
|
266 |
"""
|
|
267 |
from cStringIO import StringIO |
|
268 |
from gen_changeset import show_changeset |
|
0.5.78
by John Arbash Meinel
Working on test cases, starting with the empty project issues. |
269 |
from read_changeset import read_changeset |
270 |
||
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
271 |
cset_txt = StringIO() |
272 |
show_changeset(self.b1, base_rev_id, self.b1, rev_id, to_file=cset_txt) |
|
273 |
cset_txt.seek(0) |
|
274 |
self.assertEqual(cset_txt.readline(), '# Bazaar-NG changeset v0.0.5\n') |
|
275 |
self.assertEqual(cset_txt.readline(), '# \n') |
|
276 |
||
277 |
rev = self.b1.get_revision(rev_id) |
|
278 |
self.assertEqual(cset_txt.readline().decode('utf-8'), |
|
0.5.87
by John Arbash Meinel
Handling international characters, added more test cases. |
279 |
u'# committer: %s\n' % rev.committer) |
280 |
||
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
281 |
open(',,cset', 'wb').write(cset_txt.getvalue()) |
0.5.83
by John Arbash Meinel
Tests pass. Now ChangesetTree has it's own inventory. |
282 |
cset_txt.seek(0) |
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
283 |
# This should also validate the generate changeset
|
284 |
cset = read_changeset(cset_txt, self.b1) |
|
285 |
info, tree = cset |
|
0.5.83
by John Arbash Meinel
Tests pass. Now ChangesetTree has it's own inventory. |
286 |
for cset_rev in info.real_revisions: |
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
287 |
# These really should have already been checked in read_changeset
|
288 |
# since it computes the sha1 hash for the revision, which
|
|
289 |
# only will match if everything is okay, but lets be
|
|
290 |
# explicit about it
|
|
291 |
branch_rev = self.b1.get_revision(cset_rev.revision_id) |
|
292 |
for a in ('inventory_id', 'inventory_sha1', 'revision_id', |
|
293 |
'timestamp', 'timezone', 'message', 'committer'): |
|
294 |
self.assertEqual(getattr(branch_rev, a), getattr(cset_rev, a)) |
|
295 |
self.assertEqual(len(branch_rev.parents), len(cset_rev.parents)) |
|
296 |
for b_par, c_par in zip(branch_rev.parents, cset_rev.parents): |
|
297 |
self.assertEqual(b_par.revision_id, c_par.revision_id) |
|
298 |
# Foolishly, pending-merges generates parents which
|
|
299 |
# may not have revision entries
|
|
300 |
if b_par.revision_sha1 is None: |
|
301 |
if b_par.revision_id in self.b1.revision_store: |
|
302 |
sha1 = self.b1.get_revision_sha1(b_par.revision_id) |
|
303 |
else: |
|
304 |
sha1 = None |
|
305 |
else: |
|
306 |
sha1 = b_par.revision_sha1 |
|
307 |
if sha1 is not None: |
|
308 |
self.assertEqual(sha1, c_par.revision_sha1) |
|
309 |
||
310 |
self.valid_apply_changeset(base_rev_id, cset, |
|
0.5.88
by John Arbash Meinel
Fixed a bug in the rename code, added more tests. |
311 |
auto_commit=auto_commit, checkout_dir=checkout_dir) |
312 |
||
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
313 |
return cset |
0.5.83
by John Arbash Meinel
Tests pass. Now ChangesetTree has it's own inventory. |
314 |
|
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
315 |
def get_checkout(self, rev_id, checkout_dir=None): |
0.5.88
by John Arbash Meinel
Fixed a bug in the rename code, added more tests. |
316 |
"""Get a new tree, with the specified revision in it.
|
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
317 |
"""
|
318 |
from bzrlib.branch import find_branch |
|
319 |
import tempfile |
|
320 |
from bzrlib.merge import merge |
|
321 |
||
322 |
if checkout_dir is None: |
|
0.5.88
by John Arbash Meinel
Fixed a bug in the rename code, added more tests. |
323 |
checkout_dir = tempfile.mkdtemp(prefix='test-branch-', dir='.') |
324 |
to_branch = find_branch(checkout_dir, init=True) |
|
325 |
# TODO: Once root ids are established, remove this if
|
|
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
326 |
if hasattr(self.b1, 'get_root_id'): |
327 |
to_branch.set_root_id(self.b1.get_root_id()) |
|
328 |
if rev_id is not None: |
|
329 |
# TODO Worry about making the root id of the branch
|
|
330 |
# the same
|
|
331 |
rh = self.b1.revision_history() |
|
332 |
self.assert_(rev_id in rh, 'Missing revision %s in base tree' % rev_id) |
|
333 |
revno = self.b1.revision_history().index(rev_id) + 1 |
|
334 |
to_branch.update_revisions(self.b1, stop_revision=revno) |
|
335 |
merge((checkout_dir, -1), (checkout_dir, 0), this_dir=checkout_dir, |
|
0.5.88
by John Arbash Meinel
Fixed a bug in the rename code, added more tests. |
336 |
check_clean=False, ignore_zero=True) |
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
337 |
return to_branch |
338 |
||
339 |
def valid_apply_changeset(self, base_rev_id, cset, |
|
0.5.88
by John Arbash Meinel
Fixed a bug in the rename code, added more tests. |
340 |
auto_commit=False, checkout_dir=None): |
341 |
"""Get the base revision, apply the changes, and make
|
|
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
342 |
sure everything matches the builtin branch.
|
343 |
"""
|
|
344 |
from apply_changeset import _apply_cset |
|
345 |
||
346 |
to_branch = self.get_checkout(base_rev_id, checkout_dir=checkout_dir) |
|
0.5.88
by John Arbash Meinel
Fixed a bug in the rename code, added more tests. |
347 |
auto_committed = _apply_cset(to_branch, cset, auto_commit=auto_commit) |
0.5.86
by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing. |
348 |
|
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
349 |
info = cset[0] |
350 |
for rev in info.real_revisions: |
|
351 |
self.assert_(rev.revision_id in to_branch.revision_store, |
|
352 |
'Missing revision {%s} after applying changeset' |
|
353 |
% rev.revision_id) |
|
354 |
||
355 |
self.assert_(info.target in to_branch.inventory_store) |
|
0.5.86
by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing. |
356 |
for file_id, ie in to_branch.get_inventory(info.target).iter_entries(): |
357 |
if hasattr(ie, 'text_id') and ie.text_id is not None: |
|
358 |
self.assert_(ie.text_id in to_branch.text_store) |
|
359 |
||
360 |
||
361 |
# Don't call get_valid_cset(auto_commit=True) unless you
|
|
362 |
# expect the auto-commit to succeed.
|
|
363 |
self.assertEqual(auto_commit, auto_committed) |
|
364 |
||
365 |
if auto_committed: |
|
366 |
# We might also check that all revisions are in the
|
|
367 |
# history for some changeset applications which
|
|
368 |
# merge multiple revisions.
|
|
369 |
self.assertEqual(to_branch.last_patch(), info.target) |
|
370 |
else: |
|
371 |
self.assert_(info.target in to_branch.pending_merges()) |
|
372 |
||
373 |
||
374 |
rev = info.real_revisions[-1] |
|
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
375 |
base_tree = self.b1.revision_tree(rev.revision_id) |
376 |
to_tree = to_branch.revision_tree(rev.revision_id) |
|
377 |
||
378 |
# TODO: make sure the target tree is identical to base tree
|
|
379 |
# we might also check the working tree.
|
|
0.5.86
by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing. |
380 |
|
381 |
base_files = list(base_tree.list_files()) |
|
382 |
to_files = list(to_tree.list_files()) |
|
383 |
self.assertEqual(len(base_files), len(to_files)) |
|
384 |
self.assertEqual(base_files, to_files) |
|
385 |
||
386 |
for path, status, kind, fileid in base_files: |
|
387 |
# Check that the meta information is the same
|
|
388 |
self.assertEqual(base_tree.get_file_size(fileid), |
|
389 |
to_tree.get_file_size(fileid)) |
|
390 |
self.assertEqual(base_tree.get_file_sha1(fileid), |
|
391 |
to_tree.get_file_sha1(fileid)) |
|
392 |
# Check that the contents are the same
|
|
393 |
# This is pretty expensive
|
|
394 |
# self.assertEqual(base_tree.get_file(fileid).read(),
|
|
395 |
# to_tree.get_file(fileid).read())
|
|
396 |
||
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
397 |
def runTest(self): |
0.5.81
by John Arbash Meinel
Cleaning up from pychecker. |
398 |
from bzrlib.branch import find_branch |
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
399 |
import common |
0.5.78
by John Arbash Meinel
Working on test cases, starting with the empty project issues. |
400 |
|
401 |
import os, sys |
|
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
402 |
pjoin = os.path.join |
0.5.78
by John Arbash Meinel
Working on test cases, starting with the empty project issues. |
403 |
|
404 |
os.mkdir('b1') |
|
405 |
self.b1 = find_branch('b1', init=True) |
|
406 |
||
407 |
open(pjoin('b1/one'), 'wb').write('one\n') |
|
408 |
self.b1.add('one') |
|
409 |
self.b1.commit('add one', rev_id='a@cset-0-1') |
|
410 |
||
411 |
cset = self.get_valid_cset(None, 'a@cset-0-1') |
|
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
412 |
|
413 |
# Make sure we can handle files with spaces, tabs, other
|
|
414 |
# bogus characters
|
|
415 |
self.build_tree([ |
|
0.5.82
by John Arbash Meinel
Lots of changes, changing separators, updating tests, updated ChangesetTree to include text_ids |
416 |
'b1/with space.txt'
|
0.5.84
by John Arbash Meinel
(broken) problem with removes. |
417 |
, 'b1/dir/' |
418 |
, 'b1/dir/filein subdir.c' |
|
419 |
, 'b1/dir/WithCaps.txt' |
|
420 |
, 'b1/dir/trailing space ' |
|
0.5.87
by John Arbash Meinel
Handling international characters, added more test cases. |
421 |
, 'b1/sub/' |
0.5.84
by John Arbash Meinel
(broken) problem with removes. |
422 |
, 'b1/sub/sub/' |
423 |
, 'b1/sub/sub/nonempty.txt' |
|
424 |
# Tabs are not valid in filenames on windows
|
|
0.5.82
by John Arbash Meinel
Lots of changes, changing separators, updating tests, updated ChangesetTree to include text_ids |
425 |
#'b1/with\ttab.txt'
|
426 |
])
|
|
427 |
open('b1/sub/sub/emptyfile.txt', 'wb').close() |
|
0.5.84
by John Arbash Meinel
(broken) problem with removes. |
428 |
self.b1.add([ |
0.5.82
by John Arbash Meinel
Lots of changes, changing separators, updating tests, updated ChangesetTree to include text_ids |
429 |
'with space.txt'
|
0.5.84
by John Arbash Meinel
(broken) problem with removes. |
430 |
, 'dir' |
431 |
, 'dir/filein subdir.c' |
|
432 |
, 'dir/WithCaps.txt' |
|
433 |
, 'dir/trailing space ' |
|
0.5.87
by John Arbash Meinel
Handling international characters, added more test cases. |
434 |
, 'sub' |
0.5.84
by John Arbash Meinel
(broken) problem with removes. |
435 |
, 'sub/sub' |
436 |
, 'sub/sub/nonempty.txt' |
|
437 |
, 'sub/sub/emptyfile.txt' |
|
438 |
])
|
|
0.5.82
by John Arbash Meinel
Lots of changes, changing separators, updating tests, updated ChangesetTree to include text_ids |
439 |
self.b1.commit('add whitespace', rev_id='a@cset-0-2') |
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
440 |
|
441 |
cset = self.get_valid_cset('a@cset-0-1', 'a@cset-0-2') |
|
442 |
cset = self.get_valid_cset('a@cset-0-1', 'a@cset-0-2', auto_commit=True) |
|
0.5.86
by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing. |
443 |
# Check a rollup changeset
|
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
444 |
cset = self.get_valid_cset(None, 'a@cset-0-2') |
445 |
cset = self.get_valid_cset(None, 'a@cset-0-2', auto_commit=True) |
|
0.5.86
by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing. |
446 |
|
0.5.84
by John Arbash Meinel
(broken) problem with removes. |
447 |
# Now delete entries
|
448 |
self.b1.remove(['sub/sub/nonempty.txt' |
|
449 |
, 'sub/sub/emptyfile.txt' |
|
450 |
, 'sub/sub']) |
|
451 |
self.b1.commit('removed', rev_id='a@cset-0-3') |
|
452 |
||
0.5.80
by John Arbash Meinel
Starting to write tests for changeset, discovering some errors as I go. |
453 |
cset = self.get_valid_cset('a@cset-0-2', 'a@cset-0-3') |
0.5.84
by John Arbash Meinel
(broken) problem with removes. |
454 |
cset = self.get_valid_cset('a@cset-0-2', 'a@cset-0-3', auto_commit=True) |
0.5.86
by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing. |
455 |
# Check a rollup changeset
|
0.5.84
by John Arbash Meinel
(broken) problem with removes. |
456 |
cset = self.get_valid_cset(None, 'a@cset-0-3') |
457 |
cset = self.get_valid_cset(None, 'a@cset-0-3', auto_commit=True) |
|
0.5.86
by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing. |
458 |
|
0.5.84
by John Arbash Meinel
(broken) problem with removes. |
459 |
|
460 |
# Now move the directory
|
|
461 |
self.b1.rename_one('dir', 'sub/dir') |
|
462 |
self.b1.commit('rename dir', rev_id='a@cset-0-4') |
|
0.6.1
by Aaron Bentley
Fleshed out MockTree, fixed all test failures |
463 |
|
0.5.84
by John Arbash Meinel
(broken) problem with removes. |
464 |
cset = self.get_valid_cset('a@cset-0-3', 'a@cset-0-4') |
465 |
# Check a rollup changeset
|
|
466 |
cset = self.get_valid_cset(None, 'a@cset-0-4') |
|
467 |
cset = self.get_valid_cset(None, 'a@cset-0-4', auto_commit=True) |
|
0.5.86
by John Arbash Meinel
Updated the auto-commit functionality, and adding to pending-merges, more testing. |
468 |
cset = self.get_valid_cset('a@cset-0-1', 'a@cset-0-4', auto_commit=True) |
469 |
cset = self.get_valid_cset('a@cset-0-2', 'a@cset-0-4', auto_commit=True) |
|
470 |
cset = self.get_valid_cset('a@cset-0-3', 'a@cset-0-4', auto_commit=True) |
|
471 |
||
0.5.84
by John Arbash Meinel
(broken) problem with removes. |
472 |
# Modified files
|
0.5.87
by John Arbash Meinel
Handling international characters, added more test cases. |
473 |
open('b1/sub/dir/WithCaps.txt', 'ab').write('\nAdding some text\n') |
474 |
open('b1/sub/dir/trailing space ', 'ab').write('\nAdding some\nDOS format lines\n') |
|
0.5.88
by John Arbash Meinel
Fixed a bug in the rename code, added more tests. |
475 |
self.b1.rename_one('sub/dir/trailing space ', 'sub/ start and end space ') |
476 |
self.b1.commit('Modified files', rev_id='a@cset-0-5') |
|
0.5.87
by John Arbash Meinel
Handling international characters, added more test cases. |
477 |
cset = self.get_valid_cset('a@cset-0-4', 'a@cset-0-5', checkout_dir='Broken') |
0.5.88
by John Arbash Meinel
Fixed a bug in the rename code, added more tests. |
478 |
cset = self.get_valid_cset('a@cset-0-4', 'a@cset-0-5', auto_commit=True) |
0.5.87
by John Arbash Meinel
Handling international characters, added more test cases. |
479 |
cset = self.get_valid_cset(None, 'a@cset-0-5', auto_commit=True) |
480 |
||
481 |
# Handle international characters
|
|
482 |
f = open(u'b1/with Dod\xe9', 'wb') |
|
483 |
f.write((u'A file\n' |
|
484 |
u'With international man of mystery\n' |
|
485 |
u'William Dod\xe9\n').encode('utf-8')) |
|
486 |
self.b1.add([u'with Dod\xe9']) |
|
487 |
# BUG: (sort of) You must set verbose=False, so that python doesn't try
|
|
488 |
# and print the name of William Dode as part of the commit
|
|
489 |
self.b1.commit(u'i18n commit from William Dod\xe9', rev_id='a@cset-0-6', |
|
490 |
committer=u'William Dod\xe9', verbose=False) |
|
491 |
cset = self.get_valid_cset('a@cset-0-5', 'a@cset-0-6') |
|
492 |
cset = self.get_valid_cset('a@cset-0-5', 'a@cset-0-6', auto_commit=True) |
|
493 |
cset = self.get_valid_cset(None, 'a@cset-0-6', auto_commit=True) |
|
494 |
||
495 |
||
496 |
||
497 |
TEST_CLASSES = [ |
|
0.5.78
by John Arbash Meinel
Working on test cases, starting with the empty project issues. |
498 |
CTreeTester, |
499 |
CSetTester
|
|
500 |
]
|
|
501 |
||
0.5.66
by John Arbash Meinel
Refactoring, moving test code into test (switching back to assert is None) |
502 |