~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-04-07 07:52:50 UTC
  • mfrom: (3340.1.1 208418-1.4)
  • Revision ID: pqm@pqm.ubuntu.com-20080407075250-phs53xnslo8boaeo
Return the correct knit serialisation method in _StreamAccess.
        (Andrew Bennetts, Martin Pool, Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
    errors,
25
25
    repository,
26
26
    )
27
 
from bzrlib.builtins import merge
28
27
from bzrlib.tests import TestCase, TestCaseWithTransport
29
28
from bzrlib.revisionspec import (
30
29
    RevisionSpec,
50
49
 
51
50
        self.tree = self.make_branch_and_tree('tree')
52
51
        self.build_tree(['tree/a'])
 
52
        self.tree.lock_write()
 
53
        self.addCleanup(self.tree.unlock)
53
54
        self.tree.add(['a'])
54
55
        self.tree.commit('a', rev_id='r1')
55
56
 
56
57
        self.tree2 = self.tree.bzrdir.sprout('tree2').open_workingtree()
57
58
        self.tree2.commit('alt', rev_id='alt_r2')
58
59
 
59
 
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
60
 
                                          revision_id='alt_r2')
61
 
        self.tree.set_pending_merges(['alt_r2'])
 
60
        self.tree.merge_from_branch(self.tree2.branch)
62
61
        self.tree.commit('second', rev_id='r2')
63
62
 
64
63
    def get_in_history(self, revision_spec):
84
83
            self.fail('Expected InvalidRevisionSpec to be raised for %s'
85
84
                      % (revision_spec,))
86
85
 
 
86
    def assertAsRevisionId(self, revision_id, revision_spec):
 
87
        """Calling as_revision_id() should return the specified id."""
 
88
        spec = RevisionSpec.from_string(revision_spec)
 
89
        self.assertEqual(revision_id,
 
90
                         spec.as_revision_id(self.tree.branch))
 
91
 
87
92
 
88
93
class TestOddRevisionSpec(TestRevisionSpec):
89
94
    """Test things that aren't normally thought of as revision specs"""
90
95
 
91
96
    def test_none(self):
92
 
        self.assertInHistoryIs(0, None, None)
 
97
        self.assertInHistoryIs(None, None, None)
93
98
 
94
99
    def test_object(self):
95
100
        self.assertRaises(TypeError, RevisionSpec.from_string, object())
117
122
class TestRevisionSpec_revno(TestRevisionSpec):
118
123
 
119
124
    def test_positive_int(self):
120
 
        self.assertInHistoryIs(0, None, '0')
 
125
        self.assertInHistoryIs(0, 'null:', '0')
121
126
        self.assertInHistoryIs(1, 'r1', '1')
122
127
        self.assertInHistoryIs(2, 'r2', '2')
123
128
        self.assertInvalid('3')
134
139
        self.assertInHistoryIs(1, 'r1', '-100')
135
140
 
136
141
    def test_positive(self):
137
 
        self.assertInHistoryIs(0, None, 'revno:0')
 
142
        self.assertInHistoryIs(0, 'null:', 'revno:0')
138
143
        self.assertInHistoryIs(1, 'r1', 'revno:1')
139
144
        self.assertInHistoryIs(2, 'r2', 'revno:2')
140
145
 
247
252
        self.assertEqual((2, 'b@r-0-2'),
248
253
                         spec_in_history('revno:2:b/', None))
249
254
 
 
255
    def test_as_revision_id(self):
 
256
        self.assertAsRevisionId('null:', '0')
 
257
        self.assertAsRevisionId('r1', '1')
 
258
        self.assertAsRevisionId('r2', '2')
 
259
        self.assertAsRevisionId('r1', '-2')
 
260
        self.assertAsRevisionId('r2', '-1')
 
261
        self.assertAsRevisionId('alt_r2', '1.1.1')
250
262
 
251
263
 
252
264
class TestRevisionSpec_revid(TestRevisionSpec):
284
296
        self.assertInHistoryIs(3, revision_id, u'revid:\N{SNOWMAN}')
285
297
        self.assertInHistoryIs(3, revision_id, 'revid:' + revision_id)
286
298
 
 
299
    def test_as_revision_id(self):
 
300
        self.assertAsRevisionId('r1', 'revid:r1')
 
301
        self.assertAsRevisionId('r2', 'revid:r2')
 
302
        self.assertAsRevisionId('alt_r2', 'revid:alt_r2')
 
303
 
287
304
 
288
305
class TestRevisionSpec_last(TestRevisionSpec):
289
306
 
290
307
    def test_positive(self):
291
308
        self.assertInHistoryIs(2, 'r2', 'last:1')
292
309
        self.assertInHistoryIs(1, 'r1', 'last:2')
293
 
        self.assertInHistoryIs(0, None, 'last:3')
 
310
        self.assertInHistoryIs(0, 'null:', 'last:3')
294
311
 
295
312
    def test_empty(self):
