[conduit: 12/138] Argh, work damn u..
- From: John Carr <johncarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [conduit: 12/138] Argh, work damn u..
- Date: Thu, 21 May 2009 03:27:57 -0400 (EDT)
commit 181056dfa624f62ac501f6c6c166727cebea4870
Author: John Carr <john carr unrouted co uk>
Date: Mon Apr 20 05:31:53 2009 -0700
Argh, work damn u..
---
test/soup/__init__.py | 7 +++++++
test/soup/modules/__init__.py | 27 ++++++++++++++++++++++-----
test/soup/modules/folder.py | 1 +
test/soup/test_dataprovider.py | 9 +++++++--
4 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/test/soup/__init__.py b/test/soup/__init__.py
index a2ee49c..e5d0c30 100644
--- a/test/soup/__init__.py
+++ b/test/soup/__init__.py
@@ -9,6 +9,10 @@ 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]
+
class TestCase(unittest.TestCase):
def grumpy(self):
@@ -57,3 +61,6 @@ class TestCase(unittest.TestCase):
except KeyError:
return False
+
+import modules
+print modules.get_all()
diff --git a/test/soup/modules/__init__.py b/test/soup/modules/__init__.py
index d733a1e..91dfd2d 100644
--- a/test/soup/modules/__init__.py
+++ b/test/soup/modules/__init__.py
@@ -1,5 +1,5 @@
+import os, sys
-from soup import *
class ModuleWrapper(object):
@@ -37,8 +37,25 @@ class ModuleWrapper(object):
elif t == CHANGE_DELETE:
self.delete(uid)
-def all():
- """ Load all plugin wrappers and return everything that subclasses ModuleWrapper """
- import folder
- return ModuleWrapper.__class__.__subclasses__
+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__("modules", {}, {}, [module])
+
+load_modules()
+
+def get_all():
+ return ModuleWrapper.__subclasses__()
diff --git a/test/soup/modules/folder.py b/test/soup/modules/folder.py
index 3f69b0f..3eb89d3 100644
--- a/test/soup/modules/folder.py
+++ b/test/soup/modules/folder.py
@@ -10,3 +10,4 @@ class FolderWrapper(modules.ModuleWrapper):
"source": Utils.new_tempdir(),
})
return dp
+
diff --git a/test/soup/test_dataprovider.py b/test/soup/test_dataprovider.py
index 26011fb..dd14801 100644
--- a/test/soup/test_dataprovider.py
+++ b/test/soup/test_dataprovider.py
@@ -25,9 +25,14 @@ def make_testcase(dp):
return TestDataprovider
-from soup.modules import folder
-TestDataproviderFolder = make_testcase(folder.FolderWrapper)
+# Generate TestCase objects for each dataprovider wrapper
+self = soup.get_module(__name__)
+for wrapper in soup.modules.get_all():
+ print wrapper
+ setattr(self, "TestDataprovider%s" % "Folder", make_testcase(wrapper))
+
+# Allow people to run the test case directly
if __name__ == "__main__":
import unittest
unittest.main()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]