~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_testament.py

  • Committer: Robert Collins
  • Date: 2006-03-04 02:30:17 UTC
  • mto: (1594.2.4 integration)
  • mto: This revision was merged to the branch mainline in revision 1596.
  • Revision ID: robertc@robertcollins.net-20060304023017-7f5f460efff7d2e8
Make join cheaper for compatibly inconsistent parents.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005 by Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Test testaments for gpg signing."""
18
18
 
19
19
# TODO: Testaments with x-bits
20
20
 
21
21
import os
 
22
from sha import sha
 
23
import sys
22
24
 
23
 
from bzrlib import osutils
24
25
from bzrlib.tests import TestCaseWithTransport
25
 
from bzrlib.testament import (
26
 
    Testament,
27
 
    StrictTestament,
28
 
    StrictTestament3,
29
 
    )
30
 
from bzrlib.transform import TreeTransform
31
 
from bzrlib.tests.features import (
32
 
    SymlinkFeature,
33
 
    )
34
 
 
35
 
 
36
 
class TestamentSetup(TestCaseWithTransport):
 
26
from bzrlib.branch import Branch
 
27
from bzrlib.testament import Testament
 
28
from bzrlib.trace import mutter
 
29
from bzrlib.osutils import has_symlinks
 
30
 
 
31
 
 
32
class TestamentTests(TestCaseWithTransport):
37
33
 
38
34
    def setUp(self):
39
 
        super(TestamentSetup, self).setUp()
40
 
        self.wt = self.make_branch_and_tree('.', format='development-subtree')
41
 
        self.wt.set_root_id('TREE_ROT')
 
35
        super(TestamentTests, self).setUp()
 
36
        self.wt = self.make_branch_and_tree('.')
42
37
        b = self.b = self.wt.branch
43
38
        b.nick = "test branch"
44
39
        self.wt.commit(message='initial null commit',
51
46
                             ('src/foo.c', 'int main()\n{\n}\n')])
52
47
        self.wt.add(['hello', 'src', 'src/foo.c'],
53
48
                             ['hello-id', 'src-id', 'foo.c-id'])
54
 
        tt = TreeTransform(self.wt)
55
 
        trans_id = tt.trans_id_tree_path('hello')
56
 
        tt.set_executability(True, trans_id)
57
 
        tt.apply()
58
49
        self.wt.commit(message='add files and directories',
59
50
                 timestamp=1129025483,
60
51
                 timezone=36000,
61
52
                 rev_id='test@user-2',
62
53
                 committer='test@user')
63
54
 
64
 
 
65
 
class TestamentTests(TestamentSetup):
66
 
 
67
 
    def testament_class(self):
68
 
        return Testament
69
 
 
70
 
    def expected(self, key):
71
 
        return texts[self.testament_class()][key]
72
 
 
73
 
    def from_revision(self, repository, revision_id):
74
 
        return self.testament_class().from_revision(repository, revision_id)
75
 
 
76
55
    def test_null_testament(self):
77
56
        """Testament for a revision with no contents."""
78
 
        t = self.from_revision(self.b.repository, 'test@user-1')
 
57
        t = Testament.from_revision(self.b.repository, 'test@user-1')
79
58
        ass = self.assertTrue
80
59
        eq = self.assertEqual
81
60
        ass(isinstance(t, Testament))
86
65
 
87
66
    def test_testment_text_form(self):
88
67
        """Conversion of testament to canonical text form."""
89
 
        t = self.from_revision(self.b.repository, 'test@user-1')
 
68
        t = Testament.from_revision(self.b.repository, 'test@user-1')
90
69
        text_form = t.as_text()
91
70
        self.log('testament text form:\n' + text_form)
92
 
        self.assertEqualDiff(text_form, self.expected('rev_1'))
93
 
        short_text_form = t.as_short_text()
94
 
        self.assertEqualDiff(short_text_form, self.expected('rev_1_short'))
 
71
        self.assertEqual(text_form, REV_1_TESTAMENT)
95
72
 
96
73
    def test_testament_with_contents(self):
97
74
        """Testament containing a file and a directory."""
98
 
        t = self.from_revision(self.b.repository, 'test@user-2')
 
75
        t = Testament.from_revision(self.b.repository, 'test@user-2')
99
76
        text_form = t.as_text()
100
77
        self.log('testament text form:\n' + text_form)
101
 
        self.assertEqualDiff(text_form, self.expected('rev_2'))
 
78
        self.assertEqualDiff(text_form, REV_2_TESTAMENT)
102
79
        actual_short = t.as_short_text()
103
 
        self.assertEqualDiff(actual_short, self.expected('rev_2_short'))
 
80
        self.assertEqualDiff(actual_short, REV_2_SHORT)
 
81
 
 
82
    def test_testament_command(self):
 
83
        """Testament containing a file and a directory."""
 
84
        out, err = self.run_bzr_captured(['testament', '--long'])
 
85
        self.assertEqualDiff(err, '')
 
86
        self.assertEqualDiff(out, REV_2_TESTAMENT)
 
87
 
 
88
    def test_testament_command_2(self):
 
89
        """Command getting short testament of previous version."""
 
90
        out, err = self.run_bzr_captured(['testament', '-r1'])
 
91
        self.assertEqualDiff(err, '')
 
92
        self.assertEqualDiff(out, REV_1_SHORT)
104
93
 
105
94
    def test_testament_symlinks(self):
106
95
        """Testament containing symlink (where possible)"""
107
 
        self.requireFeature(SymlinkFeature)
 
96
        if not has_symlinks():
 
97
            return
108
98
        os.symlink('wibble/linktarget', 'link')
109
99
        self.wt.add(['link'], ['link-id'])
110
100
        self.wt.commit(message='add symlink',
112
102
                 timezone=36000,
113
103
                 rev_id='test@user-3',
114
104
                 committer='test@user')
115
 
        t = self.from_revision(self.b.repository, 'test@user-3')
116
 
        self.assertEqualDiff(t.as_text(), self.expected('rev_3'))
 
105
        t = Testament.from_revision(self.b.repository, 'test@user-3')
 
106
        self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
117
107
 
118
108
    def test_testament_revprops(self):
119
109
        """Testament to revision with extra properties"""
120
110
        props = dict(flavor='sour cherry\ncream cheese',
121
 
                     size='medium',
122
 
                     empty='',
123
 
                    )
 
111
                     size='medium')
124
112
        self.wt.commit(message='revision with properties',
125
113
                      timestamp=1129025493,
126
114
                      timezone=36000,
127
115
                      rev_id='test@user-3',
128
116
                      committer='test@user',
129
117
                      revprops=props)
130
 
        t = self.from_revision(self.b.repository, 'test@user-3')
131
 
        self.assertEqualDiff(t.as_text(), self.expected('rev_props'))
 
118
        t = Testament.from_revision(self.b.repository, 'test@user-3')
 
119
        self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
132
120
 
133
121
    def test_testament_unicode_commit_message(self):
134
122
        self.wt.commit(
136
124
            timestamp=1129025493,
137
125
            timezone=36000,
138
126
            rev_id='test@user-3',
139
 
            committer=u'Erik B\xe5gfors <test@user>',
140
 
            revprops={'uni':u'\xb5'}
141
 
            )
142
 
        t = self.from_revision(self.b.repository, 'test@user-3')
 
127
            committer='test@user')
 
128
        t = Testament.from_revision(self.b.repository, 'test@user-3')
143
129
        self.assertEqualDiff(
144
 
            self.expected('sample_unicode').encode('utf-8'), t.as_text())
145
 
 
146
 
    def test_from_tree(self):
147
 
        tree = self.b.repository.revision_tree('test@user-2')
148
 
        testament = self.testament_class().from_revision_tree(tree)
149
 
        text_1 = testament.as_short_text()
150
 
        text_2 = self.from_revision(self.b.repository,
151
 
                                    'test@user-2').as_short_text()
152
 
        self.assertEqual(text_1, text_2)
 
130
            SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text())
153
131
 
154
132
    def test___init__(self):
155
133
        revision = self.b.repository.get_revision('test@user-2')
156
 
        tree = self.b.repository.revision_tree('test@user-2')
157
 
        testament_1 = self.testament_class()(revision, tree)
158
 
        text_1 = testament_1.as_short_text()
159
 
        text_2 = self.from_revision(self.b.repository,
160
 
                                    'test@user-2').as_short_text()
161
 
        self.assertEqual(text_1, text_2)
162
 
 
163
 
 
164
 
class TestamentTestsStrict(TestamentTests):
165
 
 
166
 
    def testament_class(self):
167
 
        return StrictTestament
168
 
 
169
 
 
170
 
class TestamentTestsStrict2(TestamentTests):
171
 
 
172
 
    def testament_class(self):
173
 
        return StrictTestament3
174
 
 
 
134
        inventory = self.b.repository.get_inventory('test@user-2')
 
135
        testament_1 = Testament(revision, inventory).as_short_text()
 
136
        testament_2 = Testament.from_revision(self.b.repository, 
 
137
                                              'test@user-2').as_short_text()
 
138
        self.assertEqual(testament_1, testament_2)
 
139
                    
175
140
 
176
141
REV_1_TESTAMENT = """\
177
142
bazaar-ng testament version 1
188
153
    test branch
