/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_testament.py

  • Committer: John Arbash Meinel
  • Date: 2006-08-16 16:27:58 UTC
  • mto: This revision was merged to the branch mainline in revision 1938.
  • Revision ID: john@arbash-meinel.com-20060816162758-752ad5818bc063c9
Move out the blackbox testament tests into a real blackbox module

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 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
22
23
 
23
 
from bzrlib import osutils
24
 
from bzrlib.tests import SymlinkFeature, TestCaseWithTransport
25
 
from bzrlib.testament import Testament, StrictTestament, StrictTestament3
 
24
from bzrlib.tests import TestCaseWithTransport
 
25
from bzrlib.testament import Testament, StrictTestament
26
26
from bzrlib.transform import TreeTransform
 
27
from bzrlib.osutils import has_symlinks
27
28
 
28
29
 
29
30
class TestamentSetup(TestCaseWithTransport):
30
31
 
31
32
    def setUp(self):
32
33
        super(TestamentSetup, self).setUp()
33
 
        self.wt = self.make_branch_and_tree('.', format='dirstate-with-subtree')
34
 
        self.wt.set_root_id('TREE_ROT')
 
34
        self.wt = self.make_branch_and_tree('.')
35
35
        b = self.b = self.wt.branch
36
36
        b.nick = "test branch"
37
37
        self.wt.commit(message='initial null commit',
57
57
 
58
58
class TestamentTests(TestamentSetup):
59
59
 
60
 
    def testament_class(self):
61
 
        return Testament
62
 
 
63
 
    def expected(self, key):
64
 
        return texts[self.testament_class()][key]
65
 
 
66
 
    def from_revision(self, repository, revision_id):
67
 
        return self.testament_class().from_revision(repository, revision_id)
68
 
 
69
60
    def test_null_testament(self):
70
61
        """Testament for a revision with no contents."""
71
 
        t = self.from_revision(self.b.repository, 'test@user-1')
 
62
        t = Testament.from_revision(self.b.repository, 'test@user-1')
72
63
        ass = self.assertTrue
73
64
        eq = self.assertEqual
74
65
        ass(isinstance(t, Testament))
79
70
 
80
71
    def test_testment_text_form(self):
81
72
        """Conversion of testament to canonical text form."""
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'))
 
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)
 
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)
88
84
 
89
85
    def test_testament_with_contents(self):
90
86
        """Testament containing a file and a directory."""
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'))
 
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)
 
93
 
 
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)
97
102
 
98
103
    def test_testament_symlinks(self):
99
104
        """Testament containing symlink (where possible)"""
100
 
        self.requireFeature(SymlinkFeature)
 
105
        if not has_symlinks():
 
106
            return
101
107
        os.symlink('wibble/linktarget', 'link')
102
108
        self.wt.add(['link'], ['link-id'])
103
109
        self.wt.commit(message='add symlink',
105
111
                 timezone=36000,
106
112
                 rev_id='test@user-3',
107
113
                 committer='test@user')
108
 
        t = self.from_revision(self.b.repository, 'test@user-3')
109
 
        self.assertEqualDiff(t.as_text(), self.expected('rev_3'))
 
114
        t = Testament.from_revision(self.b.repository, 'test@user-3')
 
115
        self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
110
116
 
111
117
    def test_testament_revprops(self):
112
118
        """Testament to revision with extra properties"""
120
126
                      rev_id='test@user-3',
121
127
                      committer='test@user',
122
128
                      revprops=props)
123
 
        t = self.from_revision(self.b.repository, 'test@user-3')
124
 
        self.assertEqualDiff(t.as_text(), self.expected('rev_props'))
 
129
        t = Testament.from_revision(self.b.repository, 'test@user-3')
 
130
        self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
125
131
 
126
132
    def test_testament_unicode_commit_message(self):
127
133
        self.wt.commit(
129
135
            timestamp=1129025493,
130
136
            timezone=36000,
131
137
            rev_id='test@user-3',
132
 
            committer='Erik B\xe5gfors <test@user>',
133
 
            revprops={'uni':u'\xb5'}
134
 
            )
