~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: Martin Pool
  • Date: 2011-04-19 07:52:11 UTC
  • mto: This revision was merged to the branch mainline in revision 5833.
  • Revision ID: mbp@sourcefrog.net-20110419075211-3m94qorhr0rg3gzg
Add and test _RulesSearcher.get_single_value

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
 
616
641
        # XXX: Right now, we use fetch() to make sure the remote revisions
617
642
        # have been pulled into the local branch. We may change that
618
643
        # behavior in the future.
619
 
        self.failUnless(self.tree.branch.repository.has_revision('new_r3'))
 
644
        self.assertTrue(self.tree.branch.repository.has_revision('new_r3'))
620
645
 
621
646
    def test_no_commits(self):
622
647
        new_tree = self.make_branch_and_tree('new_tree')
652
677
    def test_as_revision_id(self):
653
678
        self.tree.branch.set_submit_branch('tree2')
654
679
        self.assertAsRevisionId('alt_r2', 'branch:tree2')
 
680
 
 
681
 
 
682
class TestRevisionSpec_mainline(TestRevisionSpec):
 
683
 
 
684
    def test_as_revision_id(self):
 
685
        self.assertAsRevisionId('r1', 'mainline:1')
 
686
        self.assertAsRevisionId('r2', 'mainline:1.1.1')
 
687
        self.assertAsRevisionId('r2', 'mainline:revid:alt_r2')
 
688
        spec = RevisionSpec.from_string('mainline:revid:alt_r22')
 
689
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
690
                              spec.as_revision_id, self.tree.branch)
 
691
        self.assertContainsRe(str(e),
 
692
            "Requested revision: 'mainline:revid:alt_r22' does not exist in"
 
693
            " branch: ")
 
694
 
 
695
    def test_in_history(self):
 
696
        self.assertInHistoryIs(2, 'r2', 'mainline:revid:alt_r2')
 
697
 
 
698
 
 
699
class TestRevisionSpec_annotate(TestRevisionSpec):
 
700
 
 
701
    def setUp(self):
 
702
        TestRevisionSpec.setUp(self)
 
703
        self.tree = self.make_branch_and_tree('annotate-tree')
 
704
        self.build_tree_contents([('annotate-tree/file1', '1\n')])
 
705
        self.tree.add('file1')
 
706
        self.tree.commit('r1', rev_id='r1')
 
707
        self.build_tree_contents([('annotate-tree/file1', '2\n1\n')])
 
708
        self.tree.commit('r2', rev_id='r2')
 
709
        self.build_tree_contents([('annotate-tree/file1', '2\n1\n3\n')])
 
710
 
 
711
    def test_as_revision_id_r1(self):
 
712
        self.assertAsRevisionId('r1', 'annotate:annotate-tree/file1:2')
 
713
 
 
714
    def test_as_revision_id_r2(self):
 
715
        self.assertAsRevisionId('r2', 'annotate:annotate-tree/file1:1')
 
716
 
 
717
    def test_as_revision_id_uncommitted(self):
 
718
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:3')
 
719
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
720
                              spec.as_revision_id, self.tree.branch)
 
721
        self.assertContainsRe(str(e),
 
722
            r"Requested revision: \'annotate:annotate-tree/file1:3\' does not"
 
723
            " exist in branch: .*\nLine 3 has not been committed.")
 
724
 
 
725
    def test_non_existent_line(self):
 
726
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:4')
 
727
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
728
                              spec.as_revision_id, self.tree.branch)
 
729
        self.assertContainsRe(str(e),
 
730
            r"Requested revision: \'annotate:annotate-tree/file1:4\' does not"
 
731
            " exist in branch: .*\nNo such line: 4")
 
732
 
 
733
    def test_invalid_line(self):
 
734
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:q')
 
735
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
736
                              spec.as_revision_id, self.tree.branch)
 
737
        self.assertContainsRe(str(e),
 
738
            r"Requested revision: \'annotate:annotate-tree/file1:q\' does not"
 
739
            " exist in branch: .*\nNo such line: q")
 
740
 
 
741
    def test_no_such_file(self):
 
742
        spec = RevisionSpec.from_string('annotate:annotate-tree/file2:1')
 
743
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
744
                              spec.as_revision_id, self.tree.branch)
 
745
        self.assertContainsRe(str(e),
 
746
            r"Requested revision: \'annotate:annotate-tree/file2:1\' does not"
 
747
            " exist in branch: .*\nFile 'file2' is not versioned")
 
748
 
 
749
    def test_no_such_file_with_colon(self):
 
750
        spec = RevisionSpec.from_string('annotate:annotate-tree/fi:le2:1')
 
751
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
752
                              spec.as_revision_id, self.tree.branch)
 
753
        self.assertContainsRe(str(e),
 
754
            r"Requested revision: \'annotate:annotate-tree/fi:le2:1\' does not"
 
755
            " exist in branch: .*\nFile 'fi:le2' is not versioned")