~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: 2006-09-25 18:42:17 UTC
  • mfrom: (2039.1.2 progress-cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20060925184217-fd144de117df49c3
cleanup 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
            if []!= progress.updates: 
 
587
                self.assertEqual(expected, progress.updates)
570
588
            return lines
571
 
        lines = iter_with_versions(['child', 'otherchild'])
 
589
        lines = iter_with_versions(['child', 'otherchild'], 
 
590
                                   [('Walking content.', 0, 2), 
 
591
                                    ('Walking content.', 0, 2), 
 
592
                                    ('Walking content.', 3, 2), 
 
593
                                    ('Walking content.', 2, 2)])
572
594
        # we must see child and otherchild
573
595
        self.assertTrue(lines['child\n'] > 0)
574
596
        self.assertTrue(lines['otherchild\n'] > 0)
575
597
        # we dont care if we got more than that.
576
598
        
577
599
        # test all lines
578
 
        lines = iter_with_versions(None)
 
600
        lines = iter_with_versions(None, [('Walking content.', 0, 5), 
 
601
                                          ('Walking content.', 0, 5), 
 
602
                                          ('Walking content.', 1, 5), 
 
603
                                          ('Walking content.', 2, 5), 
 
604
                                          ('Walking content.', 2, 5), 
 
605
                                          ('Walking content.', 3, 5), 
 
606
                                          ('Walking content.', 5, 5)])
579
607
        # all lines must be seen at least once
580
608
        self.assertTrue(lines['base\n'] > 0)
581
609
        self.assertTrue(lines['lancestor\n'] > 0)