~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_testament.py

Fix BzrDir.create_workingtree for NULL_REVISION

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import os
22
22
from sha import sha
23
 
import sys
24
23
 
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
30
28
 
31
29
 
32
 
class TestamentTests(TestCaseInTempDir):
 
30
class TestamentSetup(TestCaseWithTransport):
33
31
 
34
32
    def setUp(self):
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'
41
40
                 timezone=0,
43
42
        self.build_tree_contents([('hello', 'contents of hello file'),
44
43
                             ('src/', ),
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)
 
50
        tt.apply()
 
51
        self.wt.commit(message='add files and directories',
49
52
                 timestamp=1129025483,
50
53
                 timezone=36000,
51
54
                 rev_id='test@user-2',
52
55
                 committer='test@user')
53
56
 
 
57
 
 
58
class TestamentTests(TestamentSetup):
 
59
 
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))
64
70
 
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)
71
77
 
 
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)
 
84
 
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)
80
93
 
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)
86
 
 
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)
92
102
 
93
103
    def test_testament_symlinks(self):
94
104
        """Testament containing symlink (where possible)"""
95
105
        if not has_symlinks():
96
106
            return
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,
101
111
                 timezone=36000,
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)
106
116
 
107
117
    def test_testament_revprops(self):
108
118
        """Testament to revision with extra properties"""
109
119
        props = dict(flavor='sour cherry\ncream cheese',
110
 
                     size='medium')
111
 
        self.b.working_tree().commit(message='revision with properties',
 
120
                     size='medium',
 
121
                     empty='',
 
122
                    )
 
123
        self.wt.commit(message='revision with properties',
112
124
                      timestamp=1129025493,
113
125
                      timezone=36000,
114
126
                      rev_id='test@user-3',
115
127
                      committer='test@user',
116
128
                      revprops=props)
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)
119
131
 
 
132
    def test_testament_unicode_commit_message(self):
 
133
        self.wt.commit(
 
134
            message=u'non-ascii commit \N{COPYRIGHT SIGN} me',
 
135
            timestamp=1129025493,
 
136
            timezone=36000,
 
137
            rev_id='test@user-3',
 
138
            committer='Erik B\xe5gfors <test@user>',
 
139
            revprops={'uni':u'\xb5'}
 
140
            )
 
141
        t = Testament.from_revision(self.b.repository, 'test@user-3')
 
142
        self.assertEqualDiff(
 
143
            SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text())
 
144
 
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)
127
152
                    
141
166
    test branch
142
167
"""
143
168
 
 
169
REV_1_STRICT_TESTAMENT = """\
 
170
bazaar-ng testament version 2.1
 
171
revision-id: test@user-1
 
172
committer: test@user
 
173
timestamp: 1129025423
 
174
timezone: 0
 
175
parents:
 
176
message:
 
177
  initial null commit
 
178
inventory:
 
179
properties:
 
180
  branch-nick:
 
181
    test branch
 
182
"""
 
183
 
 
184
 
144
185
REV_1_SHORT = """\
145
186
bazaar-ng testament short form 1
146
187
revision-id: test@user-1
148
189
""" % sha(REV_1_TESTAMENT).hexdigest()
149
190
 
150
191
 
 
192
REV_1_SHORT_STRICT = """\
 
193
bazaar-ng testament short form 2.1
 
194
revision-id: test@user-1
 
195
sha1: %s
 
196
""" % sha(REV_1_STRICT_TESTAMENT).hexdigest()
 
197
 
 
198
 
151
199
REV_2_TESTAMENT = """\
152
200
bazaar-ng testament version 1
153
201
revision-id: test@user-2
168
216
"""
169
217
 
170
218
 
 
219
REV_2_STRICT_TESTAMENT = """\
 
220
bazaar-ng testament version 2.1
 
221
revision-id: test@user-2
 
222
committer: test@user
 
223
timestamp: 1129025483
 
224
timezone: 36000
 
225
parents:
 
226
  test@user-1
 
227
message:
 
228
  add files and directories
 
229
inventory:
 
230
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
 
231
  directory src src-id test@user-2 no
 
232
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
 
233
properties:
 
234
  branch-nick:
 
235
    test branch
 
236
"""
 
237
 
 
238
 
171
239
REV_2_SHORT = """\
172
240
bazaar-ng testament short form 1
173
241
revision-id: test@user-2
175
243
""" % sha(REV_2_TESTAMENT).hexdigest()
176
244
 
177
245
 
 
246
REV_2_SHORT_STRICT = """\
 
247
bazaar-ng testament short form 2.1
 
248
revision-id: test@user-2
 
249
sha1: %s
 
250
""" % sha(REV_2_STRICT_TESTAMENT).hexdigest()
 
251
 
 
252
 
178
253
REV_PROPS_TESTAMENT = """\
179
254
bazaar-ng testament version 1
180
255
revision-id: test@user-3
192
267
properties:
193
268
  branch-nick:
194
269
    test branch
 
270
  empty:
195
271
  flavor:
196
272
    sour cherry
197
273
    cream cheese
219
295
  branch-nick:
220
296
    test branch
221
297
"""
 
298
 
 
299
 
 
300
SAMPLE_UNICODE_TESTAMENT = u"""\
 
301
bazaar-ng testament version 1
 
302
revision-id: test@user-3
 
303
committer: Erik B\xe5gfors <test@user>
 
304
timestamp: 1129025493
 
305
timezone: 36000
 
306
parents:
 
307
  test@user-2
 
308
message:
 
309
  non-ascii commit \N{COPYRIGHT SIGN} me
 
310
inventory:
 
311
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73
 
312
  directory src src-id
 
313
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24
 
314
properties:
 
315
  branch-nick:
 
316
    test branch
 
317
  uni:
 
318
    \xb5
 
319
"""