~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-02-12 06:24:08 UTC
  • mfrom: (4000.2.4 test-result-registry)
  • Revision ID: pqm@pqm.ubuntu.com-20090212062408-yq0glwncmdzo5uzm
(robertc) Allow plugins to specify test runner classes for
        cmd_selftest. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006, 2007 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
 
143
146
    def test_object(self):
144
147
        self.assertRaises(TypeError, RevisionSpec.from_string, object())
145
148
 
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
 
 
158
 
class TestRevisionSpec_dwim(TestRevisionSpec):
159
 
 
160
 
    # Don't need to test revno's explicitly since TRS_revno already
161
 
    # covers that well for us
162
 
    def test_dwim_spec_revno(self):
163
 
        self.assertInHistoryIs(2, 'r2', '2')
164
 
        self.assertAsRevisionId('alt_r2', '1.1.1')
165
 
 
166
 
    def test_dwim_spec_revid(self):
167
 
        self.assertInHistoryIs(2, 'r2', 'r2')
168
 
 
169
 
    def test_dwim_spec_tag(self):
170
 
        self.tree.branch.tags.set_tag('footag', 'r1')
171
 
        self.assertAsRevisionId('r1', 'footag')
172
 
        self.tree.branch.tags.delete_tag('footag')
173
 
        self.assertRaises(errors.InvalidRevisionSpec,
174
 
                          self.get_in_history, 'footag')
175
 
 
176
 
    def test_dwim_spec_tag_that_looks_like_revno(self):
177
 
        # Test that we slip past revno with things that look like revnos,
178
 
        # but aren't.  Tags are convenient for testing this since we can
179
 
        # make them look however we want.
180
 
        self.tree.branch.tags.set_tag('3', 'r2')
181
 
        self.assertAsRevisionId('r2', '3')
182
 
        self.build_tree(['tree/b'])
183
 
        self.tree.add(['b'])
184
 
        self.tree.commit('b', rev_id='r3')
185
 
        self.assertAsRevisionId('r3', '3')
186
 
 
187
 
    def test_dwim_spec_date(self):
188
 
        self.assertAsRevisionId('r1', 'today')
189
 
 
190
 
    def test_dwim_spec_branch(self):
191
 
        self.assertInHistoryIs(None, 'alt_r2', 'tree2')
192
 
 
193
 
    def test_dwim_spec_nonexistent(self):
194
 
        self.assertInvalid('somethingrandom', invalid_as_revision_id=False)
195
 
        self.assertInvalid('-1.1', invalid_as_revision_id=False)
196
 
        self.assertInvalid('.1', invalid_as_revision_id=False)
197
 
        self.assertInvalid('1..1', invalid_as_revision_id=False)
198
 
        self.assertInvalid('1.2..1', invalid_as_revision_id=False)
199
 
        self.assertInvalid('1.', invalid_as_revision_id=False)
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')
 
149
    def test_unregistered_spec(self):
 
150
        self.assertRaises(errors.NoSuchRevisionSpec,
 
151
                          RevisionSpec.from_string, 'foo')
 
152
        self.assertRaises(errors.NoSuchRevisionSpec,
 
153
                          RevisionSpec.from_string, '123a')
 
154
 
 
155
 
 
156
 
 
157
class TestRevnoFromString(TestCase):
 
158
 
 
159
    def test_from_string_dotted_decimal(self):
 
160
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '-1.1')
 
161
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '.1')
 
162
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1..1')
 
163
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1.2..1')
 
164
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1.')
 
165
        self.assertIsInstance(RevisionSpec.from_string('1.1'), RevisionSpec_revno)
 
166
        self.assertIsInstance(RevisionSpec.from_string('1.1.3'), RevisionSpec_revno)
217
167
 
218
168
 
219
169
class TestRevisionSpec_revno(TestRevisionSpec):
326
276
        """Old revno:N:path tests"""
