74
74
% (revision_spec, exp_revision_id, rev_info.rev_id))
76
def assertInvalid(self, revision_spec, extra=''):
76
def assertInvalid(self, revision_spec, extra='',
77
invalid_as_revision_id=True):
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)
83
self.fail('Expected InvalidRevisionSpec to be raised for %s'
84
self.fail('Expected InvalidRevisionSpec to be raised for'
85
' %r.in_history' % (revision_spec,))
86
if invalid_as_revision_id:
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)
94
self.fail('Expected InvalidRevisionSpec to be raised for'
95
' %r.as_revision_id' % (revision_spec,))
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))
104
class RevisionSpecMatchOnTrap(RevisionSpec):
106
def _match_on(self, branch, revs):
107
self.last_call = (branch, revs)
108
return super(RevisionSpecMatchOnTrap, self)._match_on(branch, revs)
111
class TestRevisionSpecBase(TestRevisionSpec):
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)
119
self.assertEqual((self.tree.branch, ['r1' ,'r2']),
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)
129
self.assertEqual((self.tree.branch, None), spec.last_call)
93
133
class TestOddRevisionSpec(TestRevisionSpec):
94
134
"""Test things that aren't normally thought of as revision specs"""
270
310
self.assertInHistoryIs(2, 'r2', 'revid:r2')
272
312
def test_missing(self):
273
self.assertInvalid('revid:r3')
313
self.assertInvalid('revid:r3', invalid_as_revision_id=False)
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)
284
324
def test_in_repository(self):
285
325
"""We can get any revision id in the repository"""