189
154
"""
190
155
 
191
 
 
192
 
REV_1_STRICT_TESTAMENT = """\
193
 
bazaar-ng testament version 2.1
194
 
revision-id: test@user-1
195
 
committer: test@user
196
 
timestamp: 1129025423
197
 
timezone: 0
198
 
parents:
199
 
message:
200
 
  initial null commit
201
 
inventory:
202
 
properties:
203
 
  branch-nick:
204
 
    test branch
205
 
"""
206
 
 
207
 
 
208
 
REV_1_STRICT_TESTAMENT3 = """\
209
 
bazaar testament version 3 strict
210
 
revision-id: test@user-1
211
 
committer: test@user
212
 
timestamp: 1129025423
213
 
timezone: 0
214
 
parents:
215
 
message:
216
 
  initial null commit
217
 
inventory:
218
 
  directory . TREE_ROT test@user-1 no
219
 
properties:
220
 
  branch-nick:
221
 
    test branch
222
 
"""
223
 
 
224
 
 
225
156
REV_1_SHORT = """\
226
157
bazaar-ng testament short form 1
227
158
revision-id: test@user-1
228
159
sha1: %s
229
 
""" % osutils.sha_string(REV_1_TESTAMENT)
230
 
 
231
 
 
232
 
REV_1_SHORT_STRICT = """\
233
 
