22
22
from sha import sha
24
24
from bzrlib.tests import TestCaseWithTransport
25
from bzrlib.testament import Testament, StrictTestament
25
from bzrlib.testament import Testament, StrictTestament, StrictTestament2
26
26
from bzrlib.transform import TreeTransform
27
27
from bzrlib.osutils import has_symlinks
58
58
class TestamentTests(TestamentSetup):
60
def testament_class(self):
63
def expected(self, key):
64
return texts[self.testament_class()][key]
66
def from_revision(self, repository, revision_id):
67
return self.testament_class().from_revision(repository, revision_id)
60
69
def test_null_testament(self):
61
70
"""Testament for a revision with no contents."""
62
t = Testament.from_revision(self.b.repository, 'test@user-1')
71
t = self.from_revision(self.b.repository, 'test@user-1')
63
72
ass = self.assertTrue
64
73
eq = self.assertEqual
65
74
ass(isinstance(t, Testament))
71
80
def test_testment_text_form(self):
72
81
"""Conversion of testament to canonical text form."""
73
t = Testament.from_revision(self.b.repository, 'test@user-1')
74
text_form = t.as_text()
75
self.log('testament text form:\n' + text_form)
76
self.assertEqual(text_form, REV_1_TESTAMENT)
78
def test_strict_testment_text_form(self):
79
"""Conversion of testament to canonical text form."""
80
t = StrictTestament.from_revision(self.b.repository, 'test@user-1')
81
text_form = t.as_text()
82
self.log('testament text form:\n' + text_form)
83
self.assertEqualDiff(text_form, REV_1_STRICT_TESTAMENT)
82
t = self.from_revision(self.b.repository, 'test@user-1')
83
text_form = t.as_text()
84
self.log('testament text form:\n' + text_form)
85
self.assertEqualDiff(text_form, self.expected('rev_1'))
86
short_text_form = t.as_short_text()
87
self.assertEqualDiff(short_text_form, self.expected('rev_1_short'))
85
89
def test_testament_with_contents(self):
86
90
"""Testament containing a file and a directory."""
87
t = Testament.from_revision(self.b.repository, 'test@user-2')
88
text_form = t.as_text()
89
self.log('testament text form:\n' + text_form)
90
self.assertEqualDiff(text_form, REV_2_TESTAMENT)
91
actual_short = t.as_short_text()
92
self.assertEqualDiff(actual_short, REV_2_SHORT)
94
def test_strict_testament_with_contents(self):
95
"""Testament containing a file and a directory."""
96
t = StrictTestament.from_revision(self.b.repository, 'test@user-2')
97
text_form = t.as_text()
98
self.log('testament text form:\n' + text_form)
99
self.assertEqualDiff(text_form, REV_2_STRICT_TESTAMENT)
100
actual_short = t.as_short_text()
101
self.assertEqualDiff(actual_short, REV_2_SHORT_STRICT)
91
t = self.from_revision(self.b.repository, 'test@user-2')
92
text_form = t.as_text()
93
self.log('testament text form:\n' + text_form)
94
self.assertEqualDiff(text_form, self.expected('rev_2'))
95
actual_short = t.as_short_text()
96
self.assertEqualDiff(actual_short, self.expected('rev_2_short'))
103
98
def test_testament_symlinks(self):
104
99
"""Testament containing symlink (where possible)"""
112
107
rev_id='test@user-3',
113
108
committer='test@user')
114
t = Testament.from_revision(self.b.repository, 'test@user-3')
115
self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
109
t = self.from_revision(self.b.repository, 'test@user-3')
110
self.assertEqualDiff(t.as_text(), self.expected('rev_3'))
117
112
def test_testament_revprops(self):
118
113
"""Testament to revision with extra properties"""
126
121
rev_id='test@user-3',
127
122
committer='test@user',
129
t = Testament.from_revision(self.b.repository, 'test@user-3')
130
self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
124
t = self.from_revision(self.b.repository, 'test@user-3')
125
self.assertEqualDiff(t.as_text(), self.expected('rev_props'))
132
127
def test_testament_unicode_commit_message(self):
138
133
committer='Erik B\xe5gfors <test@user>',
139
134
revprops={'uni':u'\xb5'}
141
t = Testament.from_revision(self.b.repository, 'test@user-3')
136
t = self.from_revision(self.b.repository, 'test@user-3')
142
137
self.assertEqualDiff(
143
SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text())
138
self.expected('sample_unicode').encode('utf-8'), t.as_text())
145
140
def test___init__(self):
146
141
revision = self.b.repository.get_revision('test@user-2')
147
142
inventory = self.b.repository.get_inventory('test@user-2')
148
testament_1 = Testament(revision, inventory).as_short_text()
149
testament_2 = Testament.from_revision(self.b.repository,
143
testament_1 = self.testament_class()(revision, inventory).as_short_text()
144
testament_2 = self.from_revision(self.b.repository,
150
145
'test@user-2').as_short_text()
151
146
self.assertEqual(testament_1, testament_2)
149
class TestamentTestsStrict(TestamentTests):
151
def testament_class(self):
152
return StrictTestament
155
class TestamentTestsStrict2(TestamentTests):
157
def testament_class(self):
158
return StrictTestament2
154
161
REV_1_TESTAMENT = """\
155
162
bazaar-ng testament version 1
156
163
revision-id: test@user-1
268
REV_2_STRICT_TESTAMENT2 = """\
269
bazaar-ng testament version 3 strict
270
revision-id: test@user-2
272
timestamp: 1129025483
277
add files and directories
279
directory . TREE_ROOT test@user-2 no
280
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
281
directory src src-id test@user-2 no
282
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
239
288
REV_2_SHORT = """\
240
289
bazaar-ng testament short form 1
241
290
revision-id: test@user-2
250
299
""" % sha(REV_2_STRICT_TESTAMENT).hexdigest()
302
REV_2_SHORT_STRICT2 = """\
303
bazaar-ng testament short form 3 strict
304
revision-id: test@user-2
306
""" % sha(REV_2_STRICT_TESTAMENT2).hexdigest()
253
309
REV_PROPS_TESTAMENT = """\
254
310
bazaar-ng testament version 1
255
311
revision-id: test@user-3
335
REV_PROPS_TESTAMENT_STRICT = """\
336
bazaar-ng testament version 2.1
337
revision-id: test@user-3
339
timestamp: 1129025493
344
revision with properties
346
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
347
directory src src-id test@user-2 no
348
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
361
REV_PROPS_TESTAMENT_STRICT2 = """\
362
bazaar-ng testament version 3 strict
363
revision-id: test@user-3
365
timestamp: 1129025493
370
revision with properties
372
directory . TREE_ROOT test@user-3 no
373
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
374
directory src src-id test@user-2 no
375
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
279
388
REV_3_TESTAMENT = """\
280
389
bazaar-ng testament version 1
281
390
revision-id: test@user-3
409
REV_3_TESTAMENT_STRICT = """\
410
bazaar-ng testament version 2.1
411
revision-id: test@user-3
413
timestamp: 1129025493
420
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
421
symlink link link-id wibble/linktarget test@user-3 no
422
directory src src-id test@user-2 no
423
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
430
REV_3_TESTAMENT_STRICT2 = """\
431
bazaar-ng testament version 3 strict
432
revision-id: test@user-3
434
timestamp: 1129025493
441
directory . TREE_ROOT test@user-3 no
442
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
443
symlink link link-id wibble/linktarget test@user-3 no
444
directory src src-id test@user-2 no
445
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
300
451
SAMPLE_UNICODE_TESTAMENT = u"""\
301
452
bazaar-ng testament version 1
302
453
revision-id: test@user-3
473
SAMPLE_UNICODE_TESTAMENT_STRICT = u"""\
474
bazaar-ng testament version 2.1
475
revision-id: test@user-3
476
committer: Erik B\xe5gfors <test@user>
477
timestamp: 1129025493
482
non-ascii commit \N{COPYRIGHT SIGN} me
484
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
485
directory src src-id test@user-2 no
486
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
495
SAMPLE_UNICODE_TESTAMENT_STRICT2 = u"""\
496
bazaar-ng testament version 3 strict
497
revision-id: test@user-3
498
committer: Erik B\xe5gfors <test@user>
499
timestamp: 1129025493
504
non-ascii commit \N{COPYRIGHT SIGN} me
506
directory . TREE_ROOT test@user-3 no
507
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
508
directory src src-id test@user-2 no
509
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
519
Testament: { 'rev_1': REV_1_TESTAMENT,
520
'rev_1_short': REV_1_SHORT,
521
'rev_2': REV_2_TESTAMENT,
522
'rev_2_short': REV_2_SHORT,
523
'rev_3': REV_3_TESTAMENT,
524
'rev_props': REV_PROPS_TESTAMENT,
525
'sample_unicode': SAMPLE_UNICODE_TESTAMENT,
527
StrictTestament: {'rev_1': REV_1_STRICT_TESTAMENT,
528
'rev_1_short': REV_1_SHORT_STRICT,
529
'rev_2': REV_2_STRICT_TESTAMENT,
530
'rev_2_short': REV_2_SHORT_STRICT,
531
'rev_3': REV_3_TESTAMENT_STRICT,
532
'rev_props': REV_PROPS_TESTAMENT_STRICT,
533
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT,
535
StrictTestament2: {'rev_1': REV_1_STRICT_TESTAMENT2,
536
'rev_1_short': REV_1_SHORT_STRICT2,
537
'rev_2': REV_2_STRICT_TESTAMENT2,
538
'rev_2_short': REV_2_SHORT_STRICT2,
539
'rev_3': REV_3_TESTAMENT_STRICT2,
540
'rev_props': REV_PROPS_TESTAMENT_STRICT2,
541
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT2,