Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions fdb_utils/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@

@app.command("list")
def list_metadata(
show: Annotated[str, typer.Option(help='The keys to print, eg. "step,number,param"')] = "",
filter_values: Annotated[str, typer.Option("--filter", help='The metadata to filter results by, eg "date=20240624,time=0600".')] = ""
show: Annotated[str, typer.Argument(help='The keys to print, eg. "step,number,param"')] = "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does typer.Argument not mean that we need to provide this? Or is it still optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to my research no, also the test is green. Thus, I think it is fine.
However to mock list_all_values sounds good.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True true thanks for pointing to that test.
Yes i think that would be really nice, thanks!

filter_values: Annotated[str, typer.Option(
"--filter", "-f", help='The metadata to filter results by, eg "date=20240624,time=0600".'
)] = ""
) -> None:
"""List a union of metadata key/value pairs of GRIB messages archived to FDB."""

if not filter_values:
list_all = typer.confirm("Are you sure you want list everything in FDB? (may take some time).")
list_all = typer.confirm("Are you sure you want to list everything in FDB? (may take some time).")
if not list_all:
raise typer.Abort()

Expand Down
6 changes: 3 additions & 3 deletions test/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ def test_info():
def test_list_all_abort():
result = runner.invoke(app, ["list"], input='N')
assert result.exit_code == 1
assert "Are you sure you want list everything in FDB? (may take some time)." in result.stdout
assert "Are you sure you want to list everything in FDB? (may take some time)." in result.stdout

def test_list_all():
result = runner.invoke(app, ["list"], input='Y')
assert result.exit_code == 0
assert "Are you sure you want list everything in FDB? (may take some time)." in result.stdout
assert "Are you sure you want to list everything in FDB? (may take some time)." in result.stdout

def test_list_filter():
result = runner.invoke(app, ["list", "--filter", "date=20240606,number=0,step=0"], input='Y')
assert result.exit_code == 0
assert "Keys/Values in FDB for {'date': '20240606', 'number': '0', 'step': '0'}:" in result.stdout

def test_list_show(fdb):
result = runner.invoke(app, ["list", "--show", "date,number,step"], input='Y')
result = runner.invoke(app, ["list", "date,number,step"], input='Y')
print(result.stdout)
assert result.exit_code == 0
assert "Keys/Values of date, number, step in FDB:" in result.stdout
Expand Down
13 changes: 12 additions & 1 deletion test/test_fdb_describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
from test.utils import _generate_file_to_upload, _modify_grib_file
from test.conftest import fdb

def preprocess(show, filter_values):

show_keys = show.split(',') if show else []

filter_key_value_pairs = filter_values.split(',')
filter_by_values = dict(pair.split('=') for pair in filter_key_value_pairs) if filter_values else {}

return list_all_values(*show_keys, **filter_by_values)

def test_list_all_values(tmp_path, data_dir, fdb):

# Generate GRIB files with different dates and archive to FDB
Expand All @@ -27,14 +36,16 @@ def test_list_all_values(tmp_path, data_dir, fdb):

fdb.flush()

assert preprocess("date", "") == {'date': {'20240203', '20240202'}}
assert preprocess("date","date=20240203") == {'date': {'20240203'}}
assert list_all_values('time')['time'] == {'0300', '0600'}
assert list_all_values('step')['step'] == {'0','1','2','3'}
assert list_all_values('step', date='20240202')['step'] == {'0','1'}
assert list_all_values('number', date='20240202')['number'] == {5}
assert list_all_values(date='20240203')['step'] == {'2','3'}
assert list_all_values(date='20240203')['number'] == {1,2}

def test_listall_values_filtered(tmp_path, data_dir, fdb):
def test_list_all_values_filtered(tmp_path, data_dir, fdb):

# Generate GRIB files with different dates and archive to FDB
files = []
Expand Down