~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: Aaron Bentley
  • Date: 2006-09-25 14:52:38 UTC
  • mto: This revision was merged to the branch mainline in revision 2040.
  • Revision ID: abentley@panoramicfeedback.com-20060925145238-385b618dccf07763
Clean up progress properly when interrupted during fetch (#54000)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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,
543
546
        # versions in the weave 
544
547
        # the ordering here is to make a tree so that dumb searches have
545
548
        # more changes to muck up.
 
549
 
 
550
        class InstrumentedProgress(progress.DummyProgress):
 
551
 
 
552
            def __init__(self):
 
553
 
 
554
                progress.DummyProgress.__init__(self)
 
555
                self.updates = []
 
556
 
 
557
            def update(self, msg=None, current=None, total=None):
 
558
                self.updates.append((msg, current, total))
 
559
 
546
560
        vf = self.get_file()
547
561
        # add a base to get included
548
562
        vf.add_lines('base', [], ['base\n'])
556
570
        vf.add_lines('otherchild',
557
571
                     ['lancestor', 'base'],
558
572
                     ['base\n', 'lancestor\n', 'otherchild\n'])
559
 
        def iter_with_versions(versions):
 
573
        def iter_with_versions(versions, expected):
560
574
            # now we need to see what lines are returned, and how often.
561
575
            lines = {'base\n':0,
562
576
                     'lancestor\n':0,
564
578
                     'child\n':0,
565
579
                     'otherchild\n':0,
566
580
                     }
 
581
            progress = InstrumentedProgress()
567
582
            # iterate over the lines
568
 
            for line in vf.iter_lines_added_or_present_in_versions(versions):
 
583
            for line in vf.iter_lines_added_or_present_in_versions(versions, 
 
584
                pb=progress):
569
585
                lines[line] += 1
 
586
            try:
 
587
                self.assertEqual([], progress.updates)
 
588
            except AssertionError:
 
589
                self.assertEqual(expected,
 
590
                                 progress.updates)
570
591
            return lines
571
 
        lines = iter_with_versions(['child', 'otherchild'])
 
592
        lines = iter_with_versions(['child', 'otherchild'], 
 
593
                                   [('Walking content.', 0, 2), 
 
594
                                    ('Walking content.', 0, 2), 
 
595
                                    ('Walking content.', 3, 2), 
 
596
                                    ('Walking content.', 2, 2)])
572
597
        # we must see child and otherchild
573
598
        self.assertTrue(lines['child\n'] > 0)
574
599
        self.assertTrue(lines['otherchild\n'] > 0)
575
600
        # we dont care if we got more than that.
576
601
        
577
602
        # test all lines
578
 
        lines = iter_with_versions(None)
 
603
        lines = iter_with_versions(None, [('Walking content.', 0, 5), 
 
604
                                          ('Walking content.', 0, 5), 
 
605
                                          ('Walking content.', 1, 5), 
 
606
                                          ('Walking content.', 2, 5), 
 
607
                                          ('Walking content.', 2, 5), 
 
608
                                          ('Walking content.', 3, 5), 
 
609
                                          ('Walking content.', 5, 5)])
579
610
        # all lines must be seen at least once
580
611
        self.assertTrue(lines['base\n'] > 0)
581
612
        self.assertTrue(lines['lancestor\n'] > 0)