Mercurial > p > roundup > code
changeset 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 | 4de2e611b6f3 |
| children | 9bd553ea75fa |
| files | test/__init__.py test/test_cgi.py test/test_mailgw.py |
| diffstat | 3 files changed, 44 insertions(+), 16 deletions(-) [+] |
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
--- a/test/test_cgi.py Sun Sep 07 18:27:47 2003 +0000 +++ b/test/test_cgi.py Sun Sep 07 20:37:33 2003 +0000 @@ -8,13 +8,15 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: test_cgi.py,v 1.18 2003-08-11 11:28:31 jlgijsbers Exp $ +# $Id: test_cgi.py,v 1.19 2003-09-07 20:37:33 jlgijsbers Exp $ import unittest, os, shutil, errno, sys, difflib, cgi, re from roundup.cgi import client from roundup import init, instance, password, hyperdb, date +NEEDS_INSTANCE = 1 + class FileUpload: def __init__(self, content, filename): self.content = content @@ -65,9 +67,8 @@ except OSError, error: if error.errno not in (errno.ENOENT, errno.ESRCH): raise # create the instance - init.install(self.dirname, 'templates/classic') - init.write_select_db(self.dirname, 'anydbm') - init.initialise(self.dirname, 'sekrit') + shutil.copytree('_empty_instance', self.dirname) + # check we can load the package self.instance = instance.open(self.dirname) # and open the database
--- a/test/test_mailgw.py Sun Sep 07 18:27:47 2003 +0000 +++ b/test/test_mailgw.py Sun Sep 07 20:37:33 2003 +0000 @@ -8,7 +8,7 @@ # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # -# $Id: test_mailgw.py,v 1.50 2003-09-07 18:27:47 jlgijsbers Exp $ +# $Id: test_mailgw.py,v 1.51 2003-09-07 20:37:33 jlgijsbers Exp $ import unittest, tempfile, os, shutil, errno, imp, sys, difflib, rfc822 @@ -17,6 +17,8 @@ from roundup.mailgw import MailGW, Unauthorized, uidFromAddress from roundup import init, instance, rfc2822 +NEEDS_INSTANCE = 1 + class Message(rfc822.Message): """String-based Message class with equivalence test.""" def __init__(self, s): @@ -77,9 +79,8 @@ except OSError, error: if error.errno not in (errno.ENOENT, errno.ESRCH): raise # create the instance - init.install(self.dirname, 'templates/classic') - init.write_select_db(self.dirname, 'anydbm') - init.initialise(self.dirname, 'sekrit') + shutil.copytree('_empty_instance', self.dirname) + # check we can load the package self.instance = instance.open(self.dirname) # and open the database
