Skip to content

Commit

Permalink
Merge pull request #28 from nlesc-nano/dev
Browse files Browse the repository at this point in the history
Improve documentation and query results
  • Loading branch information
felipeZ committed Feb 22, 2021
2 parents e3d245a + 52276fd commit bcff4b2
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions ceibacli/actions/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def query_collection_properties(opts: Options) -> pd.DataFrame:
# Transform the JSON reply into a DataFrame
properties = reply["properties"]
df = json_properties_to_dataframe(properties)
df.to_csv(opts.output_file)
print(f"Requested properties has been save to: {opts.output_file}")
output_file = f"{opts.collection_name}.csv"
df.to_csv(output_file)
print(f"Requested properties has been save to: {output_file}")
return df
3 changes: 1 addition & 2 deletions ceibacli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def parse_user_arguments() -> Tuple[str, Options]:
query_parser = subparsers.add_parser(
"query", help="Query some properties from the database",
parents=[common_parser])
query_parser.add_argument("-o", "--output", help="File to store the properties", default="output_properties.csv")

# Manage the Jobs status
subparsers.add_parser(
Expand All @@ -91,7 +90,7 @@ def handle_input(args: argparse.Namespace) -> Options:
"""Check user input."""
input_file = getattr(args, "input", None)
if input_file is None:
user_input = {key: value for key, value in vars(args).items() if key not in {"command", "input", "output"}}
user_input = {key: value for key, value in vars(args).items() if key not in {"command", "input"}}
input_file = Path(tempfile.gettempdir()) / "user_input.yml"
with open(input_file, 'w') as handler:
yaml.dump(user_input, handler)
Expand Down
5 changes: 1 addition & 4 deletions ceibacli/input_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ def is_in_array_uppercase(array: Iterable[str]) -> Schema:
Optional("web", default=DEFAULT_WEB): str,

# Name to which the property belongs. e.g. Theory level
Optional("collection_name", default=None): Or(str, None),

# Name to store the properties as csv
Optional("output_file", default="output_properties.csv"): str
Optional("collection_name", default=None): Or(str, None)
})

ADD_SCHEMA = Schema({
Expand Down
2 changes: 1 addition & 1 deletion docs/query.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ To request all the datasets available in a given collection, you just need to ru
ceibacli query -w http://yourCeibaInstance:8080/grapqhl -c simulation2

That command will write into your current work directory a file called ``output_properties.csv``
That command will write into your current work directory a file called ``simulation2.csv``
containing the properties in the requested collection.
2 changes: 1 addition & 1 deletion tests/files/input_test_query.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
collection_name: "functional/basisset"
collection_name: "example_collection"
10 changes: 7 additions & 3 deletions tests/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ def test_query(mocker: MockFixture, tmp_path: Path):
# Read and Validate user input
path_input = PATH_TEST / "input_test_query.yml"
opts = validate_input(path_input, "query")
opts.output_file = (tmp_path / "output.csv").absolute().as_posix()

# Mock the server call
mocker.patch("ceibacli.actions.query.query_server",
return_value=read_mocked_reply("query_mocked.json"))

df = query_properties(opts)
assert len(df) == 10
try:
df = query_properties(opts)
assert len(df) == 10
finally:
path = Path("example_collection.csv")
if path.exists():
path.unlink()


def test_query_collections(mocker: MockFixture):
Expand Down

0 comments on commit bcff4b2

Please sign in to comment.