Mercurial > treepkg
changeset 125:34e08d52956e
Make the import_packager_module function more flexible. The modules may
now also define a RevisionPackager and a BinaryPackager. See the
docstring for details of the new rules. Also add some more tests.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Thu, 22 May 2008 18:12:30 +0000 |
parents | e08b4b09d35f |
children | 68d829cac3ff |
files | test/test_packager.py treepkg/packager.py |
diffstat | 2 files changed, 61 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/test/test_packager.py Thu May 22 12:44:43 2008 +0000 +++ b/test/test_packager.py Thu May 22 18:12:30 2008 +0000 @@ -354,7 +354,15 @@ ("withtrack.py", "\n".join(["class PackageTrack:", " pass", ""])), - ("notrack.py", "\n".join(["class SourcePackager:", + ("srconly.py", "\n".join(["class SourcePackager:", + " pass", + ""])), + ("srcandbin.py", "\n".join(["class SourcePackager:", + " pass", + "class BinaryPackager:", + " pass", + ""])), + ("revonly.py", "\n".join(["class RevisionPackager:", " pass", ""]))])] @@ -367,10 +375,39 @@ def tearDown(self): sys.path = self.old_path + def check_class_modules(self, module, classmodules): + self.assertEquals(classmodules, + [(item[0], + sys.modules[getattr(module, item[0]).__module__]) + for item in classmodules]) + def test_import_with_track(self): module = import_packager_module("treepkg_importtest.withtrack") - self.failUnless(hasattr(module, "PackageTrack")) + self.check_class_modules(module, [("PackageTrack", module)]) - def test_import_without_track(self): - module = import_packager_module("treepkg_importtest.notrack") - self.failUnless(hasattr(module, "PackageTrack")) + def test_import_with_source_packager(self): + module = import_packager_module("treepkg_importtest.srconly") + self.check_class_modules(module, [("PackageTrack", treepkg.packager), + ("SourcePackager", module),]) + + def test_import_with_source_and_binary_packager(self): + module = import_packager_module("treepkg_importtest.srcandbin") + self.check_class_modules(module, [("PackageTrack", treepkg.packager), + ("RevisionPackager", + treepkg.packager), + ("SourcePackager", module), + ("BinaryPackager", module),]) + self.assertEquals(module.PackageTrack.revision_packager_cls, + module.RevisionPackager) + self.assertEquals(module.RevisionPackager.source_packager_cls, + module.SourcePackager) + self.assertEquals(module.RevisionPackager.binary_packager_cls, + module.BinaryPackager) + + def test_import_with_revision_packager(self): + module = import_packager_module("treepkg_importtest.revonly") + self.check_class_modules(module, [("PackageTrack", treepkg.packager), + ("RevisionPackager", module)]) + + self.assertEquals(module.PackageTrack.revision_packager_cls, + module.RevisionPackager)
--- a/treepkg/packager.py Thu May 22 12:44:43 2008 +0000 +++ b/treepkg/packager.py Thu May 22 18:12:30 2008 +0000 @@ -400,17 +400,28 @@ """Import the packager module named by packager_class. The packager_class must be the full absolute module name for the - packager. The module must either contain a class called - 'PackageTrack' or a class called called 'SourcePackager'. If it - doesn't have a 'PackageTrack' class, a 'PackageTrack' class and a - 'RevisionPackager' class will be created the latter of which will - use the module's 'SourcePackager' class as source_packager_cls. + packager. The function tries to find or create a suitable + PackageTrack class from this module using the following rules: + + - If the module contains a class called PackageTrack, use that. + + - Otherwise create one using the module's RevisionPackager class, + creating RevisionPackager if necessary. + + - If RevisionPackager needs to be created, it uses the module's + SourcePackager as source_packager_cls and if present also the + module's BinaryPackager as binary_packager_cls. If the module + does not have a BinaryPackager, the default BinaryPackager is + used. """ module = util.import_dotted_name(packager_class) if not hasattr(module, "PackageTrack"): - module.RevisionPackager \ - = new.classobj("RevisionPackager", (RevisionPackager,), - dict(source_packager_cls=module.SourcePackager)) + if not hasattr(module, "RevisionPackager"): + binary_packager = getattr(module, "BinaryPackager", BinaryPackager) + module.RevisionPackager \ + = new.classobj("RevisionPackager", (RevisionPackager,), + dict(source_packager_cls=module.SourcePackager, + binary_packager_cls=binary_packager)) module.PackageTrack \ = new.classobj("PackageTrack", (PackageTrack,), dict(revision_packager_cls=module.RevisionPackager))