~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: Robert Collins
  • Date: 2010-05-06 07:48:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506074822-0bsgf2j4h8jx0xkk
Added ``bzrlib.tests.matchers`` as a place to put matchers, along with
our first in-tree matcher. See the module docstring for details.
(Robert Collins)

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
30
    RevisionSpec,
 
31
    RevisionSpec_revno,
27
32
    RevisionSpec_tag,
28
33
    )
29
34
 
647
652
    def test_as_revision_id(self):
648
653
        self.tree.branch.set_submit_branch('tree2')
649
654
        self.assertAsRevisionId('alt_r2', 'branch:tree2')
650
 
 
651
 
 
652
 
class TestRevisionSpec_mainline(TestRevisionSpec):
653
 
 
654
 
    def test_as_revision_id(self):
655
 
        self.assertAsRevisionId('r1', 'mainline:1')
656
 
        self.assertAsRevisionId('r2', 'mainline:1.1.1')
657
 
        self.assertAsRevisionId('r2', 'mainline:revid:alt_r2')
658
 
        spec = RevisionSpec.from_string('mainline:revid:alt_r22')
659
 
        e = self.assertRaises(errors.InvalidRevisionSpec,
660
 
                              spec.as_revision_id, self.tree.branch)
661
 
        self.assertContainsRe(str(e),
662
 
            "Requested revision: 'mainline:revid:alt_r22' does not exist in"
663
 
            " branch: ")
664
 
 
665
 
    def test_in_history(self):
666
 
        self.assertInHistoryIs(2, 'r2', 'mainline:revid:alt_r2')
667
 
 
668
 
 
669
 
class TestRevisionSpec_annotate(TestRevisionSpec):
670
 
 
671
 
    def setUp(self):
672
 
        TestRevisionSpec.setUp(self)
673
 
        self.tree = self.make_branch_and_tree('annotate-tree')
674
 
        self.build_tree_contents([('annotate-tree/file1', '1\n')])
675
 
        self.tree.add('file1')
676
 
        self.tree.commit('r1', rev_id='r1')
677
 
        self.build_tree_contents([('annotate-tree/file1', '2\n1\n')])
678
 
        self.tree.commit('r2', rev_id='r2')
679
 
        self.build_tree_contents([('annotate-tree/file1', '2\n1\n3\n')])
680
 
 
681
 
    def test_as_revision_id_r1(self):
682
 
        self.assertAsRevisionId('r1', 'annotate:annotate-tree/file1:2')
683
 
 
684
 
    def test_as_revision_id_r2(self):
685
 
        self.assertAsRevisionId('r2', 'annotate:annotate-tree/file1:1')
686
 
 
687
 
    def test_as_revision_id_uncommitted(self):
688
 
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:3')
689
 
        e = self.assertRaises(errors.InvalidRevisionSpec,
690
 
                              spec.as_revision_id, self.tree.branch)
691
 
        self.assertContainsRe(str(e),
692
 
            r"Requested revision: \'annotate:annotate-tree/file1:3\' does not"
693
 
            " exist in branch: .*\nLine 3 has not been committed.")
694
 
 
695
 
    def test_non_existent_line(self):
696
 
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:4')
697
 
        e = self.assertRaises(errors.InvalidRevisionSpec,
698
 
                              spec.as_revision_id, self.tree.branch)
699
 
        self.assertContainsRe(str(e),
700
 
            r"Requested revision: \'annotate:annotate-tree/file1:4\' does not"
701
 
            " exist in branch: .*\nNo such line: 4")
702
 
 
703
 
    def test_invalid_line(self):
704
 
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:q')
705
 
        e = self.assertRaises(errors.InvalidRevisionSpec,
706
 
                              spec.as_revision_id, self.tree.branch)
707
 
        self.assertContainsRe(str(e),
708
 
            r"Requested revision: \'annotate:annotate-tree/file1:q\' does not"
709
 
            " exist in branch: .*\nNo such line: q")
710
 
 
711
 
    def test_no_such_file(self):
712
 
        spec = RevisionSpec.from_string('annotate:annotate-tree/file2:1')
713
 
        e = self.assertRaises(errors.InvalidRevisionSpec,
714
 
                              spec.as_revision_id, self.tree.branch)
715
 
        self.assertContainsRe(str(e),
716
 
            r"Requested revision: \'annotate:annotate-tree/file2:1\' does not"
717
 
            " exist in branch: .*\nFile 'file2' is not versioned")
718
 
 
719
 
    def test_no_such_file_with_colon(self):
720
 
        spec = RevisionSpec.from_string('annotate:annotate-tree/fi:le2:1')
721
 
        e = self.assertRaises(errors.InvalidRevisionSpec,
722
 
                              spec.as_revision_id, self.tree.branch)
723
 
        self.assertContainsRe(str(e),
724
 
            r"Requested revision: \'annotate:annotate-tree/fi:le2:1\' does not"
725
 
            " exist in branch: .*\nFile 'fi:le2' is not versioned")