~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: Martin Pool
  • Date: 2009-03-24 05:21:02 UTC
  • mfrom: (4192 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4202.
  • Revision ID: mbp@sourcefrog.net-20090324052102-8kk087b32tep3d9h
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
    bzrdir,
24
24
    errors,
25
25
    repository,
 
26
    revision as _mod_revision,
26
27
    )
27
28
from bzrlib.tests import TestCase, TestCaseWithTransport
28
29
from bzrlib.revisionspec import (
73
74
                         ' %r != %r'
74
75
                         % (revision_spec, exp_revision_id, rev_info.rev_id))
75
76
 
76
 
    def assertInvalid(self, revision_spec, extra=''):
 
77
    def assertInvalid(self, revision_spec, extra='',
 
78
                      invalid_as_revision_id=True):
77
79
        try:
78
80
            self.get_in_history(revision_spec)
79
81
        except errors.InvalidRevisionSpec, e:
80
82
            self.assertEqual(revision_spec, e.spec)
81
83
            self.assertEqual(extra, e.extra)
82
84
        else:
83
 
            self.fail('Expected InvalidRevisionSpec to be raised for %s'
84
 
                      % (revision_spec,))
 
85
            self.fail('Expected InvalidRevisionSpec to be raised for'
 
86
                      ' %r.in_history' % (revision_spec,))
 
87
        if invalid_as_revision_id:
 
88
            try:
 
89
                spec = RevisionSpec.from_string(revision_spec)
 
90
                spec.as_revision_id(self.tree.branch)
 
91
            except errors.InvalidRevisionSpec, e:
 
92
                self.assertEqual(revision_spec, e.spec)
 
93
                self.assertEqual(extra, e.extra)
 
94
            else:
 
95
                self.fail('Expected InvalidRevisionSpec to be raised for'
 
96
                          ' %r.as_revision_id' % (revision_spec,))
85
97
 
86
98
    def assertAsRevisionId(self, revision_id, revision_spec):
87
99
        """Calling as_revision_id() should return the specified id."""
89
101
        self.assertEqual(revision_id,
90
102
                         spec.as_revision_id(self.tree.branch))
91
103
 
 
104
    def get_as_tree(self, revision_spec, tree=None):
 
105
        if tree is None:
 
106
            tree = self.tree
 
107
        spec = RevisionSpec.from_string(revision_spec)
 
108
        return spec.as_tree(tree.branch)
 
109
 
92
110
 
93
111
class RevisionSpecMatchOnTrap(RevisionSpec):
94
112
 
158
176
 
159
177
    def test_dotted_decimal(self):
160
178
        self.assertInHistoryIs(None, 'alt_r2', '1.1.1')
 
179
        self.assertInvalid('1.1.123')
161
180
 
162
181
    def test_negative_int(self):
163
182
        self.assertInHistoryIs(2, 'r2', '-1')
257
276
        """Old revno:N:path tests"""
258
277
        wta = self.make_branch_and_tree('a')
259
278
        ba = wta.branch
260
 
        
 
279
 
261
280
        wta.commit('Commit one', rev_id='a@r-0-1')
262
281
        wta.commit('Commit two', rev_id='a@r-0-2')
263
282
        wta.commit('Commit three', rev_id='a@r-0-3')
289
308
        self.assertAsRevisionId('r2', '-1')
290
309
        self.assertAsRevisionId('alt_r2', '1.1.1')
291
310
 
 
311
    def test_as_tree(self):
 
312
        tree = self.get_as_tree('0')
 
313
        self.assertEquals(_mod_revision.NULL_REVISION, tree.get_revision_id())
 
314
        tree = self.get_as_tree('1')
 
315
        self.assertEquals('r1', tree.get_revision_id())
 
316
        tree = self.get_as_tree('2')
 
317
        self.assertEquals('r2', tree.get_revision_id())
 
318
        tree = self.get_as_tree('-2')
 
319
        self.assertEquals('r1', tree.get_revision_id())
 
320
        tree = self.get_as_tree('-1')
 
321
        self.assertEquals('r2', tree.get_revision_id())
 
