~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-03 02:22:55 UTC
  • mfrom: (3298.2.18 revision_id_to_revno)
  • Revision ID: pqm@pqm.ubuntu.com-20080403022255-5l0yelvi9m74mq24
Faster Branch and revspec operations (jam, abentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
 
50
50
        self.tree = self.make_branch_and_tree('tree')
51
51
        self.build_tree(['tree/a'])
 
52
        self.tree.lock_write()
 
53
        self.addCleanup(self.tree.unlock)
52
54
        self.tree.add(['a'])
53
55
        self.tree.commit('a', rev_id='r1')
54
56
 
55
57
        self.tree2 = self.tree.bzrdir.sprout('tree2').open_workingtree()
56
58
        self.tree2.commit('alt', rev_id='alt_r2')
57
59
 
58
 
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
59
 
                                          revision_id='alt_r2')
60
 
        self.tree.set_pending_merges(['alt_r2'])
 
60
        self.tree.merge_from_branch(self.tree2.branch)
61
61
        self.tree.commit('second', rev_id='r2')
62
62
 
63
63
    def get_in_history(self, revision_spec):
83
83
            self.fail('Expected InvalidRevisionSpec to be raised for %s'
84
84
                      % (revision_spec,))
85
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
 
86
92
 
87
93
class TestOddRevisionSpec(TestRevisionSpec):
88
94
    """Test things that aren't normally thought of as revision specs"""
89
95
 
90
96
    def test_none(self):
91
 
        self.assertInHistoryIs(0, None, None)
 
97
        self.assertInHistoryIs(None, None, None)
92
98
 
93
99
    def test_object(self):
94
100
        self.assertRaises(TypeError, RevisionSpec.from_string, object())
246
252
        self.assertEqual((2, 'b@r-0-2'),
247
253
                         spec_in_history('revno:2:b/', None))
248
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')
249
262
 
250
263
 
251
264
class TestRevisionSpec_revid(TestRevisionSpec):
283
296
        self.assertInHistoryIs(3, revision_id, u'revid:\N{SNOWMAN}')
284
297
        self.assertInHistoryIs(3, revision_id, 'revid:' + revision_id)
285
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
 
286
304
 
287
305
class TestRevisionSpec_last(TestRevisionSpec):
288
306
 
314
332
            pass
315
333
        self.assertInvalid('last:Y', extra='\n' + str(e))
316
334
 
 
335
    def test_as_revision_id(self):
 
336
        self.assertAsRevisionId('r2', 'last:1')
 
337
        self.assertAsRevisionId('r1', 'last:2')
 
338
 
317
339
 
318
340
class TestRevisionSpec_before(TestRevisionSpec):
319
341
 
345
367
                                          revision_id='new_r1')
346
368
        self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
347
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')
 
375
 
348
376
 
349
377
class TestRevisionSpec_tag(TestRevisionSpec):
350
378
    
361
389
    def test_lookup_tag(self):
362
390
        self.tree.branch.tags.set_tag('bzr-0.14', 'r1')
363
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')
364
394
 
365
395
    def test_failed_lookup(self):
366
396
        # tags that don't exist give a specific message: arguably we should
369
399
            self.get_in_history,
370
400
            'tag:some-random-tag')
371
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
 
372
409
 
373
410
class TestRevisionSpec_date(TestRevisionSpec):
374
411
 
405
442
        self.assertInHistoryIs(2, 'new_r2',
406
443
            'date:%04d-%02d-%02d' % (now.year, now.month, now.day))
407
444
 
 
445
    def test_as_revision_id(self):
 
446
        self.assertAsRevisionId('new_r2', 'date:today')
 
447
 
408
448
 
409
449
class TestRevisionSpec_ancestor(TestRevisionSpec):
410
450
    
448
488
                          spec_in_history, 'ancestor:tree',
449
489
                                           new_tree.branch)
450
490
 
 
491
    def test_as_revision_id(self):
 
492
        self.assertAsRevisionId('alt_r2', 'ancestor:tree2')
 
493
 
451
494
 
452
495
class TestRevisionSpec_branch(TestRevisionSpec):
453
496
    
482
525
        self.assertRaises(errors.NoCommits,
483
526
                          self.get_in_history, 'branch:new_tree')
484
527
 
 
528
    def test_as_revision_id(self):
 
529
        self.assertAsRevisionId('alt_r2', 'branch:tree2')
 
530
 
485
531
 
486
532
class TestRevisionSpec_submit(TestRevisionSpec):
487
533
 
497
543
        # submit branch overrides parent branch
498
544
        self.tree.branch.set_submit_branch('tree2')
499
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')