[conduit: 58/138] Move test loading code out of way



commit a5f3da7440c27a48352dfbd4d13a78fde95202e3
Author: John Carr <john carr unrouted co uk>
Date:   Thu Apr 30 13:46:19 2009 -0700

    Move test loading code out of way
---
 test/soup/__init__.py |   21 +++++++++++++++++++++
 test/soup/soup        |   16 +++-------------
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/test/soup/__init__.py b/test/soup/__init__.py
index 1d67065..31b8a95 100644
--- a/test/soup/__init__.py
+++ b/test/soup/__init__.py
@@ -177,3 +177,24 @@ class _Online(Feature):
 Online = _Online()
 
 
+#
+# Custom test loader
+#
+
+class TestLoader(unittest.TestLoader):
+
+    def _flatten(self, tests):
+        if isinstance(tests, unittest.TestSuite):
+            res = []
+            for test in tests:
+                res.extend(self._flatten(test))
+            return res
+        else:
+            return [tests]
+
+    def loadTestsFromModule(self, module):
+        return self._flatten(super(TestLoader, self).loadTestsFromModule(module))
+
+    def loadTestsFromMain(self):
+        """ Load all tests that can be found starting from __main__ """
+        return self.loadTestsFromModule(__import__('__main__'))
diff --git a/test/soup/soup b/test/soup/soup
index 2233463..b087fd0 100755
--- a/test/soup/soup
+++ b/test/soup/soup
@@ -10,6 +10,8 @@ os.environ['TEST_DIRECTORY'] = 'tmp'
 if not os.path.exists('tmp'):
     os.mkdir('tmp')
 
+import soup
+
 from test_datatypes import *
 from test_dataprovider import *
 from test_synchronization import *
@@ -68,19 +70,7 @@ if __name__ == "__main__":
     opts, args = parser.parse_args()
 
     # Figure out which tests to run
-    loader = unittest.TestLoader()
-    tests = loader.loadTestsFromModule(__import__('__main__'))
-
-    # Temporary - flatten tests
-    def flatten(tests):
-        if isinstance(tests, unittest.TestSuite):
-            res = []
-            for test in tests:
-                res.extend(flatten(test))
-            return res
-        else:
-            return [tests]
-    tests = flatten(tests)
+    tests = soup.TestLoader().loadTestsFromMain()
 
     if opts.randomize:
         import random



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]