Skip to content

Commit

Permalink
add more coverage for testing the entry point script. see #198.
Browse files Browse the repository at this point in the history
  • Loading branch information
kratsg committed Aug 23, 2018
1 parent 2c12f09 commit 54b378c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pyhf/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
@click.option('--entrypoint-xml', required=True, prompt='Top-level XML', help='The top-level XML file for the workspace definition.', type=click.Path(exists=True))
@click.option('--workspace', required=True, prompt='Workspace directory', help='The location of workspace.', type=click.Path(exists=True))
@click.option('--output-file', required=True, prompt='Output file', help='The location of the output json file. If not specified, prints to screen.')
def xml2json(entrypoint_xml, workspace, output_file=None):
spec = readxml.parse(entrypoint_xml, workspace, enable_tqdm=True)
@click.option('--tqdm/--no-tqdm', default=True)
def xml2json(entrypoint_xml, workspace, output_file, tqdm):
spec = readxml.parse(entrypoint_xml, workspace, enable_tqdm=tqdm)
json.dump(spec, open(output_file, 'w+'), indent=4, sort_keys=True)
log.info("Written to {0:s}".format(output_file))
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'pytest>=3.5.1',
'pytest-cov>=2.5.1',
'pytest-benchmark[histogram]',
'pytest-console-scripts',
'python-coveralls',
'coverage==4.0.3', # coveralls
'matplotlib',
Expand Down
27 changes: 27 additions & 0 deletions tests/test_scripts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest
import json
import shlex

import pyhf

# see test_import.py for the same (detailed) test
def test_import_prepHistFactory(tmpdir, script_runner):
temp = tmpdir.join("parsed_output.json")
command = 'pyhf_xml2json --entrypoint-xml validation/xmlimport_input/config/example.xml --workspace validation/xmlimport_input/ --output-file {0:s} --no-tqdm'.format(temp.strpath)
ret = script_runner.run(*shlex.split(command))
assert ret.success
assert ret.stdout == ''
assert ret.stderr == ''

parsed_xml = json.loads(temp.read())
spec = {'channels': parsed_xml['channels']}
pyhf.utils.validate(spec, pyhf.utils.get_default_schema())

def test_import_prepHistFactory_TQDM(tmpdir, script_runner):
temp = tmpdir.join("parsed_output.json")
command = 'pyhf_xml2json --entrypoint-xml validation/xmlimport_input/config/example.xml --workspace validation/xmlimport_input/ --output-file {0:s}'.format(temp.strpath)
ret = script_runner.run(*shlex.split(command))
assert ret.success
assert ret.stdout == ''
assert ret.stderr != ''

0 comments on commit 54b378c

Please sign in to comment.