bazaar-ng testament short form 2.1
234
 
revision-id: test@user-1
235
 
sha1: %s
236
 
""" % osutils.sha_string(REV_1_STRICT_TESTAMENT)
237
 
 
238
 
 
239
 
REV_1_SHORT_STRICT3 = """\
240
 
bazaar testament short form 3 strict
241
 
revision-id: test@user-1
242
 
sha1: %s
243
 
""" % osutils.sha_string(REV_1_STRICT_TESTAMENT3)
 
160
""" % sha(REV_1_TESTAMENT).hexdigest()
244
161
 
245
162
 
246
163
REV_2_TESTAMENT = """\
263
180
"""
264
181
 
265
182
 
266
 
REV_2_STRICT_TESTAMENT = """\
267
 
bazaar-ng testament version 2.1
268
 
revision-id: test@user-2
269
 
committer: test@user
270
 
timestamp: 1129025483
271
 
timezone: 36000
272
 
parents:
273
 
  test@user-1
274
 
message:
275
 
  add files and directories
276
 
inventory:
277
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
278
 
  directory src src-id test@user-2 no
279
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
280
 
properties:
281
 
  branch-nick:
282
 
    test branch
283
 
"""
284
 
 
285
 
 
286
 
REV_2_STRICT_TESTAMENT3 = """\
287
 
bazaar testament version 3 strict
288
 
revision-id: test@user-2
289
 
committer: test@user
290
 
timestamp: 1129025483
291
 
timezone: 36000
292
 
parents:
293
 
  test@user-1
294
 
message:
295
 
  add files and directories
296
 
inventory:
297
 
  directory . TREE_ROT test@user-1 no
298
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
299
 
  directory src src-id test@user-2 no
300
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
301
 
properties:
302
 
  branch-nick:
303
 
    test branch
304
 
"""
305
 
 
306
 
 
307
183
REV_2_SHORT = """\
308
184
bazaar-ng testament short form 1
309
185
revision-id: test@user-2
310
186
sha1: %s
311
 
""" % osutils.sha_string(REV_2_TESTAMENT)
312
 
 
313
 
 
314
 
