~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionnamespaces.py

  • Committer: John Arbash Meinel
  • Date: 2008-03-20 19:25:35 UTC
  • mto: (3298.2.13 revision_id_to_revno)
  • mto: This revision was merged to the branch mainline in revision 3328.
  • Revision ID: john@arbash-meinel.com-20080320192535-1cqd3rnulm3hh36l
Add tests that all RevisionSpecs implement in_branch(b, needs_revno)

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
    return RevisionSpec.from_string(spec).in_history(branch)
38
38
 
39
39
 
 
40
def spec_in_branch(spec, branch, *args, **kwargs):
 
41
    """A simple helper to change a revision spec into a branch search"""
 
42
    return RevisionSpec.from_string(spec).in_branch(branch, *args, **kwargs)
 
43
 
 
44
 
40
45
# Basic class, which just creates a really basic set of revisions
41
46
class TestRevisionSpec(TestCaseWithTransport):
42
47
 
49
54
 
50
55
        self.tree = self.make_branch_and_tree('tree')
51
56
        self.build_tree(['tree/a'])
52
 
        self.tree.add(['a'])
53
 
        self.tree.commit('a', rev_id='r1')
54
 
 
55
 
        self.tree2 = self.tree.bzrdir.sprout('tree2').open_workingtree()
56
 
        self.tree2.commit('alt', rev_id='alt_r2')
57
 
 
58
 
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
59
 
                                          revision_id='alt_r2')
60
 
        self.tree.set_pending_merges(['alt_r2'])
61
 
        self.tree.commit('second', rev_id='r2')
 
57
        self.tree.lock_write()
 
58
        try:
 
59
            self.tree.add(['a'])
 
60
            self.tree.commit('a', rev_id='r1')
 
61
 
 
62
            self.tree2 = self.tree.bzrdir.sprout('tree2').open_workingtree()
 
63
            self.tree2.commit('alt', rev_id='alt_r2')
 
64
 
 
65
            self.tree.merge_from_branch(self.tree2.branch)
 
66
            self.tree.commit('second', rev_id='r2')
 
67
        finally:
 
68
            self.tree.unlock()
62
69
 
63
70
    def get_in_history(self, revision_spec):
64
71
        return spec_in_history(revision_spec, self.tree.branch)
65
72
 
 
73
    def get_in_branch(self, revision_spec, *args, **kwargs):
 
74
        return spec_in_branch(revision_spec, self.tree.branch, *args, **kwargs)
 
75
 
66
76
    def assertInHistoryIs(self, exp_revno, exp_revision_id, revision_spec):
67
77
        rev_info = self.get_in_history(revision_spec)
