~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: Vincent Ladeuil
  • Date: 2012-02-14 17:22:37 UTC
  • mfrom: (6466 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120214172237-7dv7er3n4uy8d5m4
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from bzrlib import (
21
21
    errors,
22
22
    revision as _mod_revision,
 
23
    symbol_versioning,
23
24
    )
24
25
from bzrlib.tests import TestCaseWithTransport
25
26
from bzrlib.revisionspec import (
 
27
    RevisionInfo,
26
28
    RevisionSpec,
 
29
    RevisionSpec_dwim,
27
30
    RevisionSpec_tag,
28
31
    )
29
32
 
116
119
        # If wants_revision_history = True, then _match_on should get the
117
120
        # branch revision history
118
121
        spec = RevisionSpecMatchOnTrap('foo', _internal=True)
119
 
        spec.in_history(self.tree.branch)
 
122
        spec.wants_revision_history = True
 
123
        self.callDeprecated(['RevisionSpec.wants_revision_history was '
 
124
            'deprecated in 2.5 (RevisionSpecMatchOnTrap).'],
 
125
            spec.in_history, self.tree.branch)
120
126
 
121
127
        self.assertEqual((self.tree.branch, ['r1' ,'r2']),
122
128
                         spec.last_call)
125
131
        # If wants_revision_history = False, then _match_on should get None for
126
132
        # the branch revision history
127
133
        spec = RevisionSpecMatchOnTrap('foo', _internal=True)
128
 
        spec.wants_revision_history = False
129
134
        spec.in_history(self.tree.branch)
130
135
 
131
136
        self.assertEqual((self.tree.branch, None), spec.last_call)
142
147
        self.assertRaises(TypeError, RevisionSpec.from_string, object())
143
148
 
144
149
 
 
150
class RevisionSpec_bork(RevisionSpec):
 
151
 
 
152
    prefix = 'irrelevant:'
 
153
 
 
154
    def _match_on(self, branch, revs):
 
155
        if self.spec == "bork":
 
156
            return RevisionInfo.from_revision_id(branch, "r1")
 
157
        else:
 
158
            raise errors.InvalidRevisionSpec(self.spec, branch)
 
159
 
 
160
 
145
161
class TestRevisionSpec_dwim(TestRevisionSpec):
146
162
 
147
163
    # Don't need to test revno's explicitly since TRS_revno already
185
201
        self.assertInvalid('1.2..1', invalid_as_revision_id=False)
186
202
        self.assertInvalid('1.', invalid_as_revision_id=False)
187
203
 
 
204
    def test_append_dwim_revspec(self):
 
205
        original_dwim_revspecs = list(RevisionSpec_dwim._possible_revspecs)
 
206
        def reset_dwim_revspecs():
 
207
            RevisionSpec_dwim._possible_revspecs = original_dwim_revspecs
 
208
        self.addCleanup(reset_dwim_revspecs)
 
209
        RevisionSpec_dwim.append_possible_revspec(RevisionSpec_bork)
 
210
        self.assertAsRevisionId('r1', 'bork')
 
211
 
 
212
    def test_append_lazy_dwim_revspec(self):
 
213
        original_dwim_revspecs = list(RevisionSpec_dwim._possible_revspecs)
 
214
        def reset_dwim_revspecs():
 
215
            RevisionSpec_dwim._possible_revspecs = original_dwim_revspecs
 
216
        self.addCleanup(reset_dwim_revspecs)
 
217
        RevisionSpec_dwim.append_possible_lazy_revspec(
 
218
            "bzrlib.tests.test_revisionspec", "RevisionSpec_bork")
 
219
        self.assertAsRevisionId('r1', 'bork')
 
220
 
188
221
 
189
222
class TestRevisionSpec_revno(TestRevisionSpec):
190
223
 
367
400
        """We can get any revision id in the repository"""
368
401
        # XXX: This may change in the future, but for now, it is true
369
402
        self.tree2.commit('alt third', rev_id='alt_r3')
370
 
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
371
 
                                          revision_id='alt_r3')
 
403
        self.tree.branch.fetch(self.tree2.branch, 'alt_r3')
372
404
        self.assertInHistoryIs(None, 'alt_r3', 'revid:alt_r3')
373
405
 
374
406
    def test_unicode(self):
445
477
    def test_alt_no_parents(self):
446
478
        new_tree = self.make_branch_and_tree('new_tree')
447
479
        new_tree.commit('first', rev_id='new_r1')
448
 
        self.tree.branch.repository.fetch(new_tree.branch.repository,
449
 
                                          revision_id='new_r1')
 
480
        self.tree.branch.fetch(new_tree.branch, 'new_r1')
450
481
        self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
451
482
 
452
483
    def test_as_revision_id(self):
611
642
        # XXX: Right now, we use fetch() to make sure the remote revisions
612
643
        # have been pulled into the local branch. We may change that
613
644
        # behavior in the future.
614
 
        self.failUnless(self.tree.branch.repository.has_revision('new_r3'))
 
645
        self.assertTrue(self.tree.branch.repository.has_revision('new_r3'))
615
646
 
616
647
    def test_no_commits(self):
617
648
        new_tree = self.make_branch_and_tree('new_tree')