22
22
from sha import sha
25
24
from bzrlib.tests import TestCaseWithTransport
26
from bzrlib.branch import Branch
27
from bzrlib.testament import Testament
28
from bzrlib.trace import mutter
25
from bzrlib.testament import Testament, StrictTestament, StrictTestament3
26
from bzrlib.transform import TreeTransform
29
27
from bzrlib.osutils import has_symlinks
32
class TestamentTests(TestCaseWithTransport):
30
class TestamentSetup(TestCaseWithTransport):
35
super(TestamentTests, self).setUp()
36
self.wt = self.make_branch_and_tree('.')
33
super(TestamentSetup, self).setUp()
34
self.wt = self.make_branch_and_tree('.', format='dirstate-with-subtree')
35
self.wt.set_root_id('TREE_ROT')
37
36
b = self.b = self.wt.branch
38
37
b.nick = "test branch"
39
38
self.wt.commit(message='initial null commit',
46
45
('src/foo.c', 'int main()\n{\n}\n')])
47
46
self.wt.add(['hello', 'src', 'src/foo.c'],
48
47
['hello-id', 'src-id', 'foo.c-id'])
48
tt = TreeTransform(self.wt)
49
trans_id = tt.trans_id_tree_path('hello')
50
tt.set_executability(True, trans_id)
49
52
self.wt.commit(message='add files and directories',
50
53
timestamp=1129025483,
52
55
rev_id='test@user-2',
53
56
committer='test@user')
59
class TestamentTests(TestamentSetup):
61
def testament_class(self):
64
def expected(self, key):
65
return texts[self.testament_class()][key]
67
def from_revision(self, repository, revision_id):
68
return self.testament_class().from_revision(repository, revision_id)
55
70
def test_null_testament(self):
56
71
"""Testament for a revision with no contents."""
57
t = Testament.from_revision(self.b.repository, 'test@user-1')
72
t = self.from_revision(self.b.repository, 'test@user-1')
58
73
ass = self.assertTrue
59
74
eq = self.assertEqual
60
75
ass(isinstance(t, Testament))
66
81
def test_testment_text_form(self):
67
82
"""Conversion of testament to canonical text form."""
68
t = Testament.from_revision(self.b.repository, 'test@user-1')
83
t = self.from_revision(self.b.repository, 'test@user-1')
69
84
text_form = t.as_text()
70
85
self.log('testament text form:\n' + text_form)
71
self.assertEqual(text_form, REV_1_TESTAMENT)
86
self.assertEqualDiff(text_form, self.expected('rev_1'))
87
short_text_form = t.as_short_text()
88
self.assertEqualDiff(short_text_form, self.expected('rev_1_short'))
73
90
def test_testament_with_contents(self):
74
91
"""Testament containing a file and a directory."""
75
t = Testament.from_revision(self.b.repository, 'test@user-2')
92
t = self.from_revision(self.b.repository, 'test@user-2')
76
93
text_form = t.as_text()
77
94
self.log('testament text form:\n' + text_form)
78
self.assertEqualDiff(text_form, REV_2_TESTAMENT)
95
self.assertEqualDiff(text_form, self.expected('rev_2'))
79
96
actual_short = t.as_short_text()
80
self.assertEqualDiff(actual_short, REV_2_SHORT)
82
def test_testament_command(self):
83
"""Testament containing a file and a directory."""
84
out, err = self.run_bzr_captured(['testament', '--long'])
85
self.assertEqualDiff(err, '')
86
self.assertEqualDiff(out, REV_2_TESTAMENT)
88
def test_testament_command_2(self):
89
"""Command getting short testament of previous version."""
90
out, err = self.run_bzr_captured(['testament', '-r1'])
91
self.assertEqualDiff(err, '')
92
self.assertEqualDiff(out, REV_1_SHORT)
97
self.assertEqualDiff(actual_short, self.expected('rev_2_short'))
94
99
def test_testament_symlinks(self):
95
100
"""Testament containing symlink (where possible)"""
103
108
rev_id='test@user-3',
104
109
committer='test@user')
105
t = Testament.from_revision(self.b.repository, 'test@user-3')
106
self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
110
t = self.from_revision(self.b.repository, 'test@user-3')
111
self.assertEqualDiff(t.as_text(), self.expected('rev_3'))
108
113
def test_testament_revprops(self):
109
114
"""Testament to revision with extra properties"""
110
115
props = dict(flavor='sour cherry\ncream cheese',
112
119
self.wt.commit(message='revision with properties',
113
120
timestamp=1129025493,
115
122
rev_id='test@user-3',
116
123
committer='test@user',
118
t = Testament.from_revision(self.b.repository, 'test@user-3')
119
self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
125
t = self.from_revision(self.b.repository, 'test@user-3')
126
self.assertEqualDiff(t.as_text(), self.expected('rev_props'))
121
128
def test_testament_unicode_commit_message(self):
124
131
timestamp=1129025493,
126
133
rev_id='test@user-3',
127
committer='test@user')
128
t = Testament.from_revision(self.b.repository, 'test@user-3')
134
committer='Erik B\xe5gfors <test@user>',
135
revprops={'uni':u'\xb5'}
137
t = self.from_revision(self.b.repository, 'test@user-3')
129
138
self.assertEqualDiff(
130
SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text())
139
self.expected('sample_unicode').encode('utf-8'), t.as_text())
132
141
def test___init__(self):
133
142
revision = self.b.repository.get_revision('test@user-2')
134
143
inventory = self.b.repository.get_inventory('test@user-2')
135
testament_1 = Testament(revision, inventory).as_short_text()
136
testament_2 = Testament.from_revision(self.b.repository,
137
'test@user-2').as_short_text()
138
self.assertEqual(testament_1, testament_2)
144
testament_1 = self.testament_class()(revision, inventory)
145
text_1 = testament_1.as_short_text()
146
text_2 = self.from_revision(self.b.repository,
147
'test@user-2').as_short_text()
148
self.assertEqual(text_1, text_2)
151
class TestamentTestsStrict(TestamentTests):
153
def testament_class(self):
154
return StrictTestament
157
class TestamentTestsStrict2(TestamentTests):
159
def testament_class(self):
160
return StrictTestament3
141
163
REV_1_TESTAMENT = """\
142
164
bazaar-ng testament version 1
143
165
revision-id: test@user-1
179
REV_1_STRICT_TESTAMENT = """\
180
bazaar-ng testament version 2.1
181
revision-id: test@user-1
183
timestamp: 1129025423
195
REV_1_STRICT_TESTAMENT3 = """\
196
bazaar testament version 3 strict
197
revision-id: test@user-1
199
timestamp: 1129025423
205
directory . TREE_ROT test@user-1 no
156
212
REV_1_SHORT = """\
157
213
bazaar-ng testament short form 1
158
214
revision-id: test@user-1
160
216
""" % sha(REV_1_TESTAMENT).hexdigest()
219
REV_1_SHORT_STRICT = """\
220
bazaar-ng testament short form 2.1
221
revision-id: test@user-1
223
""" % sha(REV_1_STRICT_TESTAMENT).hexdigest()
226
REV_1_SHORT_STRICT3 = """\
227
bazaar testament short form 3 strict
228
revision-id: test@user-1
230
""" % sha(REV_1_STRICT_TESTAMENT3).hexdigest()
163
233
REV_2_TESTAMENT = """\
164
234
bazaar-ng testament version 1
165
235
revision-id: test@user-2
253
REV_2_STRICT_TESTAMENT = """\
254
bazaar-ng testament version 2.1
255
revision-id: test@user-2
257
timestamp: 1129025483
262
add files and directories
264
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
265
directory src src-id test@user-2 no
266
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
273
REV_2_STRICT_TESTAMENT3 = """\
274
bazaar testament version 3 strict
275
revision-id: test@user-2
277
timestamp: 1129025483
282
add files and directories
284
directory . TREE_ROT test@user-1 no
285
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
286
directory src src-id test@user-2 no
287
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
183
294
REV_2_SHORT = """\
184
295
bazaar-ng testament short form 1
185
296
revision-id: test@user-2
187
298
""" % sha(REV_2_TESTAMENT).hexdigest()
301
REV_2_SHORT_STRICT = """\
302
bazaar-ng testament short form 2.1
303
revision-id: test@user-2
305
""" % sha(REV_2_STRICT_TESTAMENT).hexdigest()
308
REV_2_SHORT_STRICT3 = """\
309
bazaar testament short form 3 strict
310
revision-id: test@user-2
312
""" % sha(REV_2_STRICT_TESTAMENT3).hexdigest()
190
315
REV_PROPS_TESTAMENT = """\
191
316
bazaar-ng testament version 1
192
317
revision-id: test@user-3
341
REV_PROPS_TESTAMENT_STRICT = """\
342
bazaar-ng testament version 2.1
343
revision-id: test@user-3
345
timestamp: 1129025493
350
revision with properties
352
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
353
directory src src-id test@user-2 no
354
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
367
REV_PROPS_TESTAMENT_STRICT3 = """\
368
bazaar testament version 3 strict
369
revision-id: test@user-3
371
timestamp: 1129025493
376
revision with properties
378
directory . TREE_ROT test@user-1 no
379
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
380
directory src src-id test@user-2 no
381
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
415
REV_3_TESTAMENT_STRICT = """\
416
bazaar-ng testament version 2.1
417
revision-id: test@user-3
419
timestamp: 1129025493
426
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
427
symlink link link-id wibble/linktarget test@user-3 no
428
directory src src-id test@user-2 no
429
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
436
REV_3_TESTAMENT_STRICT3 = """\
437
bazaar testament version 3 strict
438
revision-id: test@user-3
440
timestamp: 1129025493
447
directory . TREE_ROT test@user-1 no
448
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
449
symlink link link-id wibble/linktarget test@user-3 no
450
directory src src-id test@user-2 no
451
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
236
458
SAMPLE_UNICODE_TESTAMENT = u"""\
237
459
bazaar-ng testament version 1
238
460
revision-id: test@user-3
461
committer: Erik B\xe5gfors <test@user>
240
462
timestamp: 1129025493
480
SAMPLE_UNICODE_TESTAMENT_STRICT = u"""\
481
bazaar-ng testament version 2.1
482
revision-id: test@user-3
483
committer: Erik B\xe5gfors <test@user>
484
timestamp: 1129025493
489
non-ascii commit \N{COPYRIGHT SIGN} me
491
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
492
directory src src-id test@user-2 no
493
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
502
SAMPLE_UNICODE_TESTAMENT_STRICT3 = u"""\
503
bazaar testament version 3 strict
504
revision-id: test@user-3
505
committer: Erik B\xe5gfors <test@user>
506
timestamp: 1129025493
511
non-ascii commit \N{COPYRIGHT SIGN} me
513
directory . TREE_ROT test@user-1 no
514
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
515
directory src src-id test@user-2 no
516
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
526
Testament: { 'rev_1': REV_1_TESTAMENT,
527
'rev_1_short': REV_1_SHORT,
528
'rev_2': REV_2_TESTAMENT,
529
'rev_2_short': REV_2_SHORT,
530
'rev_3': REV_3_TESTAMENT,
531
'rev_props': REV_PROPS_TESTAMENT,
532
'sample_unicode': SAMPLE_UNICODE_TESTAMENT,
534
StrictTestament: {'rev_1': REV_1_STRICT_TESTAMENT,
535
'rev_1_short': REV_1_SHORT_STRICT,
536
'rev_2': REV_2_STRICT_TESTAMENT,
537
'rev_2_short': REV_2_SHORT_STRICT,
538
'rev_3': REV_3_TESTAMENT_STRICT,
539
'rev_props': REV_PROPS_TESTAMENT_STRICT,
540
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT,
542
StrictTestament3: {'rev_1': REV_1_STRICT_TESTAMENT3,
543
'rev_1_short': REV_1_SHORT_STRICT3,
544
'rev_2': REV_2_STRICT_TESTAMENT3,
545
'rev_2_short': REV_2_SHORT_STRICT3,
546
'rev_3': REV_3_TESTAMENT_STRICT3,
547
'rev_props': REV_PROPS_TESTAMENT_STRICT3,
548
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT3,