135
 
        t = self.from_revision(self.b.repository, 'test@user-3')
 
138
            committer='test@user')
 
139
        t = Testament.from_revision(self.b.repository, 'test@user-3')
136
140
        self.assertEqualDiff(
137
 
            self.expected('sample_unicode').encode('utf-8'), t.as_text())
 
141
            SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text())
138
142
 
139
143
    def test___init__(self):
140
144
        revision = self.b.repository.get_revision('test@user-2')
141
145
        inventory = self.b.repository.get_inventory('test@user-2')
142
 
        testament_1 = self.testament_class()(revision, inventory)
143
 
        text_1 = testament_1.as_short_text()
144
 
        text_2 = self.from_revision(self.b.repository,
145
 
                                    'test@user-2').as_short_text()
146
 
        self.assertEqual(text_1, text_2)
147
 
 
148
 
 
149
 
class TestamentTestsStrict(TestamentTests):
150
 
 
151
 
    def testament_class(self):
152
 
        return StrictTestament
153
 
 
154
 
 
155
 
class TestamentTestsStrict2(TestamentTests):
156
 
 
157
 
    def testament_class(self):
158
 
        return StrictTestament3
159
 
 
 
146
        testament_1 = Testament(revision, inventory).as_short_text()
 
147
        testament_2 = Testament.from_revision(self.b.repository, 
 
148
                                              'test@user-2').as_short_text()
 
149
        self.assertEqual(testament_1, testament_2)
 
150
                    
160
151
 
161
152
REV_1_TESTAMENT = """\
162
153
bazaar-ng testament version 1
173
164
    test branch
174
165
"""
175
166
 
176
 
 
177
167
REV_1_STRICT_TESTAMENT = """\
178
168
bazaar-ng testament version 2.1
179
169
revision-id: test@user-1
190
180
"""
191
181
 
192
182
 
193
 
REV_1_STRICT_TESTAMENT3 = """\
194
 
bazaar testament version 3 strict
195
 
revision-id: test@user-1
196
 
committer: test@user
197
 
timestamp: 1129025423
198
 
timezone: 0
199
 
parents:
200
 
message:
201
 
  initial null commit
202
 
inventory:
203
 
  directory . TREE_ROT test@user-1 no
204
 
properties:
205
 
  branch-nick:
206
 
    test branch
207
 
"""
208
 
 
209
 
 
210
183
REV_1_SHORT = """\
211
184
bazaar-ng testament short form 1
212
185
revision-id: test@user-1
213
186
sha1: %s
214
 
""" % osutils.sha(REV_1_TESTAMENT).hexdigest()
 
187
""" % sha(REV_1_TESTAMENT).hexdigest()
215
188
 
216
189
 
217
190
REV_1_SHORT_STRICT = """\
218
191
bazaar-ng testament short form 2.1
219
192
revision-id: test@user-1
220
193
sha1: %s
221
 
""" % osutils.sha(REV_1_STRICT_TESTAMENT).hexdigest()
222
 
 
223
 
 
224
 
REV_1_SHORT_STRICT3 = """\
225
 
bazaar testament short form 3 strict
226
 
revision-id: test@user-1
227
 
sha1: %s
228
 
""" % osutils.sha(REV_1_STRICT_TESTAMENT3).hexdigest()
 
194
""" % sha(REV_1_STRICT_TESTAMENT).hexdigest()
229
195
 
230
196
 
231
197
REV_2_TESTAMENT = """\
268
234
"""
269
235
 
270
236
 
271
 
