diff test/test_packager.py @ 113:312949e7628d

Add a smarter way to load the packager modules: Add the function treepkg.packager.import_packager_module and use it to load the packager modules. Also add corresponding tests.
author Bernhard Herzog <bh@intevation.de>
date Tue, 01 Apr 2008 12:30:39 +0000
parents f7b9c7113c46
children 093514306186
line wrap: on
line diff
--- a/test/test_packager.py	Thu Mar 20 20:21:34 2008 +0000
+++ b/test/test_packager.py	Tue Apr 01 12:30:39 2008 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 by Intevation GmbH
+# Copyright (C) 2007, 2008 by Intevation GmbH
 # Authors:
 # Bernhard Herzog <bh@intevation.de>
 #
@@ -14,7 +14,7 @@
 from treepkg.run import call
 from treepkg.cmdexpand import cmdexpand
 from treepkg.util import writefile
-from treepkg.packager import PackagerGroup
+from treepkg.packager import PackagerGroup, import_packager_module
 import treepkg.subversion as subversion
 import treepkg
 
@@ -344,3 +344,32 @@
                           [os.path.join(srcdir, filename)
                            for filename in ["test_1.0-1_i386.changes",
                                             "test_1.0-1_i386.deb"]])
+
+
+class TestImportPackagerModule(unittest.TestCase, FileTestMixin):
+
+    files = [("treepkg_importtest",
+              [("__init__.py", ""),
+               ("withtrack.py", "\n".join(["class PackageTrack:",
+                                           "    pass",
+                                           ""])),
+               ("notrack.py", "\n".join(["class SourcePackager:",
+                                         "    pass",
+                                         ""]))])]
+
+    def setUp(self):
+        self.directory = self.create_temp_dir(self.id())
+        self.create_files(self.directory, self.files)
+        self.old_path = sys.path
+        sys.path = [self.directory] + sys.path
+
+    def tearDown(self):
+        sys.path = self.old_path
+
+    def test_import_with_track(self):
+        module = import_packager_module("treepkg_importtest.withtrack")
+        self.failUnless(hasattr(module, "PackageTrack"))
+
+    def test_import_without_track(self):
+        module = import_packager_module("treepkg_importtest.notrack")
+        self.failUnless(hasattr(module, "PackageTrack"))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)