327
277
        wta = self.make_branch_and_tree('a')
328
278
        ba = wta.branch
329
 
 
 
279
        
330
280
        wta.commit('Commit one', rev_id='a@r-0-1')
331
281
        wta.commit('Commit two', rev_id='a@r-0-2')
332
282
        wta.commit('Commit three', rev_id='a@r-0-3')
374
324
 
375
325
 
376
326
class TestRevisionSpec_revid(TestRevisionSpec):
377
 
 
 
327
    
378
328
    def test_in_history(self):
379
329
        # We should be able to access revisions that are directly
380
330
        # in the history.
381
331
        self.assertInHistoryIs(1, 'r1', 'revid:r1')
382
332
        self.assertInHistoryIs(2, 'r2', 'revid:r2')
383
 
 
 
333
        
384
334
    def test_missing(self):
385
335
        self.assertInvalid('revid:r3', invalid_as_revision_id=False)
386
336
 
397
347
        """We can get any revision id in the repository"""
398
348
        # XXX: This may change in the future, but for now, it is true
399
349
        self.tree2.commit('alt third', rev_id='alt_r3')
400
 
        self.tree.branch.fetch(self.tree2.branch, 'alt_r3')
 
350
        self.tree.branch.repository.fetch(self.tree2.branch.repository,
 
351
                                          revision_id='alt_r3')
401
352
        self.assertInHistoryIs(None, 'alt_r3', 'revid:alt_r3')
402
353
 
403
354
    def test_unicode(self):
474
425
    def test_alt_no_parents(self):
475
426
        new_tree = self.make_branch_and_tree('new_tree')
476
427
        new_tree.commit('first', rev_id='new_r1')
477
 
        self.tree.branch.fetch(new_tree.branch, 'new_r1')
 
428
        self.tree.branch.repository.fetch(new_tree.branch.repository,
 
429
                                          revision_id='new_r1')
478
430
        self.assertInHistoryIs(0, 'null:', 'before:revid:new_r1')
479
431
 
480
432
    def test_as_revision_id(self):
485
437
 
486
438
 
487
439
class TestRevisionSpec_tag(TestRevisionSpec):
488
 
 
 
440
    
489
441
    def make_branch_and_tree(self, relpath):
490
442
        # override format as the default one may not support tags
491
443
        return TestRevisionSpec.make_branch_and_tree(
557
509
 
558
510
 
559
511
class TestRevisionSpec_ancestor(TestRevisionSpec):
560
 
 
 
512
    
561
513
    def test_non_exact_branch(self):
562
514
        # It seems better to require an exact path to the branch
563
515
        # Branch.open() rather than using Branch.open_containing()
593
545
        self.assertRaises(errors.NoCommits,
594
546
                          spec_in_history, 'ancestor:new_tree',
595
547
                                           self.tree.branch)
596
 
 
 
548
                        
597
549
        self.assertRaises(errors.NoCommits,
598
550
                          spec_in_history, 'ancestor:tree',
599
551
                                           new_tree.branch)
614
566
 
615
567
 
616
568
class TestRevisionSpec_branch(TestRevisionSpec):
617
 
 
 
569
    
618
570
    def test_non_exact_branch(self):
619
571
        # It seems better to require an exact path to the branch
620
572
        # Branch.open() rather than using Branch.open_containing()
639
591
        # XXX: Right now, we use fetch() to make sure the remote revisions
640
592
        # have been pulled into the local branch. We may change that
641
593
        # behavior in the future.
642
 
        self.assertTrue(self.tree.branch.repository.has_revision('new_r3'))
 
594
        self.failUnless(self.tree.branch.repository.has_revision('new_r3'))
643
595
 
644
596
    def test_no_commits(self):
645
597
        new_tree = self.make_branch_and_tree('new_tree')
675
627
    def test_as_revision_id(self):
676
628
        self.tree.branch.set_submit_branch('tree2')
677
629
        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")