提交 99090dbe authored 作者: Olivier Delalleau's avatar Olivier Delalleau

New option --verbose to theano-nose

This option can be used to help debug the --batch option, when re-running failed tests does not work properly. This commit also gets rid of some duplicated documentation to prevent it from getting outdated (it already was a bit outdated since it was not listing all options available).
上级 eeaba683
...@@ -13,22 +13,6 @@ It is also used to load the KnownFailure plugin, in order to hide ...@@ -13,22 +13,6 @@ It is also used to load the KnownFailure plugin, in order to hide
KnownFailureTests error messages. Use --without-knownfailure to KnownFailureTests error messages. Use --without-knownfailure to
disable that plugin. disable that plugin.
There are two additional local options: '--batch[=n]' and '--time-profile'.
If '--batch[=n]' is used without '--time-profile', this script will call
run_tests_in_batch.py` in order to run the tests by batches, not all at the
same time. The batches will comprise 100 elements each by default and
'n' elements if the option '=n' is specified.
If the '--time-profile' option is used, it will call `run_tests_in_batch.py`
with the option time_profile=True to conduct time-profiling of the tests.
(See 'help' function below for details.) If also specified, '--batch[=n]'
option will be interpreted as an indication of the number of tests to be run
between notifications of progress to standard output.
If the '--theano' option is used, it is replaced with the path to theano.
Useful if you don't know where it was installed.
`run_tests_in_batch.py` will in turn call back this script in another process. `run_tests_in_batch.py` will in turn call back this script in another process.
""" """
...@@ -48,6 +32,12 @@ def main(): ...@@ -48,6 +32,12 @@ def main():
import theano import theano
sys.argv[i] = theano.__path__[0] sys.argv[i] = theano.__path__[0]
# Handle the --verbose argument.
display_batch_output = False
if '--verbose' in sys.argv:
sys.argv += ['--nocapture', '--detailed-errors']
display_batch_output = True
# Handle --batch[=n] arguments # Handle --batch[=n] arguments
batch_args = [arg for arg in sys.argv if arg.startswith('--batch')] batch_args = [arg for arg in sys.argv if arg.startswith('--batch')]
for arg in batch_args: for arg in batch_args:
...@@ -70,10 +60,12 @@ def main(): ...@@ -70,10 +60,12 @@ def main():
sys.argv.remove(arg) sys.argv.remove(arg)
# Time-profiling and batch modes # Time-profiling and batch modes
if len(time_prof_args) or len(batch_args): if time_prof_args or batch_args:
from theano.tests import run_tests_in_batch from theano.tests import run_tests_in_batch
return run_tests_in_batch.main(batch_size=batch_size, return run_tests_in_batch.main(
time_profile=len(time_prof_args) > 0) batch_size=batch_size,
time_profile=bool(time_prof_args),
display_batch_output=display_batch_output)
# Non-batch mode. # Non-batch mode.
addplugins = [] addplugins = []
...@@ -110,6 +102,8 @@ def help(): ...@@ -110,6 +102,8 @@ def help():
Local options: Local options:
--help, -h: Displays this help.
--batch[=n]: --batch[=n]:
If specified without option '--time-profile', do not run all If specified without option '--time-profile', do not run all
the tests in one run, but split the execution in batches of the tests in one run, but split the execution in batches of
...@@ -142,14 +136,20 @@ def help(): ...@@ -142,14 +136,20 @@ def help():
latter may be used to identify duration patterns among the tests latter may be used to identify duration patterns among the tests
numbers. A full log is also saved as 'timeprof_rawlog'. numbers. A full log is also saved as 'timeprof_rawlog'.
--help, -h: Displays this help.
--without-knownfailure: Do not load the KnownFailure plugin. --without-knownfailure: Do not load the KnownFailure plugin.
--theano: This parameter is replaced with the path to the theano library. --theano: This parameter is replaced with the path to the theano
As theano-nose is a wrapper to nosetests, it expect a path to the tests to run. library. As theano-nose is a wrapper to nosetests, it
If you don't know where theano is installed, use this option expects a path to the tests to run.
to have it inserted automatically. If you do not know where theano is installed, use this
option to have it inserted automatically.
--verbose: Use this parameter to run nosetests with options
'--verbose', '--nocapture' and '--detailed-errors' and
show the output of nosetests during batch execution.
This can be useful to debug situations where re-running
only the failed tests after batch execution is not
working properly.
The other options will be passed to nosetests, see ``nosetests -h``. The other options will be passed to nosetests, see ``nosetests -h``.
""" """
......
...@@ -63,7 +63,7 @@ import theano ...@@ -63,7 +63,7 @@ import theano
def main(stdout=None, stderr=None, argv=None, theano_nose=None, def main(stdout=None, stderr=None, argv=None, theano_nose=None,
batch_size=None, time_profile=False): batch_size=None, time_profile=False, display_batch_output=False):
""" """
Run tests with optional output redirection. Run tests with optional output redirection.
...@@ -77,6 +77,9 @@ def main(stdout=None, stderr=None, argv=None, theano_nose=None, ...@@ -77,6 +77,9 @@ def main(stdout=None, stderr=None, argv=None, theano_nose=None,
Theano/bin to call nosetests. Otherwise we call the provided script. Theano/bin to call nosetests. Otherwise we call the provided script.
If batch_size is None, we use a default value of 100. If batch_size is None, we use a default value of 100.
If display_batch_output is False, then the output of nosetests during batch
execution is hidden.
""" """
if stdout is None: if stdout is None:
...@@ -105,13 +108,15 @@ def main(stdout=None, stderr=None, argv=None, theano_nose=None, ...@@ -105,13 +108,15 @@ def main(stdout=None, stderr=None, argv=None, theano_nose=None,
try: try:
sys.stdout = stdout sys.stdout = stdout
sys.stderr = stderr sys.stderr = stderr
run(stdout, stderr, argv, theano_nose, batch_size, time_profile) run(stdout, stderr, argv, theano_nose, batch_size, time_profile,
display_batch_output)
finally: finally:
sys.stdout = stdout_backup sys.stdout = stdout_backup
sys.stderr = stderr_backup sys.stderr = stderr_backup
def run(stdout, stderr, argv, theano_nose, batch_size, time_profile): def run(stdout, stderr, argv, theano_nose, batch_size, time_profile,
display_batch_output):
# Setting aside current working directory for later saving # Setting aside current working directory for later saving
sav_dir = os.getcwd() sav_dir = os.getcwd()
...@@ -156,20 +161,26 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile): ...@@ -156,20 +161,26 @@ def run(stdout, stderr, argv, theano_nose, batch_size, time_profile):
################################### ###################################
# RUNNING TESTS IN BATCHES OF %s # # RUNNING TESTS IN BATCHES OF %s #
###################################""" % batch_size ###################################""" % batch_size
# We suppress all output because we want the user to focus only on # When `display_batch_output` is False, we suppress all output because
# the failed tests, which are re-run (with output) below. # we want the user to focus only on the failed tests, which are re-run
# (with output) below.
dummy_out = open(os.devnull, 'w') dummy_out = open(os.devnull, 'w')
for test_id in xrange(1, n_tests + 1, batch_size): for test_id in xrange(1, n_tests + 1, batch_size):
stdout.flush() stdout.flush()
stderr.flush() stderr.flush()
test_range = range(test_id, min(test_id + batch_size, n_tests + 1)) test_range = range(test_id, min(test_id + batch_size, n_tests + 1))
rval = subprocess.call( cmd =([python, theano_nose, '--with-id'] +
([python, theano_nose, '-q', '--with-id'] map(str, test_range) +
+ map(str, test_range) argv)
+ argv), subprocess_extra_args = dict(stdin=dummy_in.fileno())
if not display_batch_output:
# Use quiet mode in nosetests.
cmd.append('-q')
# Suppress all output.
subprocess_extra_args.update(dict(
stdout=dummy_out.fileno(), stdout=dummy_out.fileno(),
stderr=dummy_out.fileno(), stderr=dummy_out.fileno()))
stdin=dummy_in.fileno()) subprocess.call(cmd, **subprocess_extra_args)
# Recover failed test indices from the 'failed' field of the # Recover failed test indices from the 'failed' field of the
# '.noseids' file. We need to do it after each batch because # '.noseids' file. We need to do it after each batch because
# otherwise this field may get erased. We use a set because it # otherwise this field may get erased. We use a set because it
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论