296
313
        self.assertInHistoryIs(2, 'r2', 'last:')
315
332
            pass
316
333
        self.assertInvalid('last:Y', extra='\n' + str(e))
317
334
 
 
335
    def test_as_revision_id(self):
 
336
        self.assertAsRevisionId('r2', 'last:1')
 
337
        self.assertAsRevisionId('r1', 'last:2')
 
338
 
318
339
 
319
340
class TestRevisionSpec_before(TestRevisionSpec):
320
341
 
323
344
        self.assertInHistoryIs(1, 'r1', 'before:-1')
324
345
 
325
346
    def test_before_one(self):
326
 
        self.assertInHistoryIs(0, None, 'before:1')
 
347
        self.assertInHistoryIs(0, 'null:', 'before:1')
327
348
 
328
349
    def test_before_none(self):
329
350
        self.assertInvalid('before:0',
344
365
        new_tree.commit('first', rev_id='new_r1')
345
366
        self.tree.branch.repository.fetch(new_tree.branch.repository,
346
367
                                          revision_id='new_r1')
347
 
        self.assertInHistoryIs(0, None, 'before:revid:new_r1')
 
368
        self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
 
369
 
 
370
    def test_as_revision_id(self):
 
371
        self.assertAsRevisionId('r1', 'before:revid:r2')
 
372
        self.assertAsRevisionId('r1', 'before:2')
 
373
        self.assertAsRevisionId('r1', 'before:1.1.1')
 
374
        self.assertAsRevisionId('r1', 'before:revid:alt_r2')
348
375
 
349
376
 
350
377
class TestRevisionSpec_tag(TestRevisionSpec):
351
378
    
352
379
    def make_branch_and_tree(self, relpath):
353
380
        # override format as the default one may not support tags
354
 
        control = bzrdir.BzrDir.create(relpath)
355
 
        control.create_repository()
356
 
        branch.BzrBranchExperimental.initialize(control)
357
 
        return control.create_workingtree()
 
381
        return TestRevisionSpec.make_branch_and_tree(
 
382
            self, relpath, format='dirstate-tags')
358
383
 
359
384
    def test_from_string_tag(self):
360
385
        spec = RevisionSpec.from_string('tag:bzr-0.14')
364
389
    def test_lookup_tag(self):
365
390
        self.tree.branch.tags.set_tag('bzr-0.14', 'r1')
366
391
        self.assertInHistoryIs(1, 'r1', 'tag:bzr-0.14')
 
392
        self.tree.branch.tags.set_tag('null_rev', 'null:')
 
393
        self.assertInHistoryIs(0, 'null:', 'tag:null_rev')
367
394
 
368
395
    def test_failed_lookup(self):
369
396
        # tags that don't exist give a specific message: arguably we should
372
399
            self.get_in_history,
373
400
            'tag:some-random-tag')
374
401
 
 
402
    def test_as_revision_id(self):
 
403
        self.tree.branch.tags.set_tag('my-tag', 'r2')
 
404
        self.tree.branch.tags.set_tag('null_rev', 'null:')
 
405
        self.assertAsRevisionId('r2', 'tag:my-tag')
 
406
        self.assertAsRevisionId('null:', 'tag:null_rev')
 
407
        self.assertAsRevisionId('r1', 'before:tag:my-tag')
 
408
 
375
409
 
376
410
class TestRevisionSpec_date(TestRevisionSpec):
377
411
 
408
442
        self.assertInHistoryIs(2, 'new_r2',
409
443
            'date:%04d-%02d-%02d' % (now.year, now.month, now.day))
410
444
 
 
445
    def test_as_revision_id(self):
 
446
        self.assertAsRevisionId('new_r2', 'date:today')
 
447
 
411
448
 
412
449
class TestRevisionSpec_ancestor(TestRevisionSpec):
413
450
    
451
488
                          spec_in_history, 'ancestor:tree',
452
489
                                           new_tree.branch)
453
490
 
 
491
    def test_as_revision_id(self):
 
492
        self.assertAsRevisionId('alt_r2', 'ancestor:tree2')
 
493
 
454
494
 
455
495
class TestRevisionSpec_branch(TestRevisionSpec):
456
496
    
485
525
        self.assertRaises(errors.NoCommits,
486
526
                          self.get_in_history, 'branch:new_tree')
487
527
 
 
528
    def test_as_revision_id(self):
 
529
        self.assertAsRevisionId('alt_r2', 'branch:tree2')
 
530
 
488
531
 
489
532
class TestRevisionSpec_submit(TestRevisionSpec):
490
533
 
500
543
        # submit branch overrides parent branch
501
544
        self.tree.branch.set_submit_branch('tree2')
502
545
        self.assertInHistoryIs(None, 'alt_r2', 'submit:')
 
546
 
 
547
    def test_as_revision_id(self):
 
548
        self.tree.branch.set_submit_branch('tree2')
 
549
        self.assertAsRevisionId('alt_r2', 'branch:tree2')