REV_2_SHORT_STRICT = """\
315
 
bazaar-ng testament short form 2.1
316
 
revision-id: test@user-2
317
 
sha1: %s
318
 
""" % osutils.sha_string(REV_2_STRICT_TESTAMENT)
319
 
 
320
 
 
321
 
REV_2_SHORT_STRICT3 = """\
322
 
bazaar testament short form 3 strict
323
 
revision-id: test@user-2
324
 
sha1: %s
325
 
""" % osutils.sha_string(REV_2_STRICT_TESTAMENT3)
 
187
""" % sha(REV_2_TESTAMENT).hexdigest()
326
188
 
327
189
 
328
190
REV_PROPS_TESTAMENT = """\
342
204
properties:
343
205
  branch-nick:
344
206
    test branch
345
 
  empty:
346
 
  flavor:
347
 
    sour cherry
348
 
    cream cheese
349
 
  size:
350
 
    medium
351
 
"""
352
 
 
353
 
 
354
 
REV_PROPS_TESTAMENT_STRICT = """\
355
 
bazaar-ng testament version 2.1
356
 
revision-id: test@user-3
357
 
committer: test@user
358
 
timestamp: 1129025493
359
 
timezone: 36000
360
 
parents:
361
 
  test@user-2
362
 
message:
363
 
  revision with properties
364
 
inventory:
365
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
366
 
  directory src src-id test@user-2 no
367
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
368
 
properties:
369
 
  branch-nick:
370
 
    test branch
371
 
  empty:
372
 
  flavor:
373
 
    sour cherry
374
 
    cream cheese
375
 
  size:
376
 
    medium
377
 
"""
378
 
 
379
 
 
380
 
REV_PROPS_TESTAMENT_STRICT3 = """\
381
 
bazaar testament version 3 strict
382
 
revision-id: test@user-3
383
 
committer: test@user
384
 
timestamp: 1129025493
385
 
timezone: 36000
386
 
parents:
387
 
  test@user-2
388
 
message:
389
 
  revision with properties
390
 
inventory:
391
 
  directory . TREE_ROT test@user-1 no
392
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
393
 
  directory src src-id test@user-2 no
394
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
395
 
properties:
396
 
  branch-nick:
397
 
    test branch
398
 
  empty:
399
207
  flavor:
400
208
    sour cherry
401
209
    cream cheese
425
233
"""
426
234
 
427
235
 
428
 
REV_3_TESTAMENT_STRICT = """\
429
 
bazaar-ng testament version 2.1
430
 
revision-id: test@user-3
431
 
committer: test@user
432
 
timestamp: 1129025493
433
 
timezone: 36000
434
 
parents:
435
 
  test@user-2
436
 
message:
437
 
  add symlink
438
 
inventory:
439
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
440
 
  symlink link link-id wibble/linktarget test@user-3 no
441
 
  directory src src-id test@user-2 no
442
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
443
 
properties:
444
 
  branch-nick:
445
 
    test branch
446
 
"""
447
 
 
448
 
 
449
 
REV_3_TESTAMENT_STRICT3 = """\
450
 
bazaar testament version 3 strict
451
 
revision-id: test@user-3
452
 
committer: test@user
453
 
timestamp: 1129025493
454
 
timezone: 36000
455
 
