Skip to content

Commit

Permalink
test(OSMWayLoader): make test parametrization better
Browse files Browse the repository at this point in the history
  • Loading branch information
Calychas committed Mar 1, 2023
1 parent ff5b9ad commit 67a957f
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 62 deletions.
15 changes: 14 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ test = [
"pytest-mock>=3.0.0",
"requests-mock>=1.10.0",
"pytest-check>=2.1.4",
"pytest-parametrization>=2022.2.1",
]
# pdm add -dG visualization <library>
visualization = [
Expand Down Expand Up @@ -152,6 +153,7 @@ wrap-one-line = true
[tool.pytest.ini_options]
addopts = ["--import-mode=importlib"]
markers = ["slow: marks tests as slow (deselect with '-m \"not slow\"')"]
log_cli = true

[tool.licensecheck]
using = "requirements"
Expand Down
2 changes: 1 addition & 1 deletion srai/loaders/osm_way_loader/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""OSM way loader."""
"""OSMWayloader."""

from .osm_way_loader import NetworkType, OSMWayLoader

Expand Down
2 changes: 1 addition & 1 deletion srai/loaders/osm_way_loader/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""TODO."""
"""Constants for OSMWayLoader."""

from typing import Dict, List

Expand Down
120 changes: 61 additions & 59 deletions tests/loaders/test_osm_way_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pandas as pd
import pytest
import shapely.geometry as shpg
from parametrization import Parametrization as P
from pytest_check import check

from srai.loaders.exceptions import LoadedDataIsEmptyException
Expand Down Expand Up @@ -116,66 +117,67 @@ def valid_and_empty_polygons_area_gdf(
return pd.concat([first_polygon_area_gdf, empty_polygon_area_gdf], axis=0)


@pytest.mark.parametrize( # type: ignore
"area_gdf_fixture,expected_result,loader_params,expectation",
[
(
"empty_area_gdf",
None,
None,
pytest.raises(ValueError),
),
(
"no_crs_area_gdf",
None,
None,
pytest.raises(ValueError),
),
(
"bad_geometry_area_gdf",
None,
None,
pytest.raises(TypeError),
),
(
"empty_polygon_area_gdf",
None,
None,
pytest.raises(LoadedDataIsEmptyException),
),
(
"first_polygon_area_gdf",
(7, 6),
None,
does_not_raise(),
),
(
"multiple_polygons_overlaping_area_gdf",
(7, 6),
None,
does_not_raise(),
),
(
"multiple_polygons_overlaping_area_gdf",
(9, 7), # FIXME: shouldn't contain a node without an edge
{"network_type": NetworkType.BIKE, "contain_within_area": True},
does_not_raise(),
),
(
"multipolygons_area_gdf",
(11, 9),
None,
does_not_raise(),
),
(
"valid_and_empty_polygons_area_gdf",
(7, 6),
None,
does_not_raise(),
),
],
@P.parameters("area_gdf_fixture", "expected_result", "loader_params", "expectation") # type: ignore
@P.case( # type: ignore
"Raise when no geometry", "empty_area_gdf", None, None, pytest.raises(ValueError)
)
def test_osm_way_loader(
@P.case( # type: ignore
"Raise when no CRS",
"no_crs_area_gdf",
None,
None,
pytest.raises(ValueError),
)
@P.case( # type: ignore
"Raise when invalid geometry",
"bad_geometry_area_gdf",
None,
None,
pytest.raises(TypeError),
)
@P.case( # type: ignore
"Raise when no road infrastructure",
"empty_polygon_area_gdf",
None,
None,
pytest.raises(LoadedDataIsEmptyException),
)
@P.case( # type: ignore
"Return infrastructure when single polygon",
"first_polygon_area_gdf",
(7, 6),
None,
does_not_raise(),
)
@P.case( # type: ignore
"Return infrastructure when multiple overlapping polygons",
"multiple_polygons_overlaping_area_gdf",
(7, 6),
None,
does_not_raise(),
)
@P.case( # type: ignore
"Return infrastructure when node without any edges", # FIXME: shouldn't have a node w/o an edge
"multiple_polygons_overlaping_area_gdf",
(9, 7),
{"network_type": NetworkType.BIKE, "contain_within_area": True},
does_not_raise(),
)
@P.case( # type: ignore
"Return infrastructure when multipolygon",
"multipolygons_area_gdf",
(11, 9),
None,
does_not_raise(),
)
@P.case( # type: ignore
"Return infrastructure when correct polygon and polygon with no road infrastructure",
"valid_and_empty_polygons_area_gdf",
(7, 6),
None,
does_not_raise(),
)
def test_load(
area_gdf_fixture: str,
expected_result: Optional[Tuple[int, int]],
loader_params: Optional[Dict[str, Any]],
Expand Down

0 comments on commit 67a957f

Please sign in to comment.