~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_testament.py

  • Committer: Aaron Bentley
  • Date: 2006-09-21 17:40:20 UTC
  • mto: This revision was merged to the branch mainline in revision 2048.
  • Revision ID: abentley@panoramicfeedback.com-20060921174020-5a6a95957ad5dd7b
Implement testament format 3 strict

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from sha import sha
23
23
 
24
24
from bzrlib.tests import TestCaseWithTransport
25
 
from bzrlib.testament import Testament, StrictTestament
 
25
from bzrlib.testament import Testament, StrictTestament, StrictTestament2
26
26
from bzrlib.transform import TreeTransform
27
27
from bzrlib.osutils import has_symlinks
28
28
 
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
 
60
69
    def test_null_testament(self):
61
70
        """Testament for a revision with no contents."""
62
 
        t = Testament.from_revision(self.b.repository, 'test@user-1')
 
71
        t = self.from_revision(self.b.repository, 'test@user-1')
63
72
        ass = self.assertTrue
64
73
        eq = self.assertEqual
65
74
        ass(isinstance(t, Testament))
70
79
 
71
80
    def test_testment_text_form(self):
72
81
        """Conversion of testament to canonical text form."""
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)
 
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'))
84
88
 
85
89
    def test_testament_with_contents(self):
86
90
        """Testament containing a file and a directory."""
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)
 
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'))
102
97
 
103
98
    def test_testament_symlinks(self):
104
99
        """Testament containing symlink (where possible)"""
111
106
                 timezone=36000,
112
107
                 rev_id='test@user-3',
113
108
                 committer='test@user')
114
 
        t = Testament.from_revision(self.b.repository, 'test@user-3')
115
 
        self.assertEqualDiff(t.as_text(), REV_3_TESTAMENT)
 
109
        t = self.from_revision(self.b.repository, 'test@user-3')
 
110
        self.assertEqualDiff(t.as_text(), self.expected('rev_3'))
116
111
 
117
112
    def test_testament_revprops(self):
118
113
        """Testament to revision with extra properties"""
126
121
                      rev_id='test@user-3',
127
122
                      committer='test@user',
128
123
                      revprops=props)
129
 
        t = Testament.from_revision(self.b.repository, 'test@user-3')
130
 
        self.assertEqualDiff(t.as_text(), REV_PROPS_TESTAMENT)
 
124
        t = self.from_revision(self.b.repository, 'test@user-3')
 
125
        self.assertEqualDiff(t.as_text(), self.expected('rev_props'))
131
126
 
132
127
    def test_testament_unicode_commit_message(self):
133
128
        self.wt.commit(
138
133
            committer='Erik B\xe5gfors <test@user>',
139
134
            revprops={'uni':u'\xb5'}
140
135
            )
141
 
        t = Testament.from_revision(self.b.repository, 'test@user-3')
 
136
        t = self.from_revision(self.b.repository, 'test@user-3')
142
137
        self.assertEqualDiff(
143
 
            SAMPLE_UNICODE_TESTAMENT.encode('utf-8'), t.as_text())
 
138
            self.expected('sample_unicode').encode('utf-8'), t.as_text())
144
139
 
145
140
    def test___init__(self):
146
141
        revision = self.b.repository.get_revision('test@user-2')
147
142
        inventory = self.b.repository.get_inventory('test@user-2')
148
 
        testament_1 = Testament(revision, inventory).as_short_text()
