Skip to content

Commit

Permalink
chore: add test for wrong geo file
Browse files Browse the repository at this point in the history
  • Loading branch information
RaczeQ committed Jan 16, 2024
1 parent b01d909 commit b1c7324
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
10 changes: 3 additions & 7 deletions quackosm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def convert(self, value, param, ctx): # type: ignore
if not value:
return None

Check warning on line 80 in quackosm/cli.py

View check run for this annotation

Codecov / codecov/patch

quackosm/cli.py#L80

Added line #L80 was not covered by tests

if not pathlib.Path(value).exists():
raise typer.BadParameter("Cannot parse provided geo file")
value = _path_callback(ctx=ctx, value=value)

try:
gdf = gpd.read_file(value)
Expand Down Expand Up @@ -123,12 +122,9 @@ def convert(self, value, param, ctx): # type: ignore
if not value:
return None

Check warning on line 123 in quackosm/cli.py

View check run for this annotation

Codecov / codecov/patch

quackosm/cli.py#L123

Added line #L123 was not covered by tests

file_path = pathlib.Path(value)
value = _path_callback(ctx=ctx, value=value)

if not file_path.exists():
raise typer.BadParameter("Cannot parse provided OSM tags filter file")

return super().convert(file_path.read_text(), param, ctx) # type: ignore
return super().convert(pathlib.Path(value).read_text(), param, ctx) # type: ignore


def _filter_osm_ids_callback(value: list[str]) -> list[str]:
Expand Down
16 changes: 12 additions & 4 deletions tests/base/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ def test_proper_args(monaco_pbf_file_path: str, args: list[str], expected_result
"Geometry nonexistent file filter",
["--geom-filter-file", "nonexistent_geojson_file.geojson"],
) # type: ignore
@P.case(
"Geometry wrong file filter",
["--geom-filter-file", osm_tags_filter_file_path()],
) # type: ignore
@P.case("Filter OSM", ["--filter-osm-id", "124"]) # type: ignore
@P.case("Filter OSM", ["--filter-osm-id", "w/124"]) # type: ignore
@P.case("Filter OSM", ["--filter-osm-id", "w124"]) # type: ignore
Expand All @@ -304,8 +308,12 @@ def test_proper_args(monaco_pbf_file_path: str, args: list[str], expected_result
@P.case("Filter OSM", ["--filter-osm-id", "r124"]) # type: ignore
@P.case("Filter OSM", ["--filter-osm-id", "relation124"]) # type: ignore
@P.case("OSM way polygon config", ["--osm-way-polygon-config", "nonexistent_json_file.json"]) # type: ignore
def test_wrong_args(monaco_pbf_file_path: str, args: list[str]) -> None:
def test_wrong_args(
monaco_pbf_file_path: str, args: list[str], capsys: pytest.CaptureFixture
) -> None:
"""Test if doesn't run properly with options."""
result = runner.invoke(cli.app, [monaco_pbf_file_path, *args])

assert result.exit_code != 0
# Fix for the I/O error from the Click repository
# https://github.com/pallets/click/issues/824#issuecomment-1583293065
with capsys.disabled():
result = runner.invoke(cli.app, [monaco_pbf_file_path, *args])
assert result.exit_code != 0

0 comments on commit b1c7324

Please sign in to comment.