diff --git a/src/process.py b/src/process.py index 7dc0906..a11fa6a 100755 --- a/src/process.py +++ b/src/process.py @@ -101,12 +101,16 @@ def process_config(config_val): oaipmh_convert(param_list) -if __name__ == "__main__": +def main(sys_argv): + """ MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN !!! + + :param sys_argv: sys.argv from command line, can be overridden for testing purposes + """ parser = argparse.ArgumentParser(description="Metarecogen") parser.add_argument('-r', '--record', action='store', help="Specify a record group to generate") # Parse command line arguments - args = parser.parse_args() + args = parser.parse_args(sys_argv[1:]) # Create output dir if not os.path.exists(OUTPUT_DIR): @@ -127,3 +131,6 @@ def process_config(config_val): # Loop over config and process each one for k, v in CONFIG.items(): process_config(v) + +if __name__ == "__main__": + main(sys.argv) diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..fdf3654 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,21 @@ +import os +import sys +import subprocess +import pytest + +# Add in path to source scripts +src_path = os.path.join(os.path.abspath(os.pardir), 'src') +sys.path.insert(0, src_path) + +from process import main + +# Basic command line parameter testing +@pytest.mark.parametrize("cli_params, expected_out", + [(["--help"], "usage:"), + (["-r", "dfdfdfdfd"], "ERROR: Cannot find dfdfdfdfd in config"), + ]) +def test_eval(capsys, cli_params, expected_out): + with pytest.raises(SystemExit): + main(["process.py"] + cli_params) + captured = capsys.readouterr() + assert expected_out in captured.out