[Treepkg-commits] r50 - in trunk: test treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu May 22 20:12:31 CEST 2008


Author: bh
Date: 2008-05-22 20:12:30 +0200 (Thu, 22 May 2008)
New Revision: 50

Modified:
   trunk/test/test_packager.py
   trunk/treepkg/packager.py
Log:
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.


Modified: trunk/test/test_packager.py
===================================================================
--- trunk/test/test_packager.py	2008-05-22 12:44:43 UTC (rev 49)
+++ trunk/test/test_packager.py	2008-05-22 18:12:30 UTC (rev 50)
@@ -354,8 +354,16 @@
                ("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",
                                          ""]))])]
 
     def setUp(self):
@@ -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)

Modified: trunk/treepkg/packager.py
===================================================================
--- trunk/treepkg/packager.py	2008-05-22 12:44:43 UTC (rev 49)
+++ trunk/treepkg/packager.py	2008-05-22 18:12:30 UTC (rev 50)
@@ -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))



More information about the Treepkg-commits mailing list