Skip to content

Commit

Permalink
allow to set output_prefix to None
Browse files Browse the repository at this point in the history
  • Loading branch information
bast committed Nov 30, 2017
1 parent f5f4e41 commit 28e5bc2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions doc/creating/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ you define a configure function which defines how to handle a list of input
files and extra arguments. This configure function also defines the launcher
script or binary for your code, the full launch command, the output prefix, and
relative reference path where reference outputs are stored.
The output prefix can also be ``None``.

Here is an example module ``runtest_config.py`` which defines such a function:

Expand Down
5 changes: 3 additions & 2 deletions doc/creating/run_function.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ There are three more optional arguments to the ``run`` function which by default
is set by the ``configure`` function (in other words by the code using runtest).

``filters`` is a dictionary of suffix and filter list pairs and contains
filters to apply to the results. If we omit to pass it, then the calculations
filters to apply to the results. If we omit to pass it, then the calculations
will be run but not verified. This is useful for multi-step jobs. See also the
:ref:`example-test-script`.
:ref:`example-test-script`. If the ``output_prefix`` in the ``configure`` function is set to None,
then the filters are applied to the file names literally.
14 changes: 10 additions & 4 deletions runtest/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def run(options, configure, input_files, extra_args=None, filters=None, accepted
copy_path(caller_dir, options.work_dir)

launcher, command, output_prefix, relative_reference_path = configure(options, input_files, extra_args)
_output_prefix = os.path.join(options.work_dir, output_prefix)

launch_script_path = os.path.normpath(os.path.join(options.binary_dir, launcher))

Expand All @@ -46,10 +45,14 @@ def run(options, configure, input_files, extra_args=None, filters=None, accepted
stderr=subprocess.PIPE)
stdout, stderr = process.communicate()

with open('{0}.{1}'.format(_output_prefix, 'stdout'), 'w') as f:
if output_prefix is None:
_output_prefix = ''
else:
_output_prefix = os.path.join(options.work_dir, output_prefix) + '.'
with open('{0}{1}'.format(_output_prefix, 'stdout'), 'w') as f:
f.write(stdout.decode('UTF-8'))

with open('{0}.{1}'.format(_output_prefix, 'stderr'), 'w') as f:
with open('{0}{1}'.format(_output_prefix, 'stderr'), 'w') as f:
f.write(stderr.decode('UTF-8'))

if process.returncode != 0:
Expand All @@ -69,7 +72,10 @@ def run(options, configure, input_files, extra_args=None, filters=None, accepted
else:
try:
for suffix in filters:
output = '{0}.{1}'.format(output_prefix, suffix)
if output_prefix is None:
output = suffix
else:
output = '{0}.{1}'.format(output_prefix, suffix)
check(filter_list=filters[suffix],
out_name=os.path.join(options.work_dir, output),
ref_name=os.path.join(options.work_dir, relative_reference_path, output),
Expand Down
2 changes: 1 addition & 1 deletion runtest/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import namedtuple

__version__ = '2.0.1'
__version__ = '2.1.0'

version_info = namedtuple('version_info', ['major', 'minor', 'micro', 'releaselevel'])

Expand Down

0 comments on commit 28e5bc2

Please sign in to comment.