Commit acf7cfb0 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the subcommand loop to the script run.

parent f035cdc7
......@@ -8,16 +8,18 @@
DESCRIPTION
The command has to be run in the scripts directory
It can execute two subcommands 'script' and 'pytest'.
It can execute tree subcommands 'loop', 'script' and 'pytest'.
The first subcommand runs a given script in the application
The script subcommand runs a given script in the application
context (model, modules and database are available).
The second subcommand runs python tests within the pytest
framework and the application context.
The loop subcommand is similar the script one but it loops
over applications. They are defined by the DBURIS dictionary
located in models/_db_pro.py.
The pytest subcommand runs python tests within the pytest
framework and the application context.
The python tests are located in the directory myapplication/tests.
The scripts are located in myapplication/scripts.
The path of the test are relative to that directory.
OPTIONS
......@@ -35,11 +37,15 @@
> ./run -h
> ./run script -h
> ./run script fix-report-number.py
> ./run script fix_report_number.py
> ./run loop -h
> ./run loop ../models/_db_pro.py fix_report_number.py
> ./run pytest -h
> ./run pytest
> ./run pytest -xq test_foo/test_faa.py::test_fii
> ...
AUTHOR
......@@ -51,6 +57,7 @@ import pytest
import subprocess
import sys
MSG_SCRIPT = '\nExecute "%s" on "%s" [y/N]: '
PYTEST_SCRIPT = '_run_pytest.py'
TEST_DIR = 'tests'
WEB2PY_DIR = '../../web2py'
......@@ -97,6 +104,24 @@ def process(application, script, args):
return subprocess.call(cmd)
def run_loop(args):
"""Run the python script on several applications.
"""
# instantiate the DBURIS dictionary
execfile(args.dburis)
# loop over applications
for application in locals()['DBURIS']:
msg = MSG_SCRIPT % (args.filename, application)
rep = raw_input(msg)
if rep != "y":
print "Skip..."
continue
process(application, args.filename, args.args)
def run_pytest(args):
"""Run python test.
......@@ -198,6 +223,24 @@ if __name__ == "__main__":
SCRIPT.set_defaults(func=run_script)
# parser for the loop subcommand
LOOP = SUBPARSERS.add_parser("loop",
help="run the python script "
"over applications.")
LOOP.add_argument("dburis",
help="path to the python file containing the "
"DBURIS dictionary.")
LOOP.add_argument("filename",
help="the name of the python script.")
LOOP.add_argument("args",
nargs="?",
help="additional arguments to be passed to the script.")
LOOP.set_defaults(func=run_loop)
# parse the command line and run the selected command
ARGS = PARSER.parse_args()
ARGS.func(ARGS)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment