[conduit: 107/138] Remove the duplicated 'plugin' loader code
- From: John Carr <johncarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [conduit: 107/138] Remove the duplicated 'plugin' loader code
- Date: Thu, 21 May 2009 03:35:54 -0400 (EDT)
commit 4a5cc3b081f456f35b38456a7acd47ac41942977
Author: John Carr <john carr unrouted co uk>
Date: Wed May 6 02:36:44 2009 -0700
Remove the duplicated 'plugin' loader code
---
test/soup/__init__.py | 5 +++--
test/soup/data/__init__.py | 29 ++++++++---------------------
test/soup/env/__init__.py | 28 +++++++---------------------
test/soup/modules/__init__.py | 28 +++++++---------------------
test/soup/result.py | 2 +-
test/soup/test_dataprovider.py | 2 +-
test/soup/test_datatypes.py | 2 +-
test/soup/test_synchronization.py | 2 +-
8 files changed, 29 insertions(+), 69 deletions(-)
diff --git a/test/soup/__init__.py b/test/soup/__init__.py
index 9e3bab4..8a5640d 100644
--- a/test/soup/__init__.py
+++ b/test/soup/__init__.py
@@ -14,9 +14,9 @@ def get_root():
sys.path.insert(0, get_root())
-import modules
-import data
import env
+import data
+import modules
import conduit
import conduit.utils as Utils
@@ -41,6 +41,7 @@ CHANGE_ADD = 1
CHANGE_REPLACE = 2
CHANGE_DELETE = 3
+
def get_module(name):
""" This is just to avoid importing sys everywhere and i want my tests to be pretty! """
return sys.modules[name]
diff --git a/test/soup/data/__init__.py b/test/soup/data/__init__.py
index d75fab7..8784c61 100644
--- a/test/soup/data/__init__.py
+++ b/test/soup/data/__init__.py
@@ -2,6 +2,8 @@ import os, sys, glob
from conduit.datatypes import DataType, File
+from soup.utils.pluginloader import PluginLoader
+
class DataWrapper(object):
"""
This class provides a wrapper around some test data.
@@ -69,25 +71,10 @@ class DataWrapper(object):
compatible = list(cls.get_compatible_datatypes())
return datatype in compatible
-def load_modules():
- basepath = os.path.dirname(__file__)
- for root, dirs, files in os.walk(basepath):
- for dir in dirs:
- if dir[:1] != ".":
- load_module(dir)
- for file in files:
- if file.endswith(".py") and not file.startswith("__"):
- load_module(file[:-3])
- break
-
-def load_module(module):
- if sys.modules.has_key(module):
- reload(sys.modules[module])
- else:
- __import__("soup.data", {}, {}, [module])
-
-def get_all():
- if len(DataWrapper.__subclasses__()) == 0:
- load_modules()
- return DataWrapper.__subclasses__()
+class _DataLoader(PluginLoader):
+ _subclass_ = DataWrapper
+ _module_ = "soup.data"
+ _path_ = os.path.dirname(__file__)
+
+DataLoader = _DataLoader()
diff --git a/test/soup/env/__init__.py b/test/soup/env/__init__.py
index d7f7c34..f68e161 100644
--- a/test/soup/env/__init__.py
+++ b/test/soup/env/__init__.py
@@ -1,6 +1,8 @@
import os, sys
+from soup.utils.pluginloader import PluginLoader
+
class EnvironmentWrapper(object):
@classmethod
@@ -20,25 +22,9 @@ class EnvironmentWrapper(object):
pass
-def load_modules():
- basepath = os.path.dirname(__file__)
- for root, dirs, files in os.walk(basepath):
- for dir in dirs:
- if dir[:1] != ".":
- load_module(dir)
- for file in files:
- if file.endswith(".py") and not file.startswith("__"):
- load_module(file[:-3])
- break
-
-def load_module(module):
- if sys.modules.has_key(module):
- reload(sys.modules[module])
- else:
- __import__("soup.env", {}, {}, [module])
-
-def get_all():
- if len(EnvironmentWrapper.__subclasses__()) == 0:
- load_modules()
- return EnvironmentWrapper.__subclasses__()
+class _EnvironmentLoader(PluginLoader):
+ _subclass_ = EnvironmentWrapper
+ _module_ = "soup.env"
+ _path_ = os.path.dirname(__file__)
+EnvironmentLoader = _EnvironmentLoader()
diff --git a/test/soup/modules/__init__.py b/test/soup/modules/__init__.py
index 8d1a153..0a86020 100644
--- a/test/soup/modules/__init__.py
+++ b/test/soup/modules/__init__.py
@@ -1,5 +1,6 @@
import os, sys
+from soup.utils.pluginloader import PluginLoader
class ModuleWrapper(object):
@@ -56,25 +57,10 @@ class ModuleWrapper(object):
def get_wrapped(self):
return self.conduit.wrap_dataprovider(self.dp)
-def load_modules():
- basepath = os.path.dirname(__file__)
- for root, dirs, files in os.walk(basepath):
- for dir in dirs:
- if dir[:1] != ".":
- load_module(dir)
- for file in files:
- if file.endswith(".py") and not file.startswith("__"):
- load_module(file[:-3])
- break
-
-def load_module(module):
- if sys.modules.has_key(module):
- reload(sys.modules[module])
- else:
- __import__("soup.modules", {}, {}, [module])
-
-def get_all():
- if len(ModuleWrapper.__subclasses__()) == 0:
- load_modules()
- return ModuleWrapper.__subclasses__()
+class _ModuleLoader(PluginLoader):
+ _subclass_ = ModuleWrapper
+ _module_ = "soup.modules"
+ _path_ = os.path.dirname(__file__)
+
+ModuleLoader = _ModuleLoader()
diff --git a/test/soup/result.py b/test/soup/result.py
index da2ea55..0766aae 100644
--- a/test/soup/result.py
+++ b/test/soup/result.py
@@ -148,7 +148,7 @@ class TestRunner(object):
# Discover all enabled EnvironmentWrapper objects
self.env = []
- for e in soup.env.get_all():
+ for e in soup.env.EnvironmentLoader.get_all():
if e.enabled(opts):
self.env.append(e())
diff --git a/test/soup/test_dataprovider.py b/test/soup/test_dataprovider.py
index cf558d1..f1f6f4e 100644
--- a/test/soup/test_dataprovider.py
+++ b/test/soup/test_dataprovider.py
@@ -71,7 +71,7 @@ def make_testcase(wrp):
# Generate TestCase objects for each dataprovider wrapper
self = soup.get_module(__name__)
-for wrapper in soup.modules.get_all():
+for wrapper in soup.modules.ModuleLoader.get_all():
testklass = make_testcase(wrapper)
setattr(self, testklass.name(), testklass)
diff --git a/test/soup/test_datatypes.py b/test/soup/test_datatypes.py
index 467bbd7..c686b52 100644
--- a/test/soup/test_datatypes.py
+++ b/test/soup/test_datatypes.py
@@ -50,7 +50,7 @@ def make_testcase(wrp):
# Generate TestCase objects for each datatype wrapper
self = soup.get_module(__name__)
-for wrapper in soup.data.get_all():
+for wrapper in soup.data.DataLoader.get_all():
testklass = make_testcase(wrapper)
setattr(self, testklass.name(), testklass)
diff --git a/test/soup/test_synchronization.py b/test/soup/test_synchronization.py
index 89c17a9..1bff6a7 100644
--- a/test/soup/test_synchronization.py
+++ b/test/soup/test_synchronization.py
@@ -132,7 +132,7 @@ def make_testcase(src, src_data, snk, snk_data):
# Generate all the variations of TestSynchronization
self = soup.get_module(__name__)
-mods = soup.modules.get_all()
+mods = soup.modules.ModuleLoader.get_all()
for i in range(len(mods)):
for j in range(len(mods)):
source = mods[i]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]