bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
0.12.1
by Aaron Bentley
Initial bencode-based encoding |
1 |
# Copyright (C) 2008 Aaron Bentley <aaron@aaronbentley.com>
|
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 |
||
|
0.12.9
by Aaron Bentley
Simplify tests |
17 |
import os |
|
0.12.1
by Aaron Bentley
Initial bencode-based encoding |
18 |
|
|
0.13.1
by Aaron Bentley
Serialization does not dictate contents of beginning of file. |
19 |
from bzrlib import pack, transform |
|
0.13.6
by Aaron Bentley
Fix get_parents_ functions |
20 |
from bzrlib.plugins.shelf2.serialize_transform import ( |
21 |
get_parents_lines, |
|
22 |
get_parents_texts, |
|
23 |
deserialize, |
|
24 |
serialize, |
|
25 |
)
|
|
|
0.12.9
by Aaron Bentley
Simplify tests |
26 |
from bzrlib import tests |
27 |
||
28 |
||
29 |
class TestSerializeTransform(tests.TestCaseWithTransport): |
|
30 |
||
31 |
def get_two_previews(self, tree): |
|
32 |
tt = transform.TransformPreview(tree) |
|
33 |
self.addCleanup(tt.finalize) |
|
34 |
tt2 = transform.TransformPreview(tree) |
|
35 |
self.addCleanup(tt2.finalize) |
|
36 |
return tt, tt2 |
|
|
0.12.1
by Aaron Bentley
Initial bencode-based encoding |
37 |
|
|
0.13.1
by Aaron Bentley
Serialization does not dictate contents of beginning of file. |
38 |
@staticmethod
|
39 |
def reserialize(tt, tt2): |
|
40 |
serializer = pack.ContainerSerialiser() |
|
41 |
parser = pack.ContainerPushParser() |
|
42 |
parser.accept_bytes(serializer.begin()) |
|
43 |
for bytes in serialize(tt, serializer): |
|
44 |
parser.accept_bytes(bytes) |
|
45 |
parser.accept_bytes(serializer.end()) |
|
46 |
deserialize(tt2, iter(parser.read_pending_records())) |
|
47 |
||
|
0.12.8
by Aaron Bentley
Test deleting and unversioning |
48 |
def test_roundtrip_creation(self): |
|
0.12.1
by Aaron Bentley
Initial bencode-based encoding |
49 |
tree = self.make_branch_and_tree('.') |
|
0.12.9
by Aaron Bentley
Simplify tests |
50 |
tt, tt2 = self.get_two_previews(tree) |
|
0.12.1
by Aaron Bentley
Initial bencode-based encoding |
51 |
tt.new_file(u'foo\u1234', tt.root, 'bar', 'baz', True) |
|
0.12.6
by Aaron Bentley
Support serializing/deserializing directories |
52 |
tt.new_directory('qux', tt.root, 'quxx') |
|
0.13.1
by Aaron Bentley
Serialization does not dictate contents of beginning of file. |
53 |
self.reserialize(tt, tt2) |
|
0.12.6
by Aaron Bentley
Support serializing/deserializing directories |
54 |
self.assertEqual(3, tt2._id_number) |
55 |
self.assertEqual({'new-1': u'foo\u1234', |
|
56 |
'new-2': 'qux'}, tt2._new_name) |
|
57 |
self.assertEqual({'new-1': 'baz', 'new-2': 'quxx'}, tt2._new_id) |
|
58 |
self.assertEqual({'new-1': tt.root, 'new-2': tt.root}, tt2._new_parent) |
|
59 |
self.assertEqual({'baz': 'new-1', 'quxx': 'new-2'}, tt2._r_new_id) |
|
|
0.12.7
by Aaron Bentley
Get executability under test. |
60 |
self.assertEqual({'new-1': True}, tt2._new_executability) |
|
0.12.6
by Aaron Bentley
Support serializing/deserializing directories |
61 |
self.assertEqual({'new-1': 'file', |
62 |
'new-2': 'directory'}, tt2._new_contents) |
|
|
0.12.5
by Aaron Bentley
Test file content |
63 |
foo_limbo = open(tt2._limbo_name('new-1'), 'rb') |
64 |
try: |
|
65 |
foo_content = foo_limbo.read() |
|
66 |
finally: |
|
67 |
foo_limbo.close() |
|
68 |
self.assertEqual('bar', foo_content) |
|
|
0.12.8
by Aaron Bentley
Test deleting and unversioning |
69 |
|
|
0.12.10
by Aaron Bentley
Implement symlink serialization |
70 |
def test_symlink_creation(self): |
71 |
self.requireFeature(tests.SymlinkFeature) |
|
72 |
tree = self.make_branch_and_tree('.') |
|
73 |
tt, tt2 = self.get_two_previews(tree) |
|
74 |
tt.new_symlink('foo', tt.root, 'bar') |
|
|
0.13.1
by Aaron Bentley
Serialization does not dictate contents of beginning of file. |
75 |
self.reserialize(tt, tt2) |
|
0.12.10
by Aaron Bentley
Implement symlink serialization |
76 |
foo_content = os.readlink(tt2._limbo_name('new-1')) |
77 |
self.assertEqual('bar', foo_content) |
|
78 |
||
|
0.12.8
by Aaron Bentley
Test deleting and unversioning |
79 |
def test_roundtrip_destruction(self): |
80 |
tree = self.make_branch_and_tree('.') |
|
81 |
self.build_tree([u'foo\u1234', 'bar']) |
|
82 |
tree.add([u'foo\u1234', 'bar'], ['foo-id', 'bar-id']) |
|
|
0.12.9
by Aaron Bentley
Simplify tests |
83 |
tt, tt2 = self.get_two_previews(tree) |
|
0.12.8
by Aaron Bentley
Test deleting and unversioning |
84 |
foo_trans_id = tt.trans_id_tree_file_id('foo-id') |
85 |
tt.unversion_file(foo_trans_id) |
|
86 |
bar_trans_id = tt.trans_id_tree_file_id('bar-id') |
|
87 |
tt.delete_contents(bar_trans_id) |
|
|
0.13.1
by Aaron Bentley
Serialization does not dictate contents of beginning of file. |
88 |
self.reserialize(tt, tt2) |
|
0.12.8
by Aaron Bentley
Test deleting and unversioning |
89 |
self.assertEqual({u'foo\u1234': foo_trans_id, |
90 |
'bar': bar_trans_id, |
|
91 |
'': tt.root}, tt2._tree_path_ids) |
|
92 |
self.assertEqual({foo_trans_id: u'foo\u1234', |
|
93 |
bar_trans_id: 'bar', |
|
94 |
tt.root: ''}, tt2._tree_id_paths) |
|
95 |
self.assertEqual(set([foo_trans_id]), tt2._removed_id) |
|
96 |
self.assertEqual(set([bar_trans_id]), tt2._removed_contents) |
|
|
0.12.11
by Aaron Bentley
Some tweakage |
97 |
|
98 |
def test_roundtrip_missing(self): |
|
99 |
tree = self.make_branch_and_tree('.') |
|
100 |
tt, tt2 = self.get_two_previews(tree) |
|
101 |
boo_trans_id = tt.trans_id_file_id('boo') |
|
|
0.13.1
by Aaron Bentley
Serialization does not dictate contents of beginning of file. |
102 |
self.reserialize(tt, tt2) |
|
0.12.11
by Aaron Bentley
Some tweakage |
103 |
self.assertEqual({'boo': boo_trans_id}, tt2._non_present_ids) |
|
0.13.3
by Aaron Bentley
Implement MPDiff compression of shelves |
104 |
|
105 |
def test_roundtrip_modification(self): |
|
|
0.13.6
by Aaron Bentley
Fix get_parents_ functions |
106 |
LINES_ONE = 'aa\nbb\ncc\ndd\n' |
107 |
LINES_TWO = 'z\nbb\nx\ndd\n' |
|
|
0.13.3
by Aaron Bentley
Implement MPDiff compression of shelves |
108 |
tree = self.make_branch_and_tree('tree') |
109 |
self.build_tree_contents([('tree/file', LINES_ONE)]) |
|
110 |
tree.add('file', 'file-id') |
|
111 |
tt, tt2 = self.get_two_previews(tree) |
|
112 |
trans_id = tt.trans_id_file_id('file-id') |
|
113 |
tt.delete_contents(trans_id) |
|
114 |
tt.create_file(LINES_TWO, trans_id) |
|
115 |
self.reserialize(tt, tt2) |
|
116 |
self.assertFileEqual(LINES_TWO, tt2._limbo_name(trans_id)) |
|
|
0.13.4
by Aaron Bentley
Make get_parents_lines more robust |
117 |
|
118 |
def test_roundtrip_kind_change(self): |
|
119 |
LINES_ONE = 'a\nb\nc\nd\n' |
|
120 |
tree = self.make_branch_and_tree('tree') |
|
121 |
self.build_tree(['tree/foo/']) |
|
122 |
tree.add('foo', 'foo-id') |
|
123 |
tt, tt2 = self.get_two_previews(tree) |
|
124 |
trans_id = tt.trans_id_file_id('foo-id') |
|
125 |
tt.delete_contents(trans_id) |
|
126 |
tt.create_file(LINES_ONE, trans_id) |
|
127 |
self.reserialize(tt, tt2) |
|
128 |
self.assertFileEqual(LINES_ONE, tt2._limbo_name(trans_id)) |
|
129 |
||
130 |
def test_roundtrip_add_contents(self): |
|
131 |
LINES_ONE = 'a\nb\nc\nd\n' |
|
132 |
tree = self.make_branch_and_tree('tree') |
|
133 |
self.build_tree(['tree/foo']) |
|
134 |
tree.add('foo') |
|
135 |
os.unlink('tree/foo') |
|
136 |
tt, tt2 = self.get_two_previews(tree) |
|
137 |
trans_id = tt.trans_id_tree_path('foo') |
|
138 |
tt.create_file(LINES_ONE, trans_id) |
|
139 |
self.reserialize(tt, tt2) |
|
140 |
self.assertFileEqual(LINES_ONE, tt2._limbo_name(trans_id)) |
|
|
0.13.6
by Aaron Bentley
Fix get_parents_ functions |
141 |
|
142 |
def test_get_parents_lines(self): |
|
143 |
LINES_ONE = 'aa\nbb\ncc\ndd\n' |
|
144 |
LINES_TWO = 'z\nbb\nx\ndd\n' |
|
145 |
tree = self.make_branch_and_tree('tree') |
|
146 |
self.build_tree_contents([('tree/file', LINES_ONE)]) |
|
147 |
tree.add('file', 'file-id') |
|
148 |
tt, tt2 = self.get_two_previews(tree) |
|
149 |
trans_id = tt.trans_id_tree_path('file') |
|
150 |
self.assertEqual((['aa\n', 'bb\n', 'cc\n', 'dd\n'],), |
|
151 |
get_parents_lines(tt, trans_id)) |
|
152 |
||
153 |
def test_get_parents_texts(self): |
|
154 |
LINES_ONE = 'aa\nbb\ncc\ndd\n' |
|
155 |
LINES_TWO = 'z\nbb\nx\ndd\n' |
|
156 |
tree = self.make_branch_and_tree('tree') |
|
157 |
self.build_tree_contents([('tree/file', LINES_ONE)]) |
|
158 |
tree.add('file', 'file-id') |
|
159 |
tt, tt2 = self.get_two_previews(tree) |
|
160 |
trans_id = tt.trans_id_tree_path('file') |
|
161 |
self.assertEqual((LINES_ONE,), |
|
162 |
get_parents_texts(tt, trans_id)) |