322
        tree = self.get_as_tree('1.1.1')
 
323
        self.assertEquals('alt_r2', tree.get_revision_id())
 
324
 
292
325
 
293
326
class TestRevisionSpec_revid(TestRevisionSpec):
294
 
    
 
327
 
295
328
    def test_in_history(self):
296
329
        # We should be able to access revisions that are directly
297
330
        # in the history.
298
331
        self.assertInHistoryIs(1, 'r1', 'revid:r1')
299
332
        self.assertInHistoryIs(2, 'r2', 'revid:r2')
300
 
        
 
333
 
301
334
    def test_missing(self):
302
 
        self.assertInvalid('revid:r3')
 
335
        self.assertInvalid('revid:r3', invalid_as_revision_id=False)
303
336
 
304
337
    def test_merged(self):
305
338
        """We can reach revisions in the ancestry"""
308
341
    def test_not_here(self):
309
342
        self.tree2.commit('alt third', rev_id='alt_r3')
310
343
        # It exists in tree2, but not in tree
311
 
        self.assertInvalid('revid:alt_r3')
 
344
        self.assertInvalid('revid:alt_r3', invalid_as_revision_id=False)
312
345
 
313
346
    def test_in_repository(self):
314
347
        """We can get any revision id in the repository"""
404
437
 
405
438
 
406
439
class TestRevisionSpec_tag(TestRevisionSpec):
407
 
    
 
440
 
408
441
    def make_branch_and_tree(self, relpath):
409
442
        # override format as the default one may not support tags
410
443
        return TestRevisionSpec.make_branch_and_tree(
476
509
 
477
510
 
478
511
class TestRevisionSpec_ancestor(TestRevisionSpec):
479
 
    
 
512
 
480
513
    def test_non_exact_branch(self):
481
514
        # It seems better to require an exact path to the branch
482
515
        # Branch.open() rather than using Branch.open_containing()
512
545
        self.assertRaises(errors.NoCommits,
513
546
                          spec_in_history, 'ancestor:new_tree',
514
547
                                           self.tree.branch)
515
 
                        
 
548
 
516
549
        self.assertRaises(errors.NoCommits,
517
550
                          spec_in_history, 'ancestor:tree',
518
551
                                           new_tree.branch)
520
553
    def test_as_revision_id(self):
521
554
        self.assertAsRevisionId('alt_r2', 'ancestor:tree2')
522
555
 
 
556
    def test_default(self):
 
557
        # We don't have a parent to default to
 
558
        self.assertRaises(errors.NotBranchError, self.get_in_history,
 
559
                          'ancestor:')
 
560
 
 
561
        # Create a branch with a parent to default to
 
562
        tree3 = self.tree.bzrdir.sprout('tree3').open_workingtree()
 
563
        tree3.commit('foo', rev_id='r3')
 
564
        self.tree = tree3
 
565
        self.assertInHistoryIs(2, 'r2', 'ancestor:')
 
566
 
523
567
 
524
568
class TestRevisionSpec_branch(TestRevisionSpec):
525
 
    
 
569
 
526
570
    def test_non_exact_branch(self):
527
571
        # It seems better to require an exact path to the branch
528
572
        # Branch.open() rather than using Branch.open_containing()
553
597
        new_tree = self.make_branch_and_tree('new_tree')
554
598
        self.assertRaises(errors.NoCommits,
555
599
                          self.get_in_history, 'branch:new_tree')
 
600
        self.assertRaises(errors.NoCommits,
 
601
                          self.get_as_tree, 'branch:new_tree')
556
602
 
557
603
    def test_as_revision_id(self):
558
604
        self.assertAsRevisionId('alt_r2', 'branch:tree2')
559
605
 
 
606
    def test_as_tree(self):
 
607
        tree = self.get_as_tree('branch:tree', self.tree2)
 
608
        self.assertEquals('r2', tree.get_revision_id())
 
609
        self.assertFalse(self.tree2.branch.repository.has_revision('r2'))
 
610
 
560
611
 
561
612
class TestRevisionSpec_submit(TestRevisionSpec):
562
613