22
22
from sha import sha
24
from bzrlib.tests import TestCaseWithTransport
25
from bzrlib.testament import Testament, StrictTestament, StrictTestament3
26
from bzrlib.transform import TreeTransform
25
from bzrlib.tests import TestCaseInTempDir
26
from bzrlib.branch import Branch
27
from bzrlib.testament import Testament
28
from bzrlib.trace import mutter
27
29
from bzrlib.osutils import has_symlinks
30
class TestamentSetup(TestCaseWithTransport):
32
class TestamentTests(TestCaseInTempDir):
33
super(TestamentSetup, self).setUp()
34
self.wt = self.make_branch_and_tree('.')
35
b = self.b = self.wt.branch
35
super(TestamentTests, self).setUp()
36
b = self.b = Branch.initialize(u'.')
36
37
b.nick = "test branch"
37
self.wt.commit(message='initial null commit',
38
b.working_tree().commit(message='initial null commit',
38
39
committer='test@user',
39
40
timestamp=1129025423, # 'Tue Oct 11 20:10:23 2005'
42
43
self.build_tree_contents([('hello', 'contents of hello file'),
44
45
('src/foo.c', 'int main()\n{\n}\n')])
45
self.wt.add(['hello', 'src', 'src/foo.c'],
46
b.working_tree().add(['hello', 'src', 'src/foo.c'],
46
47
['hello-id', 'src-id', 'foo.c-id'])
47
tt = TreeTransform(self.wt)
48
trans_id = tt.trans_id_tree_path('hello')
49
tt.set_executability(True, trans_id)
51
self.wt.commit(message='add files and directories',
48
b.working_tree().commit(message='add files and directories',
52
49
timestamp=1129025483,
54
51
rev_id='test@user-2',
55
52
committer='test@user')
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)
69
54
def test_null_testament(self):
70
55
"""Testament for a revision with no contents."""
71
t = self.from_revision(self.b.repository, 'test@user-1')
56
t = Testament.from_revision(self.b, 'test@user-1')
72
57
ass = self.assertTrue
73
58
eq = self.assertEqual
74
59
ass(isinstance(t, Testament))
80
65
def test_testment_text_form(self):
81
66
"""Conversion of testament to canonical text form."""
82
t = self.from_revision(self.b.repository, 'test@user-1')
67
t = Testament.from_revision(self.b, 'test@user-1')
83
68
text_form = t.as_text()
84
69
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'))
70
self.assertEqual(text_form, REV_1_TESTAMENT)
89
72
def test_testament_with_contents(self):
90
73
"""Testament containing a file and a directory."""
91
t = self.from_revision(self.b.repository, 'test@user-2')
74
t = Testament.from_revision(self.b, 'test@user-2')
92
75
text_form = t.as_text()
93
76
self.log('testament text form:\n' + text_form)
94
self.assertEqualDiff(text_form, self.expected('rev_2'))
77
self.assertEqualDiff(text_form, REV_2_TESTAMENT)
95
78
actual_short = t.as_short_text()
96
self.assertEqualDiff(actual_short, self.expected('rev_2_short'))
79
self.assertEqualDiff(actual_short, REV_2_SHORT)
81
def test_testament_command(self):
82
"""Testament containing a file and a directory."""
83
out, err = self.run_bzr_captured(['testament', '--long'])
84
self.assertEqualDiff(err, '')
85
self.assertEqualDiff(out, REV_2_TESTAMENT)
87
def test_testament_command_2(self):
88
"""Command getting short testament of previous version."""
89
out, err = self.run_bzr_captured(['testament', '-r1'])
90
self.assertEqualDiff(err, '')
91
self.assertEqualDiff(out, REV_1_SHORT)
98
93
def test_testament_symlinks(self):
99
94
"""Testament containing symlink (where possible)"""
100
95
if not has_symlinks():
102
97
os.symlink('wibble/linktarget', 'link')
103
self.wt.add(['link'], ['link-id'])
104
self.wt.commit(message='add symlink',
98
self.b.working_tree().add(['link'], ['link-id'])
99
self.b.working_tree().commit(message='add symlink',
105
100
timestamp=1129025493,
107
102
rev_id='test@user-3',
108
103
committer='test@user')
109
t = self.from_revision(self.b.repository, 'test@user-3')
110
self.assertEqualDiff(t.as_text(), self.expected('rev_3'))
104
t = Testament.from_revision(self.b, 'test@user-3')
105
self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
112
107
def test_testament_revprops(self):
113
108
"""Testament to revision with extra properties"""
114
109
props = dict(flavor='sour cherry\ncream cheese',
118
self.wt.commit(message='revision with properties',
111
self.b.working_tree().commit(message='revision with properties',
119
112
timestamp=1129025493,
121
114
rev_id='test@user-3',
122
115
committer='test@user',
124
t = self.from_revision(self.b.repository, 'test@user-3')
125
self.assertEqualDiff(t.as_text(), self.expected('rev_props'))
127
def test_testament_unicode_commit_message(self):
129
message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
130
timestamp=1129025493,
132
rev_id='test@user-3',
133
committer='Erik B\xe5gfors <test@user>',
134
revprops={'uni':u'\xb5'}
136
t = self.from_revision(self.b.repository, 'test@user-3')
137
self.assertEqualDiff(
138
self.expected('sample_unicode').encode('utf-8'), t.as_text())
117
t = Testament.from_revision(self.b, 'test@user-3')
118
self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
140
120
def test___init__(self):
141
revision = self.b.repository.get_revision('test@user-2')
142
inventory = self.b.repository.get_inventory('test@user-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)
121
revision = self.b.get_revision('test@user-2')
122
inventory = self.b.get_inventory('test@user-2')
123
testament_1 = Testament(revision, inventory).as_short_text()
124
testament_2 = Testament.from_revision(self.b,
125
'test@user-2').as_short_text()
126
self.assertEqual(testament_1, testament_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
162
129
REV_1_TESTAMENT = """\
163
130
bazaar-ng testament version 1
164
131
revision-id: test@user-1
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
457
SAMPLE_UNICODE_TESTAMENT = u"""\
458
bazaar-ng testament version 1
459
revision-id: test@user-3
460
committer: Erik B\xe5gfors <test@user>
461
timestamp: 1129025493
466
non-ascii commit \N{COPYRIGHT SIGN} me
468
file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
470
file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
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,