~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-02-01 23:48:08 UTC
  • mfrom: (2225.1.6 revert)
  • Revision ID: pqm@pqm.ubuntu.com-20070201234808-3b1302d73474bd8c
Display changes made by revert

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 by Canonical Ltd
 
1
# Copyright (C) 2005 Canonical Ltd
2
2
#
3
3
# Authors:
4
4
#   Johan Rydberg <jrydberg@gnu.org>
24
24
from StringIO import StringIO
25
25
 
26
26
import bzrlib
27
 
import bzrlib.errors as errors
 
27
from bzrlib import (
 
28
    errors,
 
29
    progress,
 
30
    )
28
31
from bzrlib.errors import (
29
32
                           RevisionNotPresent, 
30
33
                           RevisionAlreadyPresent,
137
140
        except NotImplementedError:
138
141
            pass
139
142
 
 
143
    def test_add_reserved(self):
 
144
        vf = self.get_file()
 
145
        self.assertRaises(errors.ReservedId,
 
146
            vf.add_lines, 'a:', [], ['a\n', 'b\n', 'c\n'])
 
147
 
 
148
        self.assertRaises(errors.ReservedId,
 
149
            vf.add_delta, 'a:', [], None, 'sha1', False, ((0, 0, 0, []),))
 
150
 
 
151
    def test_get_reserved(self):
 
152
        vf = self.get_file()
 
153
        self.assertRaises(errors.ReservedId, vf.get_delta, 'b:')
 
154
        self.assertRaises(errors.ReservedId, vf.get_texts, ['b:'])
 
155
        self.assertRaises(errors.ReservedId, vf.get_lines, 'b:')
 
156
        self.assertRaises(errors.ReservedId, vf.get_text, 'b:')
 
157
 
140
158
    def test_get_delta(self):
141
159
        f = self.get_file()
142
160
        sha1s = self._setup_for_deltas(f)
543
561
        # versions in the weave 
544
562
        # the ordering here is to make a tree so that dumb searches have
545
563
        # more changes to muck up.
 
564
 
 
565
        class InstrumentedProgress(progress.DummyProgress):
 
566
 
 
567
            def __init__(self):
 
568
 
 
569
                progress.DummyProgress.__init__(self)
 
570
                self.updates = []
 
571
 
 
572
            def update(self, msg=None, current=None, total=None):
 
573
                self.updates.append((msg, current, total))
 
574
 
546
575
        vf = self.get_file()
547
576
        # add a base to get included
548
577
        vf.add_lines('base', [], ['base\n'])
556
585
        vf.add_lines('otherchild',
557
586
                     ['lancestor', 'base'],
558
587
                     ['base\n', 'lancestor\n', 'otherchild\n'])
559
 
        def iter_with_versions(versions):
 
588
        def iter_with_versions(versions, expected):
560
589
            # now we need to see what lines are returned, and how often.
561
590
            lines = {'base\n':0,
562
591
                     'lancestor\n':0,
564
593
                     'child\n':0,
565
594
                     'otherchild\n':0,
566
595
                     }
 
596
            progress = InstrumentedProgress()
567
597
            # iterate over the lines
568
 
            for line in vf.iter_lines_added_or_present_in_versions(versions):
 
598
            for line in vf.iter_lines_added_or_present_in_versions(versions, 
 
599
                pb=progress):
569
600
                lines[line] += 1
 
601
            if []!= progress.updates: 
 
602
                self.assertEqual(expected, progress.updates)
570
603
            return lines
571
 
        lines = iter_with_versions(['child', 'otherchild'])
 
604
        lines = iter_with_versions(['child', 'otherchild'],
 
605
                                   [('Walking content.', 0, 2),
 
606
                                    ('Walking content.', 1, 2),
 
607
                                    ('Walking content.', 2, 2)])
572
608
        # we must see child and otherchild
573
609
        self.assertTrue(lines['child\n'] > 0)
574
610
        self.assertTrue(lines['otherchild\n'] > 0)
575
611
        # we dont care if we got more than that.
576
612
        
577
613
        # test all lines
578
 
        lines = iter_with_versions(None)
 
614
        lines = iter_with_versions(None, [('Walking content.', 0, 5),
 
615
                                          ('Walking content.', 1, 5),
 
616
                                          ('Walking content.', 2, 5),
 
617
                                          ('Walking content.', 3, 5),
 
618
                                          ('Walking content.', 4, 5),
 
619
                                          ('Walking content.', 5, 5)])
579
620
        # all lines must be seen at least once
580
621
        self.assertTrue(lines['base\n'] > 0)
581
622
        self.assertTrue(lines['lancestor\n'] > 0)
636
677
            self.assertRaises(NotImplementedError, vf.get_parents_with_ghosts, 'foo')
637
678
            self.assertRaises(NotImplementedError, vf.get_graph_with_ghosts)
638
679
            return
 
680
        vf = self.reopen_file()
639
681
        # test key graph related apis: getncestry, _graph, get_parents
640
682
        # has_version
641
683
        # - these are ghost unaware and must not be reflect ghosts