~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionnamespaces.py

  • Committer: Alexander Belchenko
  • Date: 2007-01-04 23:36:44 UTC
  • mfrom: (2224 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2225.
  • Revision ID: bialix@ukr.net-20070104233644-7znkxoj9b0y7ev28
merge bzr.dev

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
    )
 
24
from bzrlib.builtins import merge
27
25
from bzrlib.tests import TestCase, TestCaseWithTransport
28
 
from bzrlib.revisionspec import (
29
 
    RevisionSpec,
30
 
    RevisionSpec_revno,
31
 
    RevisionSpec_tag,
32
 
    )
 
26
from bzrlib.revisionspec import RevisionSpec, RevisionSpec_revno
33
27
 
34
28
 
35
29
def spec_in_history(spec, branch):
66
60
    def assertInHistoryIs(self, exp_revno, exp_revision_id, revision_spec):
67
61
        rev_info = self.get_in_history(revision_spec)
68
62
        self.assertEqual(exp_revno, rev_info.revno,
69
 
                         'Revision spec: %r returned wrong revno: %r != %r'
 
63
                         'Revision spec: %s returned wrong revno: %s != %s'
70
64
                         % (revision_spec, exp_revno, rev_info.revno))
71
65
        self.assertEqual(exp_revision_id, rev_info.rev_id,
72
 
                         'Revision spec: %r returned wrong revision id:'
73
 
                         ' %r != %r'
 
66
                         'Revision spec: %s returned wrong revision id:'
 
67
                         ' %s != %s'
74
68
                         % (revision_spec, exp_revision_id, rev_info.rev_id))
75
69
 
76
70
    def assertInvalid(self, revision_spec, extra=''):
276
270
                                          revision_id='alt_r3')
277
271
        self.assertInHistoryIs(None, 'alt_r3', 'revid:alt_r3')
278
272
 
279
 
    def test_unicode(self):
280
 
        """We correctly convert a unicode ui string to an encoded revid."""
281
 
        revision_id = u'\N{SNOWMAN}'.encode('utf-8')
282
 
        self.tree.commit('unicode', rev_id=revision_id)
283
 
        self.assertInHistoryIs(3, revision_id, u'revid:\N{SNOWMAN}')
284
 
        self.assertInHistoryIs(3, revision_id, 'revid:' + revision_id)
285
 
 
286
273
 
287
274
class TestRevisionSpec_last(TestRevisionSpec):
288
275
 
348
335
 
349
336
class TestRevisionSpec_tag(TestRevisionSpec):
350
337
    
351
 
    def make_branch_and_tree(self, relpath):
352
 
        # override format as the default one may not support tags
353
 
        control = bzrdir.BzrDir.create(relpath)
354
 
        control.create_repository()
355
 
        branch.BzrBranchExperimental.initialize(control)
356
 
        return control.create_workingtree()
357
 
 
358
 
    def test_from_string_tag(self):
359
 
        spec = RevisionSpec.from_string('tag:bzr-0.14')
360
 
        self.assertIsInstance(spec, RevisionSpec_tag)
361
 
        self.assertEqual(spec.spec, 'bzr-0.14')
362
 
 
363
 
    def test_lookup_tag(self):
364
 
        self.tree.branch.tags.set_tag('bzr-0.14', 'r1')
365
 
        self.assertInHistoryIs(1, 'r1', 'tag:bzr-0.14')
366
 
 
367
 
    def test_failed_lookup(self):
368
 
        # tags that don't exist give a specific message: arguably we should
369
 
        # just give InvalidRevisionSpec but I think this is more helpful
370
 
        self.assertRaises(errors.NoSuchTag,
371
 
            self.get_in_history,
372
 
            'tag:some-random-tag')
 
338
    def test_invalid(self):
 
339
        self.assertInvalid('tag:foo', extra='\ntag: namespace registered,'
 
340
                                            ' but not implemented')
373
341
 
374
342
 
375
343
class TestRevisionSpec_date(TestRevisionSpec):
483
451
        new_tree = self.make_branch_and_tree('new_tree')
484
452
        self.assertRaises(errors.NoCommits,
485
453
                          self.get_in_history, 'branch:new_tree')
486
 
 
487
 
 
488
 
class TestRevisionSpec_submit(TestRevisionSpec):
489
 
 
490
 
    def test_submit_branch(self):
491
 
        # Common ancestor of trees is 'alt_r2'
492
 
        self.assertRaises(errors.NoSubmitBranch, self.get_in_history,
493
 
                          'submit:')
494
 
        self.tree.branch.set_parent('../tree2')
495
 
        self.assertInHistoryIs(None, 'alt_r2', 'submit:')
496
 
        self.tree.branch.set_parent('bogus')
497
 
        self.assertRaises(errors.NotBranchError, self.get_in_history,
498
 
            'submit:')
499
 
        # submit branch overrides parent branch
500
 
        self.tree.branch.set_submit_branch('tree2')
501
 
        self.assertInHistoryIs(None, 'alt_r2', 'submit:')