REV_2_STRICT_TESTAMENT3 = """\
272
 
bazaar testament version 3 strict
273
 
revision-id: test@user-2
274
 
committer: test@user
275
 
timestamp: 1129025483
276
 
timezone: 36000
277
 
parents:
278
 
  test@user-1
279
 
message:
280
 
  add files and directories
281
 
inventory:
282
 
  directory . TREE_ROT test@user-1 no
283
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
284
 
  directory src src-id test@user-2 no
285
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
286
 
properties:
287
 
  branch-nick:
288
 
    test branch
289
 
"""
290
 
 
291
 
 
292
237
REV_2_SHORT = """\
293
238
bazaar-ng testament short form 1
294
239
revision-id: test@user-2
295
240
sha1: %s
296
 
""" % osutils.sha(REV_2_TESTAMENT).hexdigest()
 
241
""" % sha(REV_2_TESTAMENT).hexdigest()
297
242
 
298
243
 
299
244
REV_2_SHORT_STRICT = """\
300
245
bazaar-ng testament short form 2.1
301
246
revision-id: test@user-2
302
247
sha1: %s
303
 
""" % osutils.sha(REV_2_STRICT_TESTAMENT).hexdigest()
304
 
 
305
 
 
306
 
REV_2_SHORT_STRICT3 = """\
307
 
bazaar testament short form 3 strict
308
 
revision-id: test@user-2
309
 
sha1: %s
310
 
""" % osutils.sha(REV_2_STRICT_TESTAMENT3).hexdigest()
 
248
""" % sha(REV_2_STRICT_TESTAMENT).hexdigest()
311
249
 
312
250
 
313
251
REV_PROPS_TESTAMENT = """\
336
274
"""
337
275
 
338
276
 
339
 
REV_PROPS_TESTAMENT_STRICT = """\
340
 
bazaar-ng testament version 2.1
341
 
revision-id: test@user-3
342
 
committer: test@user
343
 
timestamp: 1129025493
344
 
timezone: 36000
345
 
parents:
346
 
  test@user-2
347
 
message:
348
 
  revision with properties
349
 
inventory:
350
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
351
 
  directory src src-id test@user-2 no
352
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
353
 
properties:
354
 
  branch-nick:
355
 
    test branch
356
 
  empty:
357
 
  flavor:
358
 
    sour cherry
359
 
    cream cheese
360
 
  size:
361
 
    medium
362
 
"""
363
 
 
364
 
 
365
 
REV_PROPS_TESTAMENT_STRICT3 = """\
366
 
bazaar testament version 3 strict
367
 
revision-id: test@user-3
368
 
committer: test@user
369
 
timestamp: 1129025493
370
 
timezone: 36000
371
 
parents:
372
 
  test@user-2
373
 
message:
374
 
  revision with properties
375
 
inventory:
376
 
  directory . TREE_ROT test@user-1 no
377
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
378
 
  directory src src-id test@user-2 no
379
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
380
 
properties:
381
 
  branch-nick:
382
 
    test branch
383
 
  empty:
384
 
  flavor:
385
 
    sour cherry
386
 
    cream cheese
387
 
  size:
388
 
    medium
389
 
"""
390
 
 
391
 
 
392
277
REV_3_TESTAMENT = """\
393
278
bazaar-ng testament version 1
394
279
revision-id: test@user-3
410
295
"""
411
296
 
412
297
 
413
 
REV_3_TESTAMENT_STRICT = """\
414
 
bazaar-ng testament version 2.1
415
 
revision-id: test@user-3
416
 
committer: test@user
417
 
timestamp: 1129025493
418
 
timezone: 36000
419
 
parents:
420
 
  test@user-2
421
 
message:
422
 
  add symlink
423
 
inventory:
424
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
425
 
  symlink link link-id wibble/linktarget test@user-3 no
426
 
  directory src src-id test@user-2 no
427
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
428
 
properties:
429
 
  branch-nick:
430
 
    test branch
431
 
"""
432
 
 
433
 
 
434
 
