/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: Andrew Bennetts
  • Date: 2008-09-08 12:59:00 UTC
  • mfrom: (3695 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080908125900-8ywtsr7jqyyatjz0
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
                         ' %r != %r'
74
74
                         % (revision_spec, exp_revision_id, rev_info.rev_id))
75
75
 
76
 
    def assertInvalid(self, revision_spec, extra=''):
 
76
    def assertInvalid(self, revision_spec, extra='',
 
77
                      invalid_as_revision_id=True):
77
78
        try:
78
79
            self.get_in_history(revision_spec)
79
80
        except errors.InvalidRevisionSpec, e:
80
81
            self.assertEqual(revision_spec, e.spec)
81
82
            self.assertEqual(extra, e.extra)
82
83
        else:
83
 
            self.fail('Expected InvalidRevisionSpec to be raised for %s'
84
 
                      % (revision_spec,))
 
84
            self.fail('Expected InvalidRevisionSpec to be raised for'
 
85
                      ' %r.in_history' % (revision_spec,))
 
86
        if invalid_as_revision_id:
 
87
            try:
 
88
                spec = RevisionSpec.from_string(revision_spec)
 
89
                spec.as_revision_id(self.tree.branch)
 
90
            except errors.InvalidRevisionSpec, e:
 
91
                self.assertEqual(revision_spec, e.spec)
 
92
                self.assertEqual(extra, e.extra)
 
93
            else:
 
94
                self.fail('Expected InvalidRevisionSpec to be raised for'
 
95
                          ' %r.as_revision_id' % (revision_spec,))
85
96
 
86
97
    def assertAsRevisionId(self, revision_id, revision_spec):
87
98
        """Calling as_revision_id() should return the specified id."""
90
101
                         spec.as_revision_id(self.tree.branch))
91
102
 
92
103
 
 
104
class RevisionSpecMatchOnTrap(RevisionSpec):
 
105
 
 
106
    def _match_on(self, branch, revs):
 
107
        self.last_call = (branch, revs)
 
108
        return super(RevisionSpecMatchOnTrap, self)._match_on(branch, revs)
 
109
 
 
110
 
 
111
class TestRevisionSpecBase(TestRevisionSpec):
 
112
 
 
113
    def test_wants_revision_history(self):
 
114
        # If wants_revision_history = True, then _match_on should get the
 
115
        # branch revision history
 
116
        spec = RevisionSpecMatchOnTrap('foo', _internal=True)
 
117
        spec.in_history(self.tree.branch)
 
118
 
 
119
        self.assertEqual((self.tree.branch, ['r1' ,'r2']),
 
120
                         spec.last_call)
 
121
 
 
122
    def test_wants_no_revision_history(self):
 
123
        # If wants_revision_history = False, then _match_on should get None for
 
124
        # the branch revision history
 
125
        spec = RevisionSpecMatchOnTrap('foo', _internal=True)
 
126
        spec.wants_revision_history = False
 
127
        spec.in_history(self.tree.branch)
 
128
 
 
129
        self.assertEqual((self.tree.branch, None), spec.last_call)
 
130
 
 
131
 
 
132
 
93
133
class TestOddRevisionSpec(TestRevisionSpec):
94
134
    """Test things that aren't normally thought of as revision specs"""
95
135
 
270
310
        self.assertInHistoryIs(2, 'r2', 'revid:r2')
271
311
        
272
312
    def test_missing(self):
273
 
        self.assertInvalid('revid:r3')
 
313
        self.assertInvalid('revid:r3', invalid_as_revision_id=False)
274
314
 
275
315
    def test_merged(self):
276
316
        """We can reach revisions in the ancestry"""
279
319
    def test_not_here(self):
280
320
        self.tree2.commit('alt third', rev_id='alt_r3')
281
321
        # It exists in tree2, but not in tree
282
 
        self.assertInvalid('revid:alt_r3')
 
322
        self.assertInvalid('revid:alt_r3', invalid_as_revision_id=False)
283
323
 
284
324
    def test_in_repository(self):
285
325
        """We can get any revision id in the repository"""