diff test/__init__.py @ 1797:c1eec970d5c0

Optimize mailgw and cgi tests... ...by creating an empty instance before the tests start (only if needed). In setUp(), this instance is then copied to another directory for the actual tests. On my system, this about halved the execution time for test_cgi (33s -> 14s) and test_mailgw (40s -> 25s).
author Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
date Sun, 07 Sep 2003 20:37:33 +0000
parents 9b910e8d987d
children f63aa57386b0
line wrap: on
line diff
--- a/test/__init__.py	Sun Sep 07 18:27:47 2003 +0000
+++ b/test/__init__.py	Sun Sep 07 20:37:33 2003 +0000
@@ -15,12 +15,14 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: __init__.py,v 1.18 2002-09-10 00:19:54 richard Exp $
+# $Id: __init__.py,v 1.19 2003-09-07 20:37:33 jlgijsbers Exp $
 
-import os, tempfile, unittest, shutil
+import os, tempfile, unittest, shutil, errno
 import roundup.roundupdb
 roundup.roundupdb.SENDMAILDEBUG=os.environ['SENDMAILDEBUG']=tempfile.mktemp()
 
+from roundup import init
+
 # figure all the modules available
 dir = os.path.split(__file__)[0]
 test_mods = {}
@@ -30,12 +32,36 @@
 	test_mods[name] = __import__(file[:-3], globals(), locals(), [])
 all_tests = test_mods.keys()
 
+dirname = '_empty_instance'
+def create_empty_instance():
+    remove_empty_instance()
+    init.install(dirname, 'templates/classic')
+    init.write_select_db(dirname, 'anydbm')
+    init.initialise(dirname, 'sekrit')
+
+def remove_empty_instance():
+    try:
+        shutil.rmtree(dirname)
+    except OSError, error:
+        if error.errno not in (errno.ENOENT, errno.ESRCH): raise
+
 def go(tests=all_tests):
-    l = []
-    for name in tests:
-        l.append(test_mods[name].suite())
-    suite = unittest.TestSuite(l)
-    runner = unittest.TextTestRunner()
-    runner.run(suite)
+    try:
+        l = []
+        needs_instance = 0
+        for name in tests:
+            mod = test_mods[name]
+            if hasattr(mod, 'NEEDS_INSTANCE'):
+                needs_instance = 1
+            l.append(test_mods[name].suite())
+
+        if needs_instance:
+            create_empty_instance()
+
+        suite = unittest.TestSuite(l)
+        runner = unittest.TextTestRunner()
+        runner.run(suite)
+    finally:
+        remove_empty_instance()
 
 # vim: set filetype=python ts=4 sw=4 et si

Roundup Issue Tracker: http://roundup-tracker.org/