REV_3_TESTAMENT_STRICT3 = """\
435
 
bazaar testament version 3 strict
436
 
revision-id: test@user-3
437
 
committer: test@user
438
 
timestamp: 1129025493
439
 
timezone: 36000
440
 
parents:
441
 
  test@user-2
442
 
message:
443
 
  add symlink
444
 
inventory:
445
 
  directory . TREE_ROT test@user-1 no
446
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
447
 
  symlink link link-id wibble/linktarget test@user-3 no
448
 
  directory src src-id test@user-2 no
449
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
450
 
properties:
451
 
  branch-nick:
452
 
    test branch
453
 
"""
454
 
 
455
 
 
456
298
SAMPLE_UNICODE_TESTAMENT = u"""\
457
299
bazaar-ng testament version 1
458
300
revision-id: test@user-3
459
 
committer: Erik B\xe5gfors <test@user>
 
301
committer: test@user
460
302
timestamp: 1129025493
461
303
timezone: 36000
462
304
parents:
470
312
properties:
471
313
  branch-nick:
472
314
    test branch
473
 
  uni:
474
 
    \xb5
475
 
"""
476
 
 
477
 
 
478
 
SAMPLE_UNICODE_TESTAMENT_STRICT = u"""\
479
 
bazaar-ng testament version 2.1
480
 
revision-id: test@user-3
481
 
committer: Erik B\xe5gfors <test@user>
482
 
timestamp: 1129025493
483
 
timezone: 36000
484
 
parents:
485
 
  test@user-2
486
 
message:
487
 
  non-ascii commit \N{COPYRIGHT SIGN} me
488
 
inventory:
489
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
490
 
  directory src src-id test@user-2 no
491
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
492
 
properties:
493
 
  branch-nick:
494
 
    test branch
495
 
  uni:
496
 
    \xb5
497
 
"""
498
 
 
499
 
 
500
 
SAMPLE_UNICODE_TESTAMENT_STRICT3 = u"""\
501
 
bazaar testament version 3 strict
502
 
revision-id: test@user-3
503
 
committer: Erik B\xe5gfors <test@user>
504
 
timestamp: 1129025493
505
 
timezone: 36000
506
 
parents:
507
 
  test@user-2
508
 
message:
509
 
  non-ascii commit \N{COPYRIGHT SIGN} me
510
 
inventory:
511
 
  directory . TREE_ROT test@user-1 no
512
 
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
513
 
  directory src src-id test@user-2 no
514
 
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
515
 
properties:
516
 
  branch-nick:
517
 
    test branch
518
 
  uni:
519
 
    \xb5
520
 
"""
521
 
 
522
 
 
523
 
texts = {
524
 
    Testament: { 'rev_1': REV_1_TESTAMENT,
525
 
                 'rev_1_short': REV_1_SHORT,
526
 
                 'rev_2': REV_2_TESTAMENT,
527
 
                 'rev_2_short': REV_2_SHORT,
528
 
                 'rev_3': REV_3_TESTAMENT,
529
 
                 'rev_props': REV_PROPS_TESTAMENT,
530
 
                 'sample_unicode': SAMPLE_UNICODE_TESTAMENT,
531
 
    },
532
 
    StrictTestament: {'rev_1': REV_1_STRICT_TESTAMENT,
533
 
                      'rev_1_short': REV_1_SHORT_STRICT,
534
 
                      'rev_2': REV_2_STRICT_TESTAMENT,
535
 
                      'rev_2_short': REV_2_SHORT_STRICT,
536
 
                      'rev_3': REV_3_TESTAMENT_STRICT,
537
 
                      'rev_props': REV_PROPS_TESTAMENT_STRICT,
538
 
                      'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT,
539
 
    },
540
 
    StrictTestament3: {'rev_1': REV_1_STRICT_TESTAMENT3,
541
 
                      'rev_1_short': REV_1_SHORT_STRICT3,
542
 
                      'rev_2': REV_2_STRICT_TESTAMENT3,
543
 
                      'rev_2_short': REV_2_SHORT_STRICT3,
544
 
                      'rev_3': REV_3_TESTAMENT_STRICT3,
545
 
                      'rev_props': REV_PROPS_TESTAMENT_STRICT3,
546
 
                      'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT3,
547
 
    },
548
 
}
 
315
"""