~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-07-02 07:06:39 UTC
  • mfrom: (2553.2.14 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20070702070639-um9oyfoc2i6g8umv
(robertc) Reduce duplication in interface based testing by extracting a new class TestScenarioApplier.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
from bzrlib.lazy_import import lazy_import
23
23
lazy_import(globals(), """
24
 
from copy import deepcopy
25
 
import unittest
26
24
 
27
25
from bzrlib import (
28
26
    errors,
684
682
                    else:
685
683
                        new_version_ids.add(version)
686
684
                return new_version_ids
687
 
 
688
 
 
689
 
class InterVersionedFileTestProviderAdapter(object):
690
 
    """A tool to generate a suite testing multiple inter versioned-file classes.
691
 
 
692
 
    This is done by copying the test once for each InterVersionedFile provider
693
 
    and injecting the transport_server, transport_readonly_server,
694
 
    versionedfile_factory and versionedfile_factory_to classes into each copy.
695
 
    Each copy is also given a new id() to make it easy to identify.
696
 
    """
697
 
 
698
 
    def __init__(self, transport_server, transport_readonly_server, formats):
699
 
        self._transport_server = transport_server
700
 
        self._transport_readonly_server = transport_readonly_server
701
 
        self._formats = formats
702
 
    
703
 
    def adapt(self, test):
704
 
        result = unittest.TestSuite()
705
 
        for (interversionedfile_class,
706
 
             versionedfile_factory,
707
 
             versionedfile_factory_to) in self._formats:
708
 
            new_test = deepcopy(test)
709
 
            new_test.transport_server = self._transport_server
710
 
            new_test.transport_readonly_server = self._transport_readonly_server
711
 
            new_test.interversionedfile_class = interversionedfile_class
712
 
            new_test.versionedfile_factory = versionedfile_factory
713
 
            new_test.versionedfile_factory_to = versionedfile_factory_to
714
 
            def make_new_test_id():
715
 
                new_id = "%s(%s)" % (new_test.id(), interversionedfile_class.__name__)
716
 
                return lambda: new_id
717
 
            new_test.id = make_new_test_id()
718
 
            result.addTest(new_test)
719
 
        return result
720
 
 
721
 
    @staticmethod
722
 
    def default_test_list():
723
 
        """Generate the default list of interversionedfile permutations to test."""
724
 
        from bzrlib.weave import WeaveFile
725
 
        from bzrlib.knit import KnitVersionedFile
726
 
        result = []
727
 
        # test the fallback InterVersionedFile from annotated knits to weave
728
 
        result.append((InterVersionedFile, 
729
 
                       KnitVersionedFile,
730
 
                       WeaveFile))
731
 
        for optimiser in InterVersionedFile._optimisers:
732
 
            result.append((optimiser,
733
 
                           optimiser._matching_file_from_factory,
734
 
                           optimiser._matching_file_to_factory
735
 
                           ))
736
 
        # if there are specific combinations we want to use, we can add them 
737
 
        # here.
738
 
        return result