68
78
        self.assertEqual(exp_revno, rev_info.revno,
83
93
            self.fail('Expected InvalidRevisionSpec to be raised for %s'
84
94
                      % (revision_spec,))
85
95
 
 
96
    def assertInBranchSupportsNeedRevno(self, revision_spec,
 
97
                                        has_simple_revno=True):
 
98
        """Assert that the in_branch() helper supports need_revno
 
99
 
 
100
        If need_revno=False, then the RevisionInfo can have None for revno.
 
101
        But if it has a real number, then it should be the same as when
 
102
        need_revno=True is passed.
 
103
 
 
104
        :param revision_spec: The revision spec to test.
 
105
        :param has_simple_revno: If true, then 'need_revno=True' must set the
 
106
            .revno property to something other than None.
 
107
        """
 
108
        info_true = self.get_in_branch(revision_spec, need_revno=True)
 
109
        if has_simple_revno:
 
110
            self.assertIsNot(None, info_true.revno)
 
111
        else:
 
112
            self.assertIs(None, info_true.revno)
 
113
        info_false = self.get_in_branch(revision_spec, need_revno=False)
 
114
        if info_false.revno is not None:
 
115
            self.assertEqual(info_true.revno, info_false.revno)
 
116
 
86
117
 
87
118
class TestOddRevisionSpec(TestRevisionSpec):
88
119
    """Test things that aren't normally thought of as revision specs"""
246
277
        self.assertEqual((2, 'b@r-0-2'),
247
278
                         spec_in_history('revno:2:b/', None))
248
279
 
 
280
    def test_supports_need_revno(self):
 
281
        self.assertInBranchSupportsNeedRevno('1')
 
282
        self.assertInBranchSupportsNeedRevno('2')
 
283
        self.assertInBranchSupportsNeedRevno('1.1.1',
 
284
            has_simple_revno=False)
249
285
 
250
286
 
251
287
class TestRevisionSpec_revid(TestRevisionSpec):
283
319
        self.assertInHistoryIs(3, revision_id, u'revid:\N{SNOWMAN}')
284
320
        self.assertInHistoryIs(3, revision_id, 'revid:' + revision_id)
285
321
 
 
322
    def test_supports_need_revno(self):
 
323
        self.assertInBranchSupportsNeedRevno('revid:r1')
 
324
        self.assertInBranchSupportsNeedRevno('revid:r2')
 
325
        self.assertInBranchSupportsNeedRevno('revid:alt_r2',
 
326
            has_simple_revno=False)
 
327
 
286
328
 
287
329
class TestRevisionSpec_last(TestRevisionSpec):
288
330
 
314
356
            pass
315
357
        self.assertInvalid('last:Y', extra='\n' + str(e))
316
358
 
 
359
    def test_supports_need_revno(self):
 
360
        self.assertInBranchSupportsNeedRevno('last:1')
 
361
 
317
362
 
318
363
class TestRevisionSpec_before(TestRevisionSpec):
319
364
 
345
390
                                          revision_id='new_r1')
346
391
        self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
347
392
 
 
393
    def test_supports_need_revno(self):
 
394
        self.assertInBranchSupportsNeedRevno('before:2')
 
395
        self.assertInBranchSupportsNeedRevno('before:revid:r2')
 
396
 
348
397
 
349
398
class TestRevisionSpec_tag(TestRevisionSpec):
350
399
    
369
418
            self.get_in_history,
370
419
            'tag:some-random-tag')
371
420
 
 
421
    def test_supports_need_revno(self):
 
422
        self.tree.branch.tags.set_tag('bzr-0.14', 'r1')
 
423
        self.assertInBranchSupportsNeedRevno('tag:bzr-0.14')
 
424
 
372
425
 
373
426
class TestRevisionSpec_date(TestRevisionSpec):
374
427
 
405
458
        self.assertInHistoryIs(2, 'new_r2',
406
459
            'date:%04d-%02d-%02d' % (now.year, now.month, now.day))
407
460
 
 
461
    def test_supports_need_revno(self):
 
462
        self.assertInBranchSupportsNeedRevno('date:today')
 
463
 
408
464
 
409
465
class TestRevisionSpec_ancestor(TestRevisionSpec):
410
466
    
448
504
                          spec_in_history, 'ancestor:tree',
449
505
                                           new_tree.branch)
450
506
 
 
507
    def test_supports_need_revno(self):
 
508
        self.assertInBranchSupportsNeedRevno('ancestor:tree2',
 
509
            has_simple_revno=False)
 
510
 
451
511
 
452
512
class TestRevisionSpec_branch(TestRevisionSpec):
453
513
    
482
542
        self.assertRaises(errors.NoCommits,
483
543
                          self.get_in_history, 'branch:new_tree')
484
544
 
 
545
    def test_supports_need_revno(self):
 
546
        self.assertInBranchSupportsNeedRevno('branch:tree2',
 
547
            has_simple_revno=False)
 
548
 
485
549
 
486
550
class TestRevisionSpec_submit(TestRevisionSpec):
487
551
 
497
561
        # submit branch overrides parent branch
498
562
        self.tree.branch.set_submit_branch('tree2')
499
563
        self.assertInHistoryIs(None, 'alt_r2', 'submit:')
 
564
 
 
565
    def test_supports_need_revno(self):
 
566
        self.tree.branch.set_submit_branch('tree2')
 
567
        self.assertInBranchSupportsNeedRevno('submit:',
 
568
            has_simple_revno=False)