I've added Doctest for controllers files in testRunner.py :
#!/usr/bin/python
"""
Runs all tests that exist in the tests directories.
The class should have a name based on the file's path, like this:
FilenameDirectory -> DefaultTasksModel
for example:
applications/app/tests/controllers/default.py
is
class DefaultController(unittest.TestCase)
BEWARE that the name is NOT in plural (controllers->Controller)
Execute with:
> python web2py.py -S appname -M -R testRunner.py
02/03/2009
Jon Vlachoyiannis
jon@emotionull.com
"""
import unittest
import glob
import sys
import doctest
suite = unittest.TestSuite()
from copy import copy
# get all files with tests
test_files = glob.glob('applications/'+sys.argv[2]+'/tests/*/*.py')
doc_test_files = glob.glob('applications/'+sys.argv[2]+'/controllers/*.py')
if not test_files and not doc_test_files:
raise Exception("No files found for app: " + sys.argv[2])
for f in doc_test_files:
g = copy(globals())
execfile(f, g)
suite.addTest(doctest.DocFileSuite(f, globs=g,
module_relative=False))
# Bring all unit tests in and their controllers/models/whatever
for test_file in test_files:
g = copy(globals())
execfile(test_file, g)
# Create the appropriate class name based on filename and path
# TODO: use regex
filename = str.capitalize(test_file.split("/")[-1][:-3])
directory = str.capitalize(test_file.split("/")[-2][:-1])
# Load the to-be-tested file
to_be_tested_files = "applications/" + sys.argv[2] + "/" + \
directory.lower() + "s/" + filename.lower() + ".py"
execfile(to_be_tested_files, g)
suite.addTest(unittest.makeSuite(g[filename+directory]))
db = test_db # Use the test database for all tests
unittest.TextTestRunner(verbosity=2).run(suite)
0
matclab 14 years ago