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, StrictTestament3
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,
150
'test@user-2').as_short_text()
151
self.assertEqual(testament_1, testament_2)
143
testament_1 = self.testament_class()(revision, inventory)
144
text_1 = testament_1.as_short_text()
145
text_2 = self.from_revision(self.b.repository,
146
'test@user-2').as_short_text()
147
self.assertEqual(text_1, text_2)
150
class TestamentTestsStrict(TestamentTests):
152
def testament_class(self):
153
return StrictTestament
156
class TestamentTestsStrict2(TestamentTests):
158
def testament_class(self):
159
return StrictTestament3
154
162
REV_1_TESTAMENT = """\
155
163
bazaar-ng testament version 1
156
164
revision-id: test@user-1
272
REV_2_STRICT_TESTAMENT3 = """\
273
bazaar testament version 3 strict
274
revision-id: test@user-2
276
timestamp: 1129025483
281
add files and directories
283
directory . TREE_ROOT test@user-2 no
284
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
285
directory src src-id test@user-2 no
286
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
239
293
REV_2_SHORT = """\
240
294
bazaar-ng testament short form 1
241
295
revision-id: test@user-2
250
304
""" % sha(REV_2_STRICT_TESTAMENT).hexdigest()
307
REV_2_SHORT_STRICT3 = """\
308
bazaar testament short form 3 strict
309
revision-id: test@user-2
311
""" % sha(REV_2_STRICT_TESTAMENT3).hexdigest()
253
314
REV_PROPS_TESTAMENT = """\
254
315
bazaar-ng testament version 1
255
316
revision-id: test@user-3
340
REV_PROPS_TESTAMENT_STRICT = """\
341
bazaar-ng testament version 2.1
342
revision-id: test@user-3
344
timestamp: 1129025493
349
revision with properties
351
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
352
directory src src-id test@user-2 no
353
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
366
REV_PROPS_TESTAMENT_STRICT3 = """\
367
bazaar testament version 3 strict
368
revision-id: test@user-3
370
timestamp: 1129025493
375
revision with properties
377
directory . TREE_ROOT test@user-3 no
378
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
379
directory src src-id test@user-2 no
380
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
279
393
REV_3_TESTAMENT = """\
280
394
bazaar-ng testament version 1
281
395
revision-id: test@user-3
414
REV_3_TESTAMENT_STRICT = """\
415
bazaar-ng testament version 2.1
416
revision-id: test@user-3
418
timestamp: 1129025493
425
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
426
symlink link link-id wibble/linktarget test@user-3 no
427
directory src src-id test@user-2 no
428
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
435
REV_3_TESTAMENT_STRICT3 = """\
436
bazaar testament version 3 strict
437
revision-id: test@user-3
439
timestamp: 1129025493
446
directory . TREE_ROOT test@user-3 no
447
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
448
symlink link link-id wibble/linktarget test@user-3 no
449
directory src src-id test@user-2 no
450
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
300
457
SAMPLE_UNICODE_TESTAMENT = u"""\
301
458
bazaar-ng testament version 1
302
459
revision-id: test@user-3
479
SAMPLE_UNICODE_TESTAMENT_STRICT = u"""\
480
bazaar-ng testament version 2.1
481
revision-id: test@user-3
482
committer: Erik B\xe5gfors <test@user>
483
timestamp: 1129025493
488
non-ascii commit \N{COPYRIGHT SIGN} me
490
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
491
directory src src-id test@user-2 no
492
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
501
SAMPLE_UNICODE_TESTAMENT_STRICT3 = u"""\
502
bazaar testament version 3 strict
503
revision-id: test@user-3
504
committer: Erik B\xe5gfors <test@user>
505
timestamp: 1129025493
510
non-ascii commit \N{COPYRIGHT SIGN} me
512
directory . TREE_ROOT test@user-3 no
513
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
514
directory src src-id test@user-2 no
515
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
525
Testament: { 'rev_1': REV_1_TESTAMENT,
526
'rev_1_short': REV_1_SHORT,
527
'rev_2': REV_2_TESTAMENT,
528
'rev_2_short': REV_2_SHORT,
529
'rev_3': REV_3_TESTAMENT,
530
'rev_props': REV_PROPS_TESTAMENT,
531
'sample_unicode': SAMPLE_UNICODE_TESTAMENT,
533
StrictTestament: {'rev_1': REV_1_STRICT_TESTAMENT,
534
'rev_1_short': REV_1_SHORT_STRICT,
535
'rev_2': REV_2_STRICT_TESTAMENT,
536
'rev_2_short': REV_2_SHORT_STRICT,
537
'rev_3': REV_3_TESTAMENT_STRICT,
538
'rev_props': REV_PROPS_TESTAMENT_STRICT,
539
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT,
541
StrictTestament3: {'rev_1': REV_1_STRICT_TESTAMENT3,
542
'rev_1_short': REV_1_SHORT_STRICT3,
543
'rev_2': REV_2_STRICT_TESTAMENT3,
544
'rev_2_short': REV_2_SHORT_STRICT3,
545
'rev_3': REV_3_TESTAMENT_STRICT3,
546
'rev_props': REV_PROPS_TESTAMENT_STRICT3,
547
'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT3,