changeset 3830:3af779616368

plugins: use importWikiPlugin for tests
author Johannes Berg <johannes AT sipsolutions DOT net>
date Fri, 11 Jul 2008 16:15:25 +0200
parents 8fea1d0ca8ac
children 4a3c996f2d5f
files MoinMoin/util/_tests/test_pysupport.py
diffstat 1 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/util/_tests/test_pysupport.py	Fri Jul 11 16:15:04 2008 +0200
+++ b/MoinMoin/util/_tests/test_pysupport.py	Fri Jul 11 16:15:25 2008 +0200
@@ -11,7 +11,8 @@
 
 import py
 
-from MoinMoin.util import pysupport
+from MoinMoin.util import pysupport, random_string
+from MoinMoin import wikiutil
 
 
 class TestImportNameFromMoin(object):
@@ -47,7 +48,6 @@
         """ Check for valid plugin package """
         self.pluginDirectory = os.path.join(self.request.cfg.data_dir, 'plugin', 'parser')
         self.checkPackage(self.pluginDirectory)
-        self.pluginModule = (self.request.cfg.siteid + '.plugin.parser.' + self.plugin)
 
     def checkPackage(self, path):
         for item in (path, os.path.join(path, '__init__.py')):
@@ -62,16 +62,18 @@
         return os.path.join(self.pluginDirectory, self.plugin + suffix)
 
 
-class TestImportNonExisiting(TestImportNameFromPlugin):
+class TestImportNonExisting(TestImportNameFromPlugin):
 
     plugin = 'NonExistingWikiPlugin'
 
-    def testNonEsisting(self):
+    def testNonExisting(self):
         """ pysupport: import nonexistent wiki plugin fail """
         if self.pluginExists():
             py.test.skip('plugin exists: %s' % self.plugin)
-        py.test.raises(ImportError, pysupport.importName,
-                       self.pluginModule, self.name)
+        py.test.raises(wikiutil.PluginMissingError,
+                       wikiutil.importWikiPlugin,
+                           self.request.cfg, 'parser',
+                           self.plugin, 'Parser')
 
 
 class TestImportExisting(TestImportNameFromPlugin):
@@ -90,8 +92,12 @@
         """
         try:
             self.createTestPlugin()
-            plugin = pysupport.importName(self.pluginModule, self.name)
-            assert getattr(plugin, '__name__', None) == self.name
+            # clear the plugin cache...
+            self.request.cfg._site_plugin_lists = {}
+            parser = wikiutil.importWikiPlugin(self.request.cfg, 'parser',
+                                               self.plugin, 'Parser')
+            assert getattr(parser, '__name__', None) == 'Parser'
+            assert parser.key == self.key
         finally:
             self.deleteTestPlugin()
 
@@ -100,14 +106,15 @@
         if self.pluginExists():
             self.shouldDeleteTestPlugin = False
             py.test.skip("Won't overwrite exiting plugin: %s" % self.plugin)
+        self.key = random_string(32, 'abcdefg')
         data = '''
 # If you find this file in your wiki plugin directory, you can safely
 # delete it.
 import sys, os
 
 class Parser:
-    pass
-'''
+    key = '%s'
+''' % self.key
         try:
             file(self.pluginFilePath('.py'), 'w').write(data)
         except Exception, err: