~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionnamespaces.py

(Aaron Bentley) Document global options

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2004, 2005, 2006 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,
24
22
    errors,
25
 
    repository,
26
23
    )
27
24
from bzrlib.builtins import merge
28
25
from bzrlib.tests import TestCase, TestCaseWithTransport
29
 
from bzrlib.revisionspec import (
30
 
    RevisionSpec,
31
 
    RevisionSpec_revno,
32
 
    RevisionSpec_tag,
33
 
    )
 
26
from bzrlib.revisionspec import RevisionSpec, RevisionSpec_revno
34
27
 
35
28
 
36
29
def spec_in_history(spec, branch):
67
60
    def assertInHistoryIs(self, exp_revno, exp_revision_id, revision_spec):
68
61
        rev_info = self.get_in_history(revision_spec)
69
62
        self.assertEqual(exp_revno, rev_info.revno,
70
 
                         'Revision spec: %r returned wrong revno: %r != %r'
 
63
                         'Revision spec: %s returned wrong revno: %s != %s'
71
64
                         % (revision_spec, exp_revno, rev_info.revno))
72
65
        self.assertEqual(exp_revision_id, rev_info.rev_id,
73
 
                         'Revision spec: %r returned wrong revision id:'
74
 
                         ' %r != %r'
 
66
                         'Revision spec: %s returned wrong revision id:'
 
67
                         ' %s != %s'
75
68
                         % (revision_spec, exp_revision_id, rev_info.rev_id))
76
69
 
77
70
    def assertInvalid(self, revision_spec, extra=''):
277
270
                                          revision_id='alt_r3')
278
271
        self.assertInHistoryIs(None, 'alt_r3', 'revid:alt_r3')
279
272
 
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
 
 
287
273
 
288
274
class TestRevisionSpec_last(TestRevisionSpec):
289
275
 
349
335
 
350
336
class TestRevisionSpec_tag(TestRevisionSpec):
351
337
    
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')
 
338
    def test_invalid(self):
 
339
        self.assertInvalid('tag:foo', extra='\ntag: namespace registered,'
 
340
                                            ' but not implemented')
374
341
 
375
342
 
376
343
class TestRevisionSpec_date(TestRevisionSpec):
484
451
        new_tree = self.make_branch_and_tree('new_tree')
485
452
        self.assertRaises(errors.NoCommits,
486
453
                          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:')