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