~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-13 00:26:41 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101013002641-9tlh9k89mlj1666m
Keep docs-plain working.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import datetime
 
18
import os
18
19
import time
19
20
 
20
21
from bzrlib import (
 
22
    branch,
 
23
    bzrdir,
21
24
    errors,
 
25
    repository,
22
26
    revision as _mod_revision,
23
27
    )
24
 
from bzrlib.tests import TestCaseWithTransport
 
28
from bzrlib.tests import TestCase, TestCaseWithTransport
25
29
from bzrlib.revisionspec import (
26
 
    RevisionInfo,
27
30
    RevisionSpec,
28
 
    RevisionSpec_dwim,
 
31
    RevisionSpec_revno,
29
32
    RevisionSpec_tag,
30
33
    )
31
34
 
144
147
        self.assertRaises(TypeError, RevisionSpec.from_string, object())
145
148
 
146
149
 
147
 
class RevisionSpec_bork(RevisionSpec):
148
 
 
149
 
    prefix = 'irrelevant:'
150
 
 
151
 
    def _match_on(self, branch, revs):
152
 
        if self.spec == "bork":
153
 
            return RevisionInfo.from_revision_id(branch, "r1", revs)
154
 
        else:
155
 
            raise errors.InvalidRevisionSpec(self.spec, branch)
156
 
 
157
 
 
158
150
class TestRevisionSpec_dwim(TestRevisionSpec):
159
151
 
160
152
    # Don't need to test revno's explicitly since TRS_revno already
198
190
        self.assertInvalid('1.2..1', invalid_as_revision_id=False)
199
191
        self.assertInvalid('1.', invalid_as_revision_id=False)
200
192
 
201
 
    def test_append_dwim_revspec(self):
202
 
        original_dwim_revspecs = list(RevisionSpec_dwim._possible_revspecs)
203
 
        def reset_dwim_revspecs():
204
 
            RevisionSpec_dwim._possible_revspecs = original_dwim_revspecs
205
 
        self.addCleanup(reset_dwim_revspecs)
206
 
        RevisionSpec_dwim.append_possible_revspec(RevisionSpec_bork)
207
 
        self.assertAsRevisionId('r1', 'bork')
208
 
 
209
 
    def test_append_lazy_dwim_revspec(self):
210
 
        original_dwim_revspecs = list(RevisionSpec_dwim._possible_revspecs)
211
 
        def reset_dwim_revspecs():
212
 
            RevisionSpec_dwim._possible_revspecs = original_dwim_revspecs
213
 
        self.addCleanup(reset_dwim_revspecs)
214
 
        RevisionSpec_dwim.append_possible_lazy_revspec(
215
 
            "bzrlib.tests.test_revisionspec", "RevisionSpec_bork")
216
 
        self.assertAsRevisionId('r1', 'bork')
217
 
 
218
193
 
219
194
class TestRevisionSpec_revno(TestRevisionSpec):
220
195
 
397
372
        """We can get any revision id in the repository"""
398
373
        # XXX: This may change in the future, but for now, it is true
399
374
        self.tree2.commit('alt third', rev_id='alt_r3')
400
 
        self.tree.branch.fetch(self.tree2.branch, 'alt_r3')
 
375
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
 
376
                                          revision_id='alt_r3')
401
377
        self.assertInHistoryIs(None, 'alt_r3', 'revid:alt_r3')
402
378
 
403
379
    def test_unicode(self):
474
450
    def test_alt_no_parents(self):
475
451
        new_tree = self.make_branch_and_tree('new_tree')
476
452
        new_tree.commit('first', rev_id='new_r1')
477
 
        self.tree.branch.fetch(new_tree.branch, 'new_r1')
 
453
        self.tree.branch.repository.fetch(new_tree.branch.repository,
 
454
                                          revision_id='new_r1')
478
455
        self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
479
456
 
480
457
    def test_as_revision_id(self):
639
616
        # XXX: Right now, we use fetch() to make sure the remote revisions
640
617
        # have been pulled into the local branch. We may change that
641
618
        # behavior in the future.
642
 
        self.assertTrue(self.tree.branch.repository.has_revision('new_r3'))
 
619
        self.failUnless(self.tree.branch.repository.has_revision('new_r3'))
643
620
 
644
621
    def test_no_commits(self):
645
622
        new_tree = self.make_branch_and_tree('new_tree')