~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_testament.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-30 13:54:37 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1898.
  • Revision ID: john@arbash-meinel.com-20060730135437-1d722abdb14bff76
(jelmer) Install new intertree tests

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