Skip to content

Commit

Permalink
Add basic command line tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vjf committed Aug 16, 2024
1 parent c563bb9 commit 427e2f8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
21 changes: 21 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 427e2f8

Please sign in to comment.