/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_revisionspec.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-08 21:56:12 UTC
  • mto: This revision was merged to the branch mainline in revision 3773.
  • Revision ID: john@arbash-meinel.com-20081008215612-y9v94tqxreqoangx
Simplify the --raw mode.

I didn't realize, but the only node that is special cased is the 'root' node,
and to read it, you actually have to parse it directly, because the
compressed bytes start immediately after the end of the header, rather than
having any padding before the zlib bytes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 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
18
import os
146
146
    def test_object(self):
147
147
        self.assertRaises(TypeError, RevisionSpec.from_string, object())
148
148
 
149
 
 
150
 
class TestRevisionSpec_dwim(TestRevisionSpec):
151
 
 
152
 
    # Don't need to test revno's explicitly since TRS_revno already
153
 
    # covers that well for us
154
 
    def test_dwim_spec_revno(self):
155
 
        self.assertInHistoryIs(2, 'r2', '2')
156
 
        self.assertAsRevisionId('alt_r2', '1.1.1')
157
 
 
158
 
    def test_dwim_spec_revid(self):
159
 
        self.assertInHistoryIs(2, 'r2', 'r2')
160
 
 
161
 
    def test_dwim_spec_tag(self):
162
 
        self.tree.branch.tags.set_tag('footag', 'r1')
163
 
        self.assertAsRevisionId('r1', 'footag')
164
 
        self.tree.branch.tags.delete_tag('footag')
165
 
        self.assertRaises(errors.InvalidRevisionSpec,
166
 
                          self.get_in_history, 'footag')
167
 
 
168
 
    def test_dwim_spec_tag_that_looks_like_revno(self):
169
 
        # Test that we slip past revno with things that look like revnos,
170
 
        # but aren't.  Tags are convenient for testing this since we can
171
 
        # make them look however we want.
172
 
        self.tree.branch.tags.set_tag('3', 'r2')
173
 
        self.assertAsRevisionId('r2', '3')
174
 
        self.build_tree(['tree/b'])
175
 
        self.tree.add(['b'])
176
 
        self.tree.commit('b', rev_id='r3')
177
 
        self.assertAsRevisionId('r3', '3')
178
 
 
179
 
    def test_dwim_spec_date(self):
180
 
        self.assertAsRevisionId('r1', 'today')
181
 
 
182
 
    def test_dwim_spec_branch(self):
183
 
        self.assertInHistoryIs(None, 'alt_r2', 'tree2')
184
 
 
185
 
    def test_dwim_spec_nonexistent(self):
186
 
        self.assertInvalid('somethingrandom', invalid_as_revision_id=False)
187
 
        self.assertInvalid('-1.1', invalid_as_revision_id=False)
188
 
        self.assertInvalid('.1', invalid_as_revision_id=False)
189
 
        self.assertInvalid('1..1', invalid_as_revision_id=False)
190
 
        self.assertInvalid('1.2..1', invalid_as_revision_id=False)
191
 
        self.assertInvalid('1.', invalid_as_revision_id=False)
 
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)
192
167
 
193
168
 
194
169
class TestRevisionSpec_revno(TestRevisionSpec):
201
176
 
202
177
    def test_dotted_decimal(self):
203
178
        self.assertInHistoryIs(None, 'alt_r2', '1.1.1')
204
 
        self.assertInvalid('1.1.123')
205
179
 
206
180
    def test_negative_int(self):
207
181
        self.assertInHistoryIs(2, 'r2', '-1')
301
275
        """Old revno:N:path tests"""
302
276
        wta = self.make_branch_and_tree('a')
303
277
        ba = wta.branch
304
 
 
 
278
        
305
279
        wta.commit('Commit one', rev_id='a@r-0-1')
306
280
        wta.commit('Commit two', rev_id='a@r-0-2')
307
281
        wta.commit('Commit three', rev_id='a@r-0-3')
349
323
 
350
324
 
351
325
class TestRevisionSpec_revid(TestRevisionSpec):
352
 
 
 
326
    
353
327
    def test_in_history(self):
354
328
        # We should be able to access revisions that are directly
355
329
        # in the history.
356
330
        self.assertInHistoryIs(1, 'r1', 'revid:r1')
357
331
        self.assertInHistoryIs(2, 'r2', 'revid:r2')
358
 
 
 
332
        
359
333
    def test_missing(self):
360
334
        self.assertInvalid('revid:r3', invalid_as_revision_id=False)
361
335
 
462
436
 
463
437
 
464
438
class TestRevisionSpec_tag(TestRevisionSpec):
465
 
 
 
439
    
466
440
    def make_branch_and_tree(self, relpath):
467
441
        # override format as the default one may not support tags
468
442
        return TestRevisionSpec.make_branch_and_tree(
534
508
 
535
509
 
536
510
class TestRevisionSpec_ancestor(TestRevisionSpec):
537
 
 
 
511
    
538
512
    def test_non_exact_branch(self):
539
513
        # It seems better to require an exact path to the branch
540
514
        # Branch.open() rather than using Branch.open_containing()
570
544
        self.assertRaises(errors.NoCommits,
571
545
                          spec_in_history, 'ancestor:new_tree',
572
546
                                           self.tree.branch)
573
 
 
 
547
                        
574
548
        self.assertRaises(errors.NoCommits,
575
549
                          spec_in_history, 'ancestor:tree',
576
550
                                           new_tree.branch)
578
552
    def test_as_revision_id(self):
579
553
        self.assertAsRevisionId('alt_r2', 'ancestor:tree2')
580
554
 
581
 
    def test_default(self):
582
 
        # We don't have a parent to default to
583
 
        self.assertRaises(errors.NotBranchError, self.get_in_history,
584
 
                          'ancestor:')
585
 
 
586
 
        # Create a branch with a parent to default to
587
 
        tree3 = self.tree.bzrdir.sprout('tree3').open_workingtree()
588
 
        tree3.commit('foo', rev_id='r3')
589
 
        self.tree = tree3
590
 
        self.assertInHistoryIs(2, 'r2', 'ancestor:')
591
 
 
592
555
 
593
556
class TestRevisionSpec_branch(TestRevisionSpec):
594
 
 
 
557
    
595
558
    def test_non_exact_branch(self):
596
559
        # It seems better to require an exact path to the branch
597
560
        # Branch.open() rather than using Branch.open_containing()