~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: John Arbash Meinel
  • Date: 2011-09-26 12:12:40 UTC
  • mto: This revision was merged to the branch mainline in revision 6170.
  • Revision ID: john@arbash-meinel.com-20110926121240-vdlz94tgi2i6py0f
Jelmer caught that getsignal() only takes one parameter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
19
18
import time
20
19
 
21
20
from bzrlib import (
22
 
    branch,
23
 
    bzrdir,
24
21
    errors,
25
 
    repository,
26
22
    revision as _mod_revision,
27
23
    )
28
 
from bzrlib.tests import TestCase, TestCaseWithTransport
 
24
from bzrlib.tests import TestCaseWithTransport
29
25
from bzrlib.revisionspec import (
 
26
    RevisionInfo,
30
27
    RevisionSpec,
31
 
    RevisionSpec_revno,
 
28
    RevisionSpec_dwim,
32
29
    RevisionSpec_tag,
33
30
    )
34
31
 
147
144
        self.assertRaises(TypeError, RevisionSpec.from_string, object())
148
145
 
149
146
 
 
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
 
150
158
class TestRevisionSpec_dwim(TestRevisionSpec):
151
159
 
152
160
    # Don't need to test revno's explicitly since TRS_revno already
190
198
        self.assertInvalid('1.2..1', invalid_as_revision_id=False)
191
199
        self.assertInvalid('1.', invalid_as_revision_id=False)
192
200
 
 
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
 
193
218
 
194
219
class TestRevisionSpec_revno(TestRevisionSpec):
195
220
 
372
397
        """We can get any revision id in the repository"""
373
398
        # XXX: This may change in the future, but for now, it is true
374
399
        self.tree2.commit('alt third', rev_id='alt_r3')
375
 
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
376
 
                                          revision_id='alt_r3')
 
400
        self.tree.branch.fetch(self.tree2.branch, 'alt_r3')
377
401
        self.assertInHistoryIs(None, 'alt_r3', 'revid:alt_r3')
378
402
 
379
403
    def test_unicode(self):
450
474
    def test_alt_no_parents(self):
451
475
        new_tree = self.make_branch_and_tree('new_tree')
452
476
        new_tree.commit('first', rev_id='new_r1')
453
 
        self.tree.branch.repository.fetch(new_tree.branch.repository,
454
 
                                          revision_id='new_r1')
 
477
        self.tree.branch.fetch(new_tree.branch, 'new_r1')
455
478
        self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
456
479
 
457
480
    def test_as_revision_id(self):
616
639
        # XXX: Right now, we use fetch() to make sure the remote revisions
617
640
        # have been pulled into the local branch. We may change that
618
641
        # behavior in the future.
619
 
        self.failUnless(self.tree.branch.repository.has_revision('new_r3'))
 
642
        self.assertTrue(self.tree.branch.repository.has_revision('new_r3'))
620
643
 
621
644
    def test_no_commits(self):
622
645
        new_tree = self.make_branch_and_tree('new_tree')
652
675
    def test_as_revision_id(self):
653
676
        self.tree.branch.set_submit_branch('tree2')
654
677
        self.assertAsRevisionId('alt_r2', 'branch:tree2')
 
678
 
 
679
 
 
680
class TestRevisionSpec_mainline(TestRevisionSpec):
 
681
 
 
682
    def test_as_revision_id(self):
 
683
        self.assertAsRevisionId('r1', 'mainline:1')
 
684
        self.assertAsRevisionId('r2', 'mainline:1.1.1')
 
685
        self.assertAsRevisionId('r2', 'mainline:revid:alt_r2')
 
686
        spec = RevisionSpec.from_string('mainline:revid:alt_r22')
 
687
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
688
                              spec.as_revision_id, self.tree.branch)
 
689
        self.assertContainsRe(str(e),
 
690
            "Requested revision: 'mainline:revid:alt_r22' does not exist in"
 
691
            " branch: ")
 
692
 
 
693
    def test_in_history(self):
 
694
        self.assertInHistoryIs(2, 'r2', 'mainline:revid:alt_r2')
 
695
 
 
696
 
 
697
class TestRevisionSpec_annotate(TestRevisionSpec):
 
698
 
 
699
    def setUp(self):
 
700
        TestRevisionSpec.setUp(self)
 
701
        self.tree = self.make_branch_and_tree('annotate-tree')
 
702
        self.build_tree_contents([('annotate-tree/file1', '1\n')])
 
703
        self.tree.add('file1')
 
704
        self.tree.commit('r1', rev_id='r1')
 
705
        self.build_tree_contents([('annotate-tree/file1', '2\n1\n')])
 
706
        self.tree.commit('r2', rev_id='r2')
 
707
        self.build_tree_contents([('annotate-tree/file1', '2\n1\n3\n')])
 
708
 
 
709
    def test_as_revision_id_r1(self):
 
710
        self.assertAsRevisionId('r1', 'annotate:annotate-tree/file1:2')
 
711
 
 
712
    def test_as_revision_id_r2(self):
 
713
        self.assertAsRevisionId('r2', 'annotate:annotate-tree/file1:1')
 
714
 
 
715
    def test_as_revision_id_uncommitted(self):
 
716
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:3')
 
717
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
718
                              spec.as_revision_id, self.tree.branch)
 
719
        self.assertContainsRe(str(e),
 
720
            r"Requested revision: \'annotate:annotate-tree/file1:3\' does not"
 
721
            " exist in branch: .*\nLine 3 has not been committed.")
 
722
 
 
723
    def test_non_existent_line(self):
 
724
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:4')
 
725
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
726
                              spec.as_revision_id, self.tree.branch)
 
727
        self.assertContainsRe(str(e),
 
728
            r"Requested revision: \'annotate:annotate-tree/file1:4\' does not"
 
729
            " exist in branch: .*\nNo such line: 4")
 
730
 
 
731
    def test_invalid_line(self):
 
732
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:q')
 
733
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
734
                              spec.as_revision_id, self.tree.branch)
 
735
        self.assertContainsRe(str(e),
 
736
            r"Requested revision: \'annotate:annotate-tree/file1:q\' does not"
 
737
            " exist in branch: .*\nNo such line: q")
 
738
 
 
739
    def test_no_such_file(self):
 
740
        spec = RevisionSpec.from_string('annotate:annotate-tree/file2:1')
 
741
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
742
                              spec.as_revision_id, self.tree.branch)
 
743
        self.assertContainsRe(str(e),
 
744
            r"Requested revision: \'annotate:annotate-tree/file2:1\' does not"
 
745
            " exist in branch: .*\nFile 'file2' is not versioned")
 
746
 
 
747
    def test_no_such_file_with_colon(self):
 
748
        spec = RevisionSpec.from_string('annotate:annotate-tree/fi:le2:1')
 
749
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
750
                              spec.as_revision_id, self.tree.branch)
 
751
        self.assertContainsRe(str(e),
 
752
            r"Requested revision: \'annotate:annotate-tree/fi:le2:1\' does not"
 
753
            " exist in branch: .*\nFile 'fi:le2' is not versioned")