~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: Andrew Starr-Bochicchio
  • Date: 2015-07-31 01:04:41 UTC
  • mto: This revision was merged to the branch mainline in revision 6606.
  • Revision ID: a.starr.b@gmail.com-20150731010441-3domwjjtnjijxlr2
Use hexlify() from binascii directly as paramiko removed hexify().

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,
 
23
    symbol_versioning,
27
24
    )
28
 
from bzrlib.tests import TestCase, TestCaseWithTransport
 
25
from bzrlib.tests import TestCaseWithTransport
29
26
from bzrlib.revisionspec import (
 
27
    RevisionInfo,
30
28
    RevisionSpec,
31
 
    RevisionSpec_revno,
 
29
    RevisionSpec_dwim,
32
30
    RevisionSpec_tag,
33
31
    )
34
32
 
121
119
        # If wants_revision_history = True, then _match_on should get the
122
120
        # branch revision history
123
121
        spec = RevisionSpecMatchOnTrap('foo', _internal=True)
124
 
        spec.in_history(self.tree.branch)
 
122
        spec.wants_revision_history = True
 
123
        self.callDeprecated(['RevisionSpec.wants_revision_history was '
 
124
            'deprecated in 2.5 (RevisionSpecMatchOnTrap).'],
 
125
            spec.in_history, self.tree.branch)
125
126
 
126
127
        self.assertEqual((self.tree.branch, ['r1' ,'r2']),
127
128
                         spec.last_call)
130
131
        # If wants_revision_history = False, then _match_on should get None for
131
132
        # the branch revision history
132
133
        spec = RevisionSpecMatchOnTrap('foo', _internal=True)
133
 
        spec.wants_revision_history = False
134
134
        spec.in_history(self.tree.branch)
135
135
 
136
136
        self.assertEqual((self.tree.branch, None), spec.last_call)
147
147
        self.assertRaises(TypeError, RevisionSpec.from_string, object())
148
148
 
149
149
 
 
150
class RevisionSpec_bork(RevisionSpec):
 
151
 
 
152
    prefix = 'irrelevant:'
 
153
 
 
154
    def _match_on(self, branch, revs):
 
155
        if self.spec == "bork":
 
156
            return RevisionInfo.from_revision_id(branch, "r1")
 
157
        else:
 
158
            raise errors.InvalidRevisionSpec(self.spec, branch)
 
159
 
 
160
 
150
161
class TestRevisionSpec_dwim(TestRevisionSpec):
151
162
 
152
163
    # Don't need to test revno's explicitly since TRS_revno already
190
201
        self.assertInvalid('1.2..1', invalid_as_revision_id=False)
191
202
        self.assertInvalid('1.', invalid_as_revision_id=False)
192
203
 
 
204
    def test_append_dwim_revspec(self):
 
205
        original_dwim_revspecs = list(RevisionSpec_dwim._possible_revspecs)
 
206
        def reset_dwim_revspecs():
 
207
            RevisionSpec_dwim._possible_revspecs = original_dwim_revspecs
 
208
        self.addCleanup(reset_dwim_revspecs)
 
209
        RevisionSpec_dwim.append_possible_revspec(RevisionSpec_bork)
 
210
        self.assertAsRevisionId('r1', 'bork')
 
211
 
 
212
    def test_append_lazy_dwim_revspec(self):
 
213
        original_dwim_revspecs = list(RevisionSpec_dwim._possible_revspecs)
 
214
        def reset_dwim_revspecs():
 
215
            RevisionSpec_dwim._possible_revspecs = original_dwim_revspecs
 
216
        self.addCleanup(reset_dwim_revspecs)
 
217
        RevisionSpec_dwim.append_possible_lazy_revspec(
 
218
            "bzrlib.tests.test_revisionspec", "RevisionSpec_bork")
 
219
        self.assertAsRevisionId('r1', 'bork')
 
220
 
193
221
 
194
222
class TestRevisionSpec_revno(TestRevisionSpec):
195
223
 
372
400
        """We can get any revision id in the repository"""
373
401
        # XXX: This may change in the future, but for now, it is true
374
402
        self.tree2.commit('alt third', rev_id='alt_r3')
375
 
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
376
 
                                          revision_id='alt_r3')
 
403
        self.tree.branch.fetch(self.tree2.branch, 'alt_r3')
377
404
        self.assertInHistoryIs(None, 'alt_r3', 'revid:alt_r3')
378
405
 
379
406
    def test_unicode(self):
450
477
    def test_alt_no_parents(self):
451
478
        new_tree = self.make_branch_and_tree('new_tree')
452
479
        new_tree.commit('first', rev_id='new_r1')
453
 
        self.tree.branch.repository.fetch(new_tree.branch.repository,
454
 
                                          revision_id='new_r1')
 
480
        self.tree.branch.fetch(new_tree.branch, 'new_r1')
