~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-07-29 11:17:57 UTC
  • mfrom: (5050.3.17 2.2)
  • mto: This revision was merged to the branch mainline in revision 5365.
  • Revision ID: andrew.bennetts@canonical.com-20100729111757-018h3pcefo7z0dnq
Merge lp:bzr/2.2 into lp:bzr.

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')
675
652
    def test_as_revision_id(self):
676
653
        self.tree.branch.set_submit_branch('tree2')
677
654
        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")