149
 
        testament_2 = Testament.from_revision(self.b.repository, 
 
143
        testament_1 = self.testament_class()(revision, inventory).as_short_text()
 
144
        testament_2 = self.from_revision(self.b.repository, 
150
145
                                              'test@user-2').as_short_text()
151
146
        self.assertEqual(testament_1, testament_2)
152
147
                    
153
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 StrictTestament2
 
159
 
 
160
 
154
161
REV_1_TESTAMENT = """\
155
162
bazaar-ng testament version 1
156
163
revision-id: test@user-1
181
188
    test branch
182
189
"""
183
190
 
 
191
REV_1_STRICT_TESTAMENT2 = """\
 
192
bazaar-ng testament version 3 strict
 
193
revision-id: test@user-1
 
194
committer: test@user
 
195
timestamp: 1129025423
 
196
timezone: 0
 
197
parents:
 
198
message:
 
199
  initial null commit
 
200
inventory:
 
201
  directory . TREE_ROOT test@user-1 no
 
202
properties:
 
203
  branch-nick:
 
204
    test branch
 
205
"""
184
206
 
185
207
REV_1_SHORT = """\
186
208
bazaar-ng testament short form 1
196
218
""" % sha(REV_1_STRICT_TESTAMENT).hexdigest()
197
219
 
198
220
 
 
221
REV_1_SHORT_STRICT2 = """\
 
222
bazaar-ng testament short form 3 strict
 
223
revision-id: test@user-1
 
224
sha1: %s
 
225
""" % sha(REV_1_STRICT_TESTAMENT2).hexdigest()
 
226
 
 
227
 
199
228
REV_2_TESTAMENT = """\
200
229
bazaar-ng testament version 1
201
230
revision-id: test@user-2
236
265
"""
237
266
 
238
267
 
 
268
REV_2_STRICT_TESTAMENT2 = """\
 
269
bazaar-ng testament version 3 strict
 
270
revision-id: test@user-2
 
271
committer: test@user
 
272
timestamp: 1129025483
 
273
timezone: 36000
 
274
parents:
 
275
  test@user-1
 
276
message:
 
277
  add files and directories
 
278
inventory:
 
279
  directory . TREE_ROOT test@user-2 no
 
280
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
 
281
  directory src src-id test@user-2 no
 
282
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
 
283
properties:
 
284
  branch-nick:
 
285
    test branch
 
286
"""
 
287
 
239
288
REV_2_SHORT = """\
240
289
bazaar-ng testament short form 1
241
290
revision-id: test@user-2
250
299
""" % sha(REV_2_STRICT_TESTAMENT).hexdigest()
251
300
 
252
301
 
 
302
REV_2_SHORT_STRICT2 = """\
 
303
bazaar-ng testament short form 3 strict
 
304
revision-id: test@user-2
 
305
sha1: %s
 
306
""" % sha(REV_2_STRICT_TESTAMENT2).hexdigest()
 
307
 
 
308
 
253
309
REV_PROPS_TESTAMENT = """\
254
310
bazaar-ng testament version 1
255
311
revision-id: test@user-3
276
332
"""
277
333
 
278
334
 
 
335
REV_PROPS_TESTAMENT_STRICT = """\
 
336
bazaar-ng testament version 2.1
 
337
revision-id: test@user-3
 
338
committer: test@user
 
339
timestamp: 1129025493
 
340
timezone: 36000
 
341
parents:
 
342
  test@user-2
 
343
message:
 
344
  revision with properties
 
345
inventory:
 
346
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
 
347
  directory src src-id test@user-2 no
 
348
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
 
349
properties:
 
350
  branch-nick:
 
351
    test branch
 
352
  empty:
 
353
  flavor:
 
354
    sour cherry
 
355
    cream cheese
 
356
  size:
 
357
    medium
 
358
"""
 
359
 
 
360
 
 
361
REV_PROPS_TESTAMENT_STRICT2 = """\
 
362
bazaar-ng testament version 3 strict
 
363
revision-id: test@user-3
 
364
committer: test@user
 
365
timestamp: 1129025493
 
366
timezone: 36000
 
367
parents:
 
368
  test@user-2
 
369
message:
 
370
  revision with properties
 
371
inventory:
 
372
  directory . TREE_ROOT test@user-3 no
 
373
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
 
374
  directory src src-id test@user-2 no
 
375
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
 
376
properties:
 
377
  branch-nick:
 
378
    test branch
 
379
  empty:
 
380
  flavor:
 
381
    sour cherry
 
382
    cream cheese
 
383
  size:
 
384
    medium
 
385
"""
 
386
 
 
387
 
279
388
REV_3_TESTAMENT = """\
280
389
bazaar-ng testament version 1
281
390
revision-id: test@user-3
297
406
"""
298
407
 
299
408
 
 
409
REV_3_TESTAMENT_STRICT = """\
 
410
bazaar-ng testament version 2.1
 
411
revision-id: test@user-3
 
412
committer: test@user
 
413
timestamp: 1129025493
 
414
timezone: 36000
 
415
parents:
 
416
  test@user-2
 
417
message:
 
418
  add symlink
 
419
inventory:
 
420
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
 
421
  symlink link link-id wibble/linktarget test@user-3 no
 
422
  directory src src-id test@user-2 no
 
423
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
 
424
properties:
 
425
  branch-nick:
 
426
    test branch
 
427
"""
 
428
 
 
429
 
 
430
REV_3_TESTAMENT_STRICT2 = """\
 
431
bazaar-ng testament version 3 strict
 
432
revision-id: test@user-3
 
433
committer: test@user
 
434
timestamp: 1129025493
 
435
timezone: 36000
 
436
parents:
 
437
  test@user-2
 
438
message:
 
439
  add symlink
 
440
inventory:
 
441
  directory . TREE_ROOT test@user-3 no
 
442
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
 
443
  symlink link link-id wibble/linktarget test@user-3 no
 
444
  directory src src-id test@user-2 no
 
445
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
 
446
properties:
 
447
  branch-nick:
 
448
    test branch
 
449
"""
 
450
 
300
451
SAMPLE_UNICODE_TESTAMENT = u"""\
301
452
bazaar-ng testament version 1
302
453
revision-id: test@user-3
317
468
  uni:
318
469
    \xb5
319
470
"""
 
471
 
 
472
 
 
473
SAMPLE_UNICODE_TESTAMENT_STRICT = u"""\
 
474
bazaar-ng testament version 2.1
 
475
revision-id: test@user-3
 
476
committer: Erik B\xe5gfors <test@user>
 
477
timestamp: 1129025493
 
478
timezone: 36000
 
479
parents:
 
480
  test@user-2
 
481
message:
 
482
  non-ascii commit \N{COPYRIGHT SIGN} me
 
483
inventory:
 
484
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
 
485
  directory src src-id test@user-2 no
 
486
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
 
487
properties:
 
488
  branch-nick:
 
489
    test branch
 
490
  uni:
 
491
    \xb5
 
492
"""
 
493
 
 
494
 
 
495
SAMPLE_UNICODE_TESTAMENT_STRICT2 = u"""\
 
496
bazaar-ng testament version 3 strict
 
497
revision-id: test@user-3
 
498
committer: Erik B\xe5gfors <test@user>
 
499
timestamp: 1129025493
 
500
timezone: 36000
 
501
parents:
 
502
  test@user-2
 
503
message:
 
504
  non-ascii commit \N{COPYRIGHT SIGN} me
 
505
inventory:
 
506
  directory . TREE_ROOT test@user-3 no
 
507
  file hello hello-id 34dd0ac19a24bf80c4d33b5c8960196e8d8d1f73 test@user-2 yes
 
508
  directory src src-id test@user-2 no
 
509
  file src/foo.c foo.c-id a2a049c20f908ae31b231d98779eb63c66448f24 test@user-2 no
 
510
properties:
 
511
  branch-nick:
 
512
    test branch
 
513
  uni:
 
514
    \xb5
 
515
"""
 
516
 
 
517
 
 
518
texts = {
 
519
    Testament: { 'rev_1': REV_1_TESTAMENT,
 
520
                 'rev_1_short': REV_1_SHORT,
 
521
                 'rev_2': REV_2_TESTAMENT,
 
522
                 'rev_2_short': REV_2_SHORT,
 
523
                 'rev_3': REV_3_TESTAMENT,
 
524
                 'rev_props': REV_PROPS_TESTAMENT,
 
525
                 'sample_unicode': SAMPLE_UNICODE_TESTAMENT,
 
526
    },
 
527
    StrictTestament: {'rev_1': REV_1_STRICT_TESTAMENT,
 
528
                      'rev_1_short': REV_1_SHORT_STRICT,
 
529
                      'rev_2': REV_2_STRICT_TESTAMENT,
 
530
                      'rev_2_short': REV_2_SHORT_STRICT,
 
531
                      'rev_3': REV_3_TESTAMENT_STRICT,
 
532
                      'rev_props': REV_PROPS_TESTAMENT_STRICT,
 
533
                      'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT,
 
534
    },
 
535
    StrictTestament2: {'rev_1': REV_1_STRICT_TESTAMENT2,
 
536
                      'rev_1_short': REV_1_SHORT_STRICT2,
 
537
                      'rev_2': REV_2_STRICT_TESTAMENT2,
 
538
                      'rev_2_short': REV_2_SHORT_STRICT2,
 
539
                      'rev_3': REV_3_TESTAMENT_STRICT2,
 
540
                      'rev_props': REV_PROPS_TESTAMENT_STRICT2,
 
541
                      'sample_unicode': SAMPLE_UNICODE_TESTAMENT_STRICT2,
 
542
    },
 
543
}