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