455
481
        self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
456
482
 
457
483
    def test_as_revision_id(self):
616
642
        # XXX: Right now, we use fetch() to make sure the remote revisions
617
643
        # have been pulled into the local branch. We may change that
618
644
        # behavior in the future.
619
 
        self.failUnless(self.tree.branch.repository.has_revision('new_r3'))
 
645
        self.assertTrue(self.tree.branch.repository.has_revision('new_r3'))
620
646
 
621
647
    def test_no_commits(self):
622
648
        new_tree = self.make_branch_and_tree('new_tree')
652
678
    def test_as_revision_id(self):
653
679
        self.tree.branch.set_submit_branch('tree2')
654
680
        self.assertAsRevisionId('alt_r2', 'branch:tree2')
 
681
 
 
682
 
 
683
class TestRevisionSpec_mainline(TestRevisionSpec):
 
684
 
 
685
    def test_as_revision_id(self):
 
686
        self.assertAsRevisionId('r1', 'mainline:1')
 
687
        self.assertAsRevisionId('r2', 'mainline:1.1.1')
 
688
        self.assertAsRevisionId('r2', 'mainline:revid:alt_r2')
 
689
        spec = RevisionSpec.from_string('mainline:revid:alt_r22')
 
690
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
691
                              spec.as_revision_id, self.tree.branch)
 
692
        self.assertContainsRe(str(e),
 
693
            "Requested revision: 'mainline:revid:alt_r22' does not exist in"
 
694
            " branch: ")
 
695
 
 
696
    def test_in_history(self):
 
697
        self.assertInHistoryIs(2, 'r2', 'mainline:revid:alt_r2')
 
698
 
 
699
 
 
700
class TestRevisionSpec_annotate(TestRevisionSpec):
 
701
 
 
702
    def setUp(self):
 
703
        super(TestRevisionSpec_annotate, self).setUp()
 
704
        self.tree = self.make_branch_and_tree('annotate-tree')
 
705
        self.build_tree_contents([('annotate-tree/file1', '1\n')])
 
706
        self.tree.add('file1')
 
707
        self.tree.commit('r1', rev_id='r1')
 
708
        self.build_tree_contents([('annotate-tree/file1', '2\n1\n')])
 
709
        self.tree.commit('r2', rev_id='r2')
 
710
        self.build_tree_contents([('annotate-tree/file1', '2\n1\n3\n')])
 
711
 
 
712
    def test_as_revision_id_r1(self):
 
713
        self.assertAsRevisionId('r1', 'annotate:annotate-tree/file1:2')
 
714
 
 
715
    def test_as_revision_id_r2(self):
 
716
        self.assertAsRevisionId('r2', 'annotate:annotate-tree/file1:1')
 
717
 
 
718
    def test_as_revision_id_uncommitted(self):
 
719
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:3')
 
720
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
721
                              spec.as_revision_id, self.tree.branch)
 
722
        self.assertContainsRe(str(e),
 
723
            r"Requested revision: \'annotate:annotate-tree/file1:3\' does not"
 
724
            " exist in branch: .*\nLine 3 has not been committed.")
 
725
 
 
726
    def test_non_existent_line(self):
 
727
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:4')
 
728
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
729
                              spec.as_revision_id, self.tree.branch)
 
730
        self.assertContainsRe(str(e),
 
731
            r"Requested revision: \'annotate:annotate-tree/file1:4\' does not"
 
732
            " exist in branch: .*\nNo such line: 4")
 
733
 
 
734
    def test_invalid_line(self):
 
735
        spec = RevisionSpec.from_string('annotate:annotate-tree/file1:q')
 
736
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
737
                              spec.as_revision_id, self.tree.branch)
 
738
        self.assertContainsRe(str(e),
 
739
            r"Requested revision: \'annotate:annotate-tree/file1:q\' does not"
 
740
            " exist in branch: .*\nNo such line: q")
 
741
 
 
742
    def test_no_such_file(self):
 
743
        spec = RevisionSpec.from_string('annotate:annotate-tree/file2:1')
 
744
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
745
                              spec.as_revision_id, self.tree.branch)
 
746
        self.assertContainsRe(str(e),
 
747
            r"Requested revision: \'annotate:annotate-tree/file2:1\' does not"
 
748
            " exist in branch: .*\nFile 'file2' is not versioned")
 
749
 
 
750
    def test_no_such_file_with_colon(self):
 
751
        spec = RevisionSpec.from_string('annotate:annotate-tree/fi:le2:1')
 
752
        e = self.assertRaises(errors.InvalidRevisionSpec,
 
753
                              spec.as_revision_id, self.tree.branch)
 
754
        self.assertContainsRe(str(e),
 
755
            r"Requested revision: \'annotate:annotate-tree/fi:le2:1\' does not"
 
756
            " exist in branch: .*\nFile 'fi:le2' is not versioned")