comparison 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
comparison
equal deleted inserted replaced
1796:4de2e611b6f3 1797:c1eec970d5c0
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 # 17 #
18 # $Id: __init__.py,v 1.18 2002-09-10 00:19:54 richard Exp $ 18 # $Id: __init__.py,v 1.19 2003-09-07 20:37:33 jlgijsbers Exp $
19 19
20 import os, tempfile, unittest, shutil 20 import os, tempfile, unittest, shutil, errno
21 import roundup.roundupdb 21 import roundup.roundupdb
22 roundup.roundupdb.SENDMAILDEBUG=os.environ['SENDMAILDEBUG']=tempfile.mktemp() 22 roundup.roundupdb.SENDMAILDEBUG=os.environ['SENDMAILDEBUG']=tempfile.mktemp()
23
24 from roundup import init
23 25
24 # figure all the modules available 26 # figure all the modules available
25 dir = os.path.split(__file__)[0] 27 dir = os.path.split(__file__)[0]
26 test_mods = {} 28 test_mods = {}
27 for file in os.listdir(dir): 29 for file in os.listdir(dir):
28 if file.startswith('test_') and file.endswith('.py'): 30 if file.startswith('test_') and file.endswith('.py'):
29 name = file[5:-3] 31 name = file[5:-3]
30 test_mods[name] = __import__(file[:-3], globals(), locals(), []) 32 test_mods[name] = __import__(file[:-3], globals(), locals(), [])
31 all_tests = test_mods.keys() 33 all_tests = test_mods.keys()
32 34
35 dirname = '_empty_instance'
36 def create_empty_instance():
37 remove_empty_instance()
38 init.install(dirname, 'templates/classic')
39 init.write_select_db(dirname, 'anydbm')
40 init.initialise(dirname, 'sekrit')
41
42 def remove_empty_instance():
43 try:
44 shutil.rmtree(dirname)
45 except OSError, error:
46 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
47
33 def go(tests=all_tests): 48 def go(tests=all_tests):
34 l = [] 49 try:
35 for name in tests: 50 l = []
36 l.append(test_mods[name].suite()) 51 needs_instance = 0
37 suite = unittest.TestSuite(l) 52 for name in tests:
38 runner = unittest.TextTestRunner() 53 mod = test_mods[name]
39 runner.run(suite) 54 if hasattr(mod, 'NEEDS_INSTANCE'):
55 needs_instance = 1
56 l.append(test_mods[name].suite())
57
58 if needs_instance:
59 create_empty_instance()
60
61 suite = unittest.TestSuite(l)
62 runner = unittest.TextTestRunner()
63 runner.run(suite)
64 finally:
65 remove_empty_instance()
40 66
41 # vim: set filetype=python ts=4 sw=4 et si 67 # vim: set filetype=python ts=4 sw=4 et si

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