parents:
456
 
  test@user-2
457
 
message:
458
 
  add symlink
459
 
inventory:
460
 
  directory . TREE_ROT test@user-1 no
461
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
462
 
  symlink link link-id wibble/linktarget test@user-3 no
463
 
  directory src src-id test@user-2 no
464
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
465
 
properties:
466
 
  branch-nick:
467
 
    test branch
468
 
"""
469
 
 
470
 
 
471
236
SAMPLE_UNICODE_TESTAMENT = u"""\
472
237
bazaar-ng testament version 1
473
238
revision-id: test@user-3
474
 
committer: Erik B\xe5gfors <test@user>
 
239
committer: test@user
475
240
timestamp: 1129025493
476
241
timezone: 36000
477
242
parents:
485
250
properties:
486
251
  branch-nick:
487
252
    test branch
488
 
  uni:
489
 
    \xb5
490
 
"""
491
 
 
492
 
 
493
 
SAMPLE_UNICODE_TESTAMENT_STRICT = u"""\
494
 
bazaar-ng testament version 2.1
495
 
revision-id: test@user-3
496
 
committer: Erik B\xe5gfors <test@user>
497
 
timestamp: 1129025493
498
 
timezone: 36000
499
 
parents:
500
 
  test@user-2
501
 
message:
502
 
  non-ascii commit \N{COPYRIGHT SIGN} me
503
 
inventory:
504
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
505
 
  directory src src-id test@user-2 no
506
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
507
 
properties:
508
 
  branch-nick:
509
 
    test branch
510
 
  uni:
511
 
    \xb5
512
 
"""
513
 
 
514
 
 
515
 
SAMPLE_UNICODE_TESTAMENT_STRICT3 = u"""\
516
 
bazaar testament version 3 strict
517
 
revision-id: test@user-3
518
 
committer: Erik B\xe5gfors <test@user>
519
 
timestamp: 1129025493
520
 
timezone: 36000
521
 
parents:
522
 
  test@user-2
523
 
message:
524
 
  non-ascii commit \N{COPYRIGHT SIGN} me
525
 
inventory:
526
 
  directory . TREE_ROT test@user-1 no
527
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
528
 
  directory src src-id test@user-2 no
529
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
530
 
properties:
531
 
  branch-nick:
532
 
    test branch
533
 
  uni:
534
 
    \xb5
535
 
"""
536
 
 
537
 
 
538
 
texts = {
539
 
    Testament: { 'rev_1': REV_1_TESTAMENT,
540
 
                 'rev_1_short': REV_1_SHORT,
541
 
                 'rev_2': REV_2_TESTAMENT,
542
 
                 'rev_2_short': REV_2_SHORT,
543
 
                 'rev_3': REV_3_TESTAMENT,
544
 
                 'rev_props': REV_PROPS_TESTAMENT,
545
 
                 'sample_unicode': SAMPLE_UNICODE_TESTAMENT,
546
 
    },
547
 
    StrictTestament: {'rev_1': REV_1_STRICT_TESTAMENT,
548
 
                      'rev_1_short': REV_1_SHORT_STRICT,
549
 
                      'rev_2': REV_2_STRICT_TESTAMENT,
550
 
                      'rev_2_short': REV_2_SHORT_STRICT,
551
 
                      'rev_3': REV_3_TESTAMENT_STRICT,
552
 
                      'rev_props': REV_PROPS_TESTAMENT_STRICT,
553
 
                      'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT,
554
 
    },
555
 
    StrictTestament3: {'rev_1': REV_1_STRICT_TESTAMENT3,
556
 
                      'rev_1_short': REV_1_SHORT_STRICT3,
557
 
                      'rev_2': REV_2_STRICT_TESTAMENT3,
558
 
                      'rev_2_short': REV_2_SHORT_STRICT3,
559
 
                      'rev_3': REV_3_TESTAMENT_STRICT3,
560
 
                      'rev_props': REV_PROPS_TESTAMENT_STRICT3,
561
 
                      'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT3,
562
 
    },
563
 
}
 
253
"""