23
from bzrlib import osutils
24
from bzrlib.tests import SymlinkFeature, TestCaseWithTransport
25
from bzrlib.testament import Testament, StrictTestament, StrictTestament3
26
from bzrlib.transform import TreeTransform
23
from breezy import osutils
24
from breezy.tests import TestCaseWithTransport
25
from breezy.bzr.testament import (
30
from breezy.transform import TreeTransform
31
from breezy.tests.features import (
29
36
class TestamentSetup(TestCaseWithTransport):
32
39
super(TestamentSetup, self).setUp()
33
self.wt = self.make_branch_and_tree('.', format='dirstate-with-subtree')
34
self.wt.set_root_id('TREE_ROT')
40
self.wt = self.make_branch_and_tree('.', format='development-subtree')
41
self.wt.set_root_id(b'TREE_ROT')
35
42
b = self.b = self.wt.branch
36
43
b.nick = "test branch"
37
44
self.wt.commit(message='initial null commit',
38
committer='test@user',
39
timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
42
self.build_tree_contents([('hello', 'contents of hello file'),
44
('src/foo.c', 'int main()\n{\n}\n')])
45
committer='test@user',
46
timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
48
rev_id=b'test@user-1')
49
self.build_tree_contents([('hello', b'contents of hello file'),
51
('src/foo.c', b'int main()\n{\n}\n')])
45
52
self.wt.add(['hello', 'src', 'src/foo.c'],
46
['hello-id', 'src-id', 'foo.c-id'])
53
[b'hello-id', b'src-id', b'foo.c-id'])
47
54
tt = TreeTransform(self.wt)
48
55
trans_id = tt.trans_id_tree_path('hello')
49
56
tt.set_executability(True, trans_id)
51
58
self.wt.commit(message='add files and directories',
55
committer='test@user')
61
rev_id=b'test@user-2',
62
committer='test@user')
58
65
class TestamentTests(TestamentSetup):
69
76
def test_null_testament(self):
70
77
"""Testament for a revision with no contents."""
71
t = self.from_revision(self.b.repository, 'test@user-1')
78
t = self.from_revision(self.b.repository, b'test@user-1')
72
79
ass = self.assertTrue
73
80
eq = self.assertEqual
74
81
ass(isinstance(t, Testament))
75
eq(t.revision_id, 'test@user-1')
82
eq(t.revision_id, b'test@user-1')
76
83
eq(t.committer, 'test@user')
77
84
eq(t.timestamp, 1129025423)
80
87
def test_testment_text_form(self):
81
88
"""Conversion of testament to canonical text form."""
82
t = self.from_revision(self.b.repository, 'test@user-1')
89
t = self.from_revision(self.b.repository, b'test@user-1')
83
90
text_form = t.as_text()
84
self.log('testament text form:\n' + text_form)
91
self.log('testament text form:\n%s' % text_form)
85
92
self.assertEqualDiff(text_form, self.expected('rev_1'))
86
93
short_text_form = t.as_short_text()
87
94
self.assertEqualDiff(short_text_form, self.expected('rev_1_short'))
89
96
def test_testament_with_contents(self):
90
97
"""Testament containing a file and a directory."""
91
t = self.from_revision(self.b.repository, 'test@user-2')
98
t = self.from_revision(self.b.repository, b'test@user-2')
92
99
text_form = t.as_text()
93
self.log('testament text form:\n' + text_form)
100
self.log('testament text form:\n%s' % text_form)
94
101
self.assertEqualDiff(text_form, self.expected('rev_2'))
95
102
actual_short = t.as_short_text()
96
103
self.assertEqualDiff(actual_short, self.expected('rev_2_short'))
99
106
"""Testament containing symlink (where possible)"""
100
107
self.requireFeature(SymlinkFeature)
101
108
os.symlink('wibble/linktarget', 'link')
102
self.wt.add(['link'], ['link-id'])
109
self.wt.add(['link'], [b'link-id'])
103
110
self.wt.commit(message='add symlink',
104
timestamp=1129025493,
106
rev_id='test@user-3',
107
committer='test@user')
108
t = self.from_revision(self.b.repository, 'test@user-3')
111
timestamp=1129025493,
113
rev_id=b'test@user-3',
114
committer='test@user')
115
t = self.from_revision(self.b.repository, b'test@user-3')
109
116
self.assertEqualDiff(t.as_text(), self.expected('rev_3'))
111
118
def test_testament_revprops(self):
112
119
"""Testament to revision with extra properties"""
113
props = dict(flavor='sour cherry\ncream cheese',
120
props = {u'flavor': 'sour cherry\ncream cheese',
117
124
self.wt.commit(message='revision with properties',
118
timestamp=1129025493,
120
rev_id='test@user-3',
121
committer='test@user',
123
t = self.from_revision(self.b.repository, 'test@user-3')
125
timestamp=1129025493,
127
rev_id=b'test@user-3',
128
committer='test@user',
130
t = self.from_revision(self.b.repository, b'test@user-3')
124
131
self.assertEqualDiff(t.as_text(), self.expected('rev_props'))
126
133
def test_testament_unicode_commit_message(self):
128
135
message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
129
136
timestamp=1129025493,
131
rev_id='test@user-3',
132
committer='Erik B\xe5gfors <test@user>',
133
revprops={'uni':u'\xb5'}
138
rev_id=b'test@user-3',
139
committer=u'Erik B\xe5gfors <test@user>',
140
revprops={u'uni': u'\xb5'}
135
t = self.from_revision(self.b.repository, 'test@user-3')
142
t = self.from_revision(self.b.repository, b'test@user-3')
136
143
self.assertEqualDiff(
137
144
self.expected('sample_unicode').encode('utf-8'), t.as_text())
146
def test_from_tree(self):
147
tree = self.b.repository.revision_tree(b'test@user-2')
148
testament = self.testament_class().from_revision_tree(tree)
149
text_1 = testament.as_short_text()
150
text_2 = self.from_revision(self.b.repository,
151
b'test@user-2').as_short_text()
152
self.assertEqual(text_1, text_2)
139
154
def test___init__(self):
140
revision = self.b.repository.get_revision('test@user-2')
141
inventory = self.b.repository.get_inventory('test@user-2')
142
testament_1 = self.testament_class()(revision, inventory)
155
revision = self.b.repository.get_revision(b'test@user-2')
156
tree = self.b.repository.revision_tree(b'test@user-2')
157
testament_1 = self.testament_class()(revision, tree)
143
158
text_1 = testament_1.as_short_text()
144
159
text_2 = self.from_revision(self.b.repository,
145
'test@user-2').as_short_text()
160
b'test@user-2').as_short_text()
146
161
self.assertEqual(text_1, text_2)
158
173
return StrictTestament3
161
REV_1_TESTAMENT = """\
162
bazaar-ng testament version 1
163
revision-id: test@user-1
165
timestamp: 1129025423
177
REV_1_STRICT_TESTAMENT = """\
178
bazaar-ng testament version 2.1
179
revision-id: test@user-1
181
timestamp: 1129025423
193
REV_1_STRICT_TESTAMENT3 = """\
194
bazaar testament version 3 strict
195
revision-id: test@user-1
197
timestamp: 1129025423
203
directory . TREE_ROT test@user-1 no
211
bazaar-ng testament short form 1
212
revision-id: test@user-1
214
""" % osutils.sha(REV_1_TESTAMENT).hexdigest()
217
REV_1_SHORT_STRICT = """\
218
bazaar-ng testament short form 2.1
219
revision-id: test@user-1
221
""" % osutils.sha(REV_1_STRICT_TESTAMENT).hexdigest()
224
REV_1_SHORT_STRICT3 = """\
225
bazaar testament short form 3 strict
226
revision-id: test@user-1
228
""" % osutils.sha(REV_1_STRICT_TESTAMENT3).hexdigest()
231
REV_2_TESTAMENT = """\
232
bazaar-ng testament version 1
233
revision-id: test@user-2
235
timestamp: 1129025483
240
add files and directories
242
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
244
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
251
REV_2_STRICT_TESTAMENT = """\
252
bazaar-ng testament version 2.1
253
revision-id: test@user-2
255
timestamp: 1129025483
260
add files and directories
262
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
263
directory src src-id test@user-2 no
264
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
271
REV_2_STRICT_TESTAMENT3 = """\
272
bazaar testament version 3 strict
273
revision-id: test@user-2
275
timestamp: 1129025483
280
add files and directories
282
directory . TREE_ROT test@user-1 no
283
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
284
directory src src-id test@user-2 no
285
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
293
bazaar-ng testament short form 1
294
revision-id: test@user-2
296
""" % osutils.sha(REV_2_TESTAMENT).hexdigest()
299
REV_2_SHORT_STRICT = """\
300
bazaar-ng testament short form 2.1
301
revision-id: test@user-2
303
""" % osutils.sha(REV_2_STRICT_TESTAMENT).hexdigest()
306
REV_2_SHORT_STRICT3 = """\
307
bazaar testament short form 3 strict
308
revision-id: test@user-2
310
""" % osutils.sha(REV_2_STRICT_TESTAMENT3).hexdigest()
313
REV_PROPS_TESTAMENT = """\
314
bazaar-ng testament version 1
315
revision-id: test@user-3
317
timestamp: 1129025493
322
revision with properties
324
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
326
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
339
REV_PROPS_TESTAMENT_STRICT = """\
340
bazaar-ng testament version 2.1
341
revision-id: test@user-3
343
timestamp: 1129025493
348
revision with properties
350
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
351
directory src src-id test@user-2 no
352
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
365
REV_PROPS_TESTAMENT_STRICT3 = """\
366
bazaar testament version 3 strict
367
revision-id: test@user-3
369
timestamp: 1129025493
374
revision with properties
376
directory . TREE_ROT test@user-1 no
377
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
378
directory src src-id test@user-2 no
379
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
392
REV_3_TESTAMENT = """\
176
REV_1_TESTAMENT = b"""\
177
bazaar-ng testament version 1
178
revision-id: test@user-1
180
timestamp: 1129025423
192
REV_1_STRICT_TESTAMENT = b"""\
193
bazaar-ng testament version 2.1
194
revision-id: test@user-1
196
timestamp: 1129025423
208
REV_1_STRICT_TESTAMENT3 = b"""\
209
bazaar testament version 3 strict
210
revision-id: test@user-1
212
timestamp: 1129025423
218
directory . TREE_ROT test@user-1 no
226
bazaar-ng testament short form 1
227
revision-id: test@user-1
229
""" % osutils.sha_string(REV_1_TESTAMENT)
232
REV_1_SHORT_STRICT = b"""\
233
bazaar-ng testament short form 2.1
234
revision-id: test@user-1
236
""" % osutils.sha_string(REV_1_STRICT_TESTAMENT)
239
REV_1_SHORT_STRICT3 = b"""\
240
bazaar testament short form 3 strict
241
revision-id: test@user-1
243
""" % osutils.sha_string(REV_1_STRICT_TESTAMENT3)
246
REV_2_TESTAMENT = b"""\
247
bazaar-ng testament version 1
248
revision-id: test@user-2
250
timestamp: 1129025483
255
add files and directories
257
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
259
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
266
REV_2_STRICT_TESTAMENT = b"""\
267
bazaar-ng testament version 2.1
268
revision-id: test@user-2
270
timestamp: 1129025483
275
add files and directories
277
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
278
directory src src-id test@user-2 no
279
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
286
REV_2_STRICT_TESTAMENT3 = b"""\
287
bazaar testament version 3 strict
288
revision-id: test@user-2
290
timestamp: 1129025483
295
add files and directories
297
directory . TREE_ROT test@user-1 no
298
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
299
directory src src-id test@user-2 no
300
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
308
bazaar-ng testament short form 1
309
revision-id: test@user-2
311
""" % osutils.sha_string(REV_2_TESTAMENT)
314
REV_2_SHORT_STRICT = b"""\
315
bazaar-ng testament short form 2.1
316
revision-id: test@user-2
318
""" % osutils.sha_string(REV_2_STRICT_TESTAMENT)
321
REV_2_SHORT_STRICT3 = b"""\
322
bazaar testament short form 3 strict
323
revision-id: test@user-2
325
""" % osutils.sha_string(REV_2_STRICT_TESTAMENT3)
328
REV_PROPS_TESTAMENT = b"""\
329
bazaar-ng testament version 1
330
revision-id: test@user-3
332
timestamp: 1129025493
337
revision with properties
339
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
341
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
354
REV_PROPS_TESTAMENT_STRICT = b"""\
355
bazaar-ng testament version 2.1
356
revision-id: test@user-3
358
timestamp: 1129025493
363
revision with properties
365
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
366
directory src src-id test@user-2 no
367
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
380
REV_PROPS_TESTAMENT_STRICT3 = b"""\
381
bazaar testament version 3 strict
382
revision-id: test@user-3
384
timestamp: 1129025493
389
revision with properties
391
directory . TREE_ROT test@user-1 no
392
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
393
directory src src-id test@user-2 no
394
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
407
REV_3_TESTAMENT = b"""\
393
408
bazaar-ng testament version 1
394
409
revision-id: test@user-3
395
410
committer: test@user
524
Testament: { 'rev_1': REV_1_TESTAMENT,
525
'rev_1_short': REV_1_SHORT,
526
'rev_2': REV_2_TESTAMENT,
527
'rev_2_short': REV_2_SHORT,
528
'rev_3': REV_3_TESTAMENT,
529
'rev_props': REV_PROPS_TESTAMENT,
530
'sample_unicode': SAMPLE_UNICODE_TESTAMENT,
539
Testament: {'rev_1': REV_1_TESTAMENT,
540
'rev_1_short': REV_1_SHORT,
541
'rev_2': REV_2_TESTAMENT,
542
'rev_2_short': REV_2_SHORT,
543
'rev_3': REV_3_TESTAMENT,
544
'rev_props': REV_PROPS_TESTAMENT,
545
'sample_unicode': SAMPLE_UNICODE_TESTAMENT,
532
547
StrictTestament: {'rev_1': REV_1_STRICT_TESTAMENT,
533
548
'rev_1_short': REV_1_SHORT_STRICT,
534
549
'rev_2': REV_2_STRICT_TESTAMENT,
536
551
'rev_3': REV_3_TESTAMENT_STRICT,
537
552
'rev_props': REV_PROPS_TESTAMENT_STRICT,
538
553
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT,
540
555
StrictTestament3: {'rev_1': REV_1_STRICT_TESTAMENT3,
541
'rev_1_short': REV_1_SHORT_STRICT3,
542
'rev_2': REV_2_STRICT_TESTAMENT3,
543
'rev_2_short': REV_2_SHORT_STRICT3,
544
'rev_3': REV_3_TESTAMENT_STRICT3,
545
'rev_props': REV_PROPS_TESTAMENT_STRICT3,
546
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT3,
556
'rev_1_short': REV_1_SHORT_STRICT3,
557
'rev_2': REV_2_STRICT_TESTAMENT3,
558
'rev_2_short': REV_2_SHORT_STRICT3,
559
'rev_3': REV_3_TESTAMENT_STRICT3,
560
'rev_props': REV_PROPS_TESTAMENT_STRICT3,
561
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT3,