~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_testament.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-09-29 15:31:52 UTC
  • mfrom: (2052.1.1 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20060929153152-9a32a9b020e0f74b
Lukáš Lalinský: Windows-speficic smart server transport selftest fixes.

Show diffs side-by-side

added added

removed removed

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