~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_versionedfile.py

  • Committer: wang
  • Date: 2006-10-29 13:41:32 UTC
  • mto: (2104.4.1 wang_65714)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: wang@ubuntu-20061029134132-3d7f4216f20c4aef
Replace python's difflib by patiencediff because the worst case 
performance is cubic for difflib and people commiting large data 
files are often hurt by this. The worst case performance of patience is 
quadratic. Fix bug 65714.

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,
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)