~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionnamespaces.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006 by 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
19
19
import time
20
20
 
21
21
from bzrlib import (
 
22
    branch,
 
23
    bzrdir,
22
24
    errors,
 
25
    repository,
23
26
    )
24
27
from bzrlib.builtins import merge
25
 
from bzrlib.tests import TestCaseWithTransport
26
 
from bzrlib.revisionspec import RevisionSpec
 
28
from bzrlib.tests import TestCase, TestCaseWithTransport
 
29
from bzrlib.revisionspec import (
 
30
    RevisionSpec,
 
31
    RevisionSpec_revno,
 
32
    RevisionSpec_tag,
 
33
    )
27
34
 
28
35
 
29
36
def spec_in_history(spec, branch):
36
43
 
37
44
    def setUp(self):
38
45
        super(TestRevisionSpec, self).setUp()
 
46
        # this sets up a revision graph:
 
47
        # r1: []             1
 
48
        # alt_r2: [r1]       1.1.1
 
49
        # r2: [r1, alt_r2]   2
39
50
 
40
51
        self.tree = self.make_branch_and_tree('tree')
41
52
        self.build_tree(['tree/a'])
56
67
    def assertInHistoryIs(self, exp_revno, exp_revision_id, revision_spec):
57
68
        rev_info = self.get_in_history(revision_spec)
58
69
        self.assertEqual(exp_revno, rev_info.revno,
59
 
                         'Revision spec: %s returned wrong revno: %s != %s'
 
70
                         'Revision spec: %r returned wrong revno: %r != %r'
60
71
                         % (revision_spec, exp_revno, rev_info.revno))
61
72
        self.assertEqual(exp_revision_id, rev_info.rev_id,
62
 
                         'Revision spec: %s returned wrong revision id:'
63
 
                         ' %s != %s'
 
73
                         'Revision spec: %r returned wrong revision id:'
 
74
                         ' %r != %r'
64
75
                         % (revision_spec, exp_revision_id, rev_info.rev_id))
65
76
 
66
77
    def assertInvalid(self, revision_spec, extra=''):
90
101
                          RevisionSpec.from_string, '123a')
91
102
 
92
103
 
 
104
 
 
105
class TestRevnoFromString(TestCase):
 
106
 
 
107
    def test_from_string_dotted_decimal(self):
 
108
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '-1.1')
 
109
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '.1')
 
110
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1..1')
 
111
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1.2..1')
 
112
        self.assertRaises(errors.NoSuchRevisionSpec, RevisionSpec.from_string, '1.')
 
113
        self.assertIsInstance(RevisionSpec.from_string('1.1'), RevisionSpec_revno)
 
114
        self.assertIsInstance(RevisionSpec.from_string('1.1.3'), RevisionSpec_revno)
 
115
 
 
116
 
93
117
class TestRevisionSpec_revno(TestRevisionSpec):
94
118
 
95
119
    def test_positive_int(self):
96
120
        self.assertInHistoryIs(0, None, '0')
97
121
        self.assertInHistoryIs(1, 'r1', '1')
98
122
        self.assertInHistoryIs(2, 'r2', '2')
99
 
 
100
123
        self.assertInvalid('3')
101
124
 
 
125
    def test_dotted_decimal(self):
 
126
        self.assertInHistoryIs(None, 'alt_r2', '1.1.1')
 
127
 
102
128
    def test_negative_int(self):
103
129
        self.assertInHistoryIs(2, 'r2', '-1')
104
130
        self.assertInHistoryIs(1, 'r1', '-2')
251
277
                                          revision_id='alt_r3')
252
278
        self.assertInHistoryIs(None, 'alt_r3', 'revid:alt_r3')
253
279
 
 
280
    def test_unicode(self):
 
281
        """We correctly convert a unicode ui string to an encoded revid."""
 
282
        revision_id = u'\N{SNOWMAN}'.encode('utf-8')
 
283
        self.tree.commit('unicode', rev_id=revision_id)
 
284
        self.assertInHistoryIs(3, revision_id, u'revid:\N{SNOWMAN}')
 
285
        self.assertInHistoryIs(3, revision_id, 'revid:' + revision_id)
 
286
 
254
287
 
255
288
class TestRevisionSpec_last(TestRevisionSpec):
256
289
 
316
349
 
317
350
class TestRevisionSpec_tag(TestRevisionSpec):
318
351
    
319
 
    def test_invalid(self):
320
 
        self.assertInvalid('tag:foo', extra='\ntag: namespace registered,'
321
 
                                            ' but not implemented')
 
352
    def make_branch_and_tree(self, relpath):
 
353
        # override format as the default one may not support tags
 
354
        control = bzrdir.BzrDir.create(relpath)
 
355
        control.create_repository()
 
356
        branch.BzrBranchExperimental.initialize(control)
 
357
        return control.create_workingtree()
 
358
 
 
359
    def test_from_string_tag(self):
 
360
        spec = RevisionSpec.from_string('tag:bzr-0.14')
 
361
        self.assertIsInstance(spec, RevisionSpec_tag)
 
362
        self.assertEqual(spec.spec, 'bzr-0.14')
 
363
 
 
364
    def test_lookup_tag(self):
 
365
        self.tree.branch.tags.set_tag('bzr-0.14', 'r1')
 
366
        self.assertInHistoryIs(1, 'r1', 'tag:bzr-0.14')
 
367
 
 
368
    def test_failed_lookup(self):
 
369
        # tags that don't exist give a specific message: arguably we should
 
370
        # just give InvalidRevisionSpec but I think this is more helpful
 
371
        self.assertRaises(errors.NoSuchTag,
 
372
            self.get_in_history,
 
373
            'tag:some-random-tag')
322
374
 
323
375
 
324
376
class TestRevisionSpec_date(TestRevisionSpec):
432
484
        new_tree = self.make_branch_and_tree('new_tree')
433
485
        self.assertRaises(errors.NoCommits,
434
486
                          self.get_in_history, 'branch:new_tree')
 
487
 
 
488
 
 
489
class TestRevisionSpec_submit(TestRevisionSpec):
 
490
 
 
491
    def test_submit_branch(self):
 
492
        # Common ancestor of trees is 'alt_r2'
 
493
        self.assertRaises(errors.NoSubmitBranch, self.get_in_history,
 
494
                          'submit:')
 
495
        self.tree.branch.set_parent('../tree2')
 
496
        self.assertInHistoryIs(None, 'alt_r2', 'submit:')
 
497
        self.tree.branch.set_parent('bogus')
 
498
        self.assertRaises(errors.NotBranchError, self.get_in_history,
 
499
            'submit:')
 
500
        # submit branch overrides parent branch
 
501
        self.tree.branch.set_submit_branch('tree2')
 
502
        self.assertInHistoryIs(None, 'alt_r2', 'submit:')