Skip to content

Commit

Permalink
Allow multiple file paths in cli create-archive
Browse files Browse the repository at this point in the history
  • Loading branch information
ka-sarthak committed Aug 15, 2024
1 parent b602902 commit 7a18adc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/nomad_polymerization_reactions/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ def cli():
)
@click.argument(
'JSON_FILE_PATH',
nargs=-1,
required=True,
type=click.Path(exists=True),
)
def _create_archive(json_file_path):
try:
generate_archive_from_json(json_file_path)
click.echo('Archive created successfully.')
for file_path in json_file_path:
generate_archive_from_json(file_path)
click.echo('Archive created successfully.')
except Exception as e:
click.echo(f'Archive creation failed. Error: {e}')
15 changes: 9 additions & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import glob
import os

from click.testing import CliRunner
Expand All @@ -23,10 +24,12 @@ def test_create_archive_help():


def test_create_archive_success():
result = invoke_cli(
cli,
['create-archive', 'tests/data/processed_reactions/paper_0_reaction_1.json'],
)
files = glob.glob('tests/data/processed_reactions/*.json')
result = invoke_cli(cli, ['create-archive', *files])
assert result.exit_code == 0
assert 'Archive created successfully.' in result.output
os.remove('paper_0_reaction_1.archive.yaml')
assert (
'Archive created successfully.\nArchive created successfully.\n'
in result.output
)
for file in files:
os.remove(file.split('/')[-1].replace('.json', '.archive.yaml'))

0 comments on commit 7a18adc

Please sign in to comment.