generated from FAIRmat-NFDI/nomad-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from FAIRmat-NFDI/8-add-cli-for-create-archive-…
…functionality 8 add cli for create archive functionality
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import click | ||
|
||
from nomad_polymerization_reactions.utils import generate_archive_from_json | ||
|
||
|
||
@click.group( | ||
help=""" | ||
This is the entry point to nomad-polymerization-reactions's command line interface | ||
CLI. This CLI provides a set of commands to interact with the utility functions | ||
of the package. | ||
""", | ||
) | ||
def cli(): | ||
pass | ||
|
||
|
||
@cli.command( | ||
help='Create an archive from a JSON file containing polymerization reaction data.', | ||
name='create-archive', | ||
) | ||
@click.argument( | ||
'JSON_FILE_PATH', | ||
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.') | ||
except Exception as e: | ||
click.echo(f'Archive creation failed. Error: {e}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
|
||
from click.testing import CliRunner | ||
from nomad_polymerization_reactions.cli import cli | ||
|
||
|
||
def invoke_cli(*args, **kwargs): | ||
return CliRunner().invoke(*args, **kwargs) | ||
|
||
|
||
def test_cli_help(): | ||
result = invoke_cli(cli, ['--help']) | ||
assert result.exit_code == 0 | ||
assert 'Usage' in result.output | ||
assert 'This is the entry point to nomad-polymerization-reactions' in result.output | ||
|
||
|
||
def test_create_archive_help(): | ||
result = invoke_cli(cli, ['create-archive', '--help']) | ||
assert result.exit_code == 0 | ||
assert 'Usage' in result.output | ||
assert 'Create an archive from a JSON file' in result.output | ||
|
||
|
||
def test_create_archive_success(): | ||
result = invoke_cli( | ||
cli, | ||
['create-archive', 'tests/data/processed_reactions/paper_0_reaction_1.json'], | ||
) | ||
assert result.exit_code == 0 | ||
assert 'Archive created successfully.' in result.output | ||
os.remove('paper_0_reaction_1.archive.yaml') |