1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# Copyright (C) 2008 Aaron Bentley <aaron@aaronbentley.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
from bzrlib import pack, transform
from bzrlib.plugins.shelf2.serialize_transform import (serialize, deserialize)
from bzrlib import tests
class TestSerializeTransform(tests.TestCaseWithTransport):
def get_two_previews(self, tree):
tt = transform.TransformPreview(tree)
self.addCleanup(tt.finalize)
tt2 = transform.TransformPreview(tree)
self.addCleanup(tt2.finalize)
return tt, tt2
@staticmethod
def reserialize(tt, tt2):
serializer = pack.ContainerSerialiser()
parser = pack.ContainerPushParser()
parser.accept_bytes(serializer.begin())
for bytes in serialize(tt, serializer):
parser.accept_bytes(bytes)
parser.accept_bytes(serializer.end())
deserialize(tt2, iter(parser.read_pending_records()))
def test_roundtrip_creation(self):
tree = self.make_branch_and_tree('.')
tt, tt2 = self.get_two_previews(tree)
tt.new_file(u'foo\u1234', tt.root, 'bar', 'baz', True)
tt.new_directory('qux', tt.root, 'quxx')
self.reserialize(tt, tt2)
self.assertEqual(3, tt2._id_number)
self.assertEqual({'new-1': u'foo\u1234',
'new-2': 'qux'}, tt2._new_name)
self.assertEqual({'new-1': 'baz', 'new-2': 'quxx'}, tt2._new_id)
self.assertEqual({'new-1': tt.root, 'new-2': tt.root}, tt2._new_parent)
self.assertEqual({'baz': 'new-1', 'quxx': 'new-2'}, tt2._r_new_id)
self.assertEqual({'new-1': True}, tt2._new_executability)
self.assertEqual({'new-1': 'file',
'new-2': 'directory'}, tt2._new_contents)
foo_limbo = open(tt2._limbo_name('new-1'), 'rb')
try:
foo_content = foo_limbo.read()
finally:
foo_limbo.close()
self.assertEqual('bar', foo_content)
def test_symlink_creation(self):
self.requireFeature(tests.SymlinkFeature)
tree = self.make_branch_and_tree('.')
tt, tt2 = self.get_two_previews(tree)
tt.new_symlink('foo', tt.root, 'bar')
self.reserialize(tt, tt2)
foo_content = os.readlink(tt2._limbo_name('new-1'))
self.assertEqual('bar', foo_content)
def test_roundtrip_destruction(self):
tree = self.make_branch_and_tree('.')
self.build_tree([u'foo\u1234', 'bar'])
tree.add([u'foo\u1234', 'bar'], ['foo-id', 'bar-id'])
tt, tt2 = self.get_two_previews(tree)
foo_trans_id = tt.trans_id_tree_file_id('foo-id')
tt.unversion_file(foo_trans_id)
bar_trans_id = tt.trans_id_tree_file_id('bar-id')
tt.delete_contents(bar_trans_id)
self.reserialize(tt, tt2)
self.assertEqual({u'foo\u1234': foo_trans_id,
'bar': bar_trans_id,
'': tt.root}, tt2._tree_path_ids)
self.assertEqual({foo_trans_id: u'foo\u1234',
bar_trans_id: 'bar',
tt.root: ''}, tt2._tree_id_paths)
self.assertEqual(set([foo_trans_id]), tt2._removed_id)
self.assertEqual(set([bar_trans_id]), tt2._removed_contents)
def test_roundtrip_missing(self):
tree = self.make_branch_and_tree('.')
tt, tt2 = self.get_two_previews(tree)
boo_trans_id = tt.trans_id_file_id('boo')
self.reserialize(tt, tt2)
self.assertEqual({'boo': boo_trans_id}, tt2._non_present_ids)
|