-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* work towards get table cli * add tests and adjust cli * correct docstring Co-Authored-By: Gregory Way <[email protected]> * updates to subprocess test util Co-Authored-By: Gregory Way <[email protected]> Co-Authored-By: Faisal Alquaddoomi <[email protected]> * serialize via json.dumps with python-fire Co-Authored-By: Faisal Alquaddoomi <[email protected]> --------- Co-authored-by: Gregory Way <[email protected]> Co-authored-by: Faisal Alquaddoomi <[email protected]>
- Loading branch information
1 parent
f35a001
commit 906da2b
Showing
6 changed files
with
104 additions
and
27 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,29 @@ | ||
""" | ||
Setup almanack CLI through python-fire | ||
""" | ||
|
||
import json | ||
|
||
import fire | ||
|
||
from .metrics.data import get_table | ||
|
||
|
||
def cli_get_table() -> None: | ||
""" | ||
Creates Fire CLI for get_table_json_wrapper. | ||
This enables the use of CLI such as: | ||
`almanck <repo path>` | ||
""" | ||
fire.Fire(component=get_table, serialize=json.dumps) | ||
|
||
|
||
if __name__ == "__main__": | ||
""" | ||
Setup the CLI with python-fire for the almanack package. | ||
This allows the function `check` to be ran through the | ||
command line interface. | ||
""" | ||
cli_get_table() |
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 was deleted.
Oops, something went wrong.
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,56 @@ | ||
""" | ||
Tests CLI functionality. | ||
""" | ||
|
||
import json | ||
|
||
import yaml | ||
|
||
from almanack.metrics.data import METRICS_TABLE | ||
from tests.data.almanack.repo_setup.create_repo import repo_setup | ||
|
||
from .utils import run_cli_command | ||
|
||
|
||
def test_cli_util(): | ||
""" | ||
Test the run_cli_command for successful output | ||
""" | ||
|
||
_, _, returncode = run_cli_command(["echo", "'hello world'"]) | ||
|
||
assert returncode == 0 | ||
|
||
|
||
def test_cli_almanack(tmp_path): | ||
""" | ||
Tests running `almanack` as a CLI | ||
""" | ||
|
||
# create a repo with a single file and commit | ||
repo = repo_setup(repo_path=tmp_path, files={"example.txt": "example"}) | ||
|
||
# gather output and return code from running a CLI command | ||
stdout, _, returncode = run_cli_command(command=["almanack", repo.path]) | ||
|
||
# make sure we return 0 on success | ||
assert returncode == 0 | ||
|
||
# gather result of CLI as json | ||
results = json.loads(stdout) | ||
|
||
# make sure we have a list of output | ||
assert isinstance(results, list) | ||
|
||
# open the metrics table | ||
with open(METRICS_TABLE, "r") as f: | ||
metrics_table = yaml.safe_load(f) | ||
|
||
# check that all keys exist in the output from metrics table to cli str | ||
assert all( | ||
x == y | ||
for x, y in zip( | ||
sorted([result["name"] for result in results]), | ||
sorted([metric["name"] for metric in metrics_table["metrics"]]), | ||
) | ||
) |
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