Skip to content

Commit

Permalink
tests: added tests to check band argument behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRec committed Oct 5, 2023
1 parent 130c434 commit 7aee85f
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions tests/population/test_rasterpop.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def test__raster_pop_internal_methods(
assert np.array_equal(
rp._xds.to_numpy(), xarr_1_aoi[1]["post_clip"], equal_nan=True
)
assert len(rp._xds.shape) == 2

# call and test _to_geopandas and assert to geopandas expectations
rp._to_geopandas()
Expand Down Expand Up @@ -457,7 +458,7 @@ def test_rasterpop_init_raises(

@pytest.mark.parametrize(
"aoi_bounds, aoi_crs, round, threshold, var_name, urban_centre_bounds,"
" urban_centre_crs, expected",
" urban_centre_crs, band, expected",
[
# test aoi_bounds incorrect type
(
Expand All @@ -468,6 +469,7 @@ def test_rasterpop_init_raises(
"population",
lazy_fixture("xarr_1_uc"),
None,
1,
pytest.raises(
TypeError,
match="^`aoi_bounds` expected .*Polygon.*. Got .*str.*",
Expand All @@ -482,6 +484,7 @@ def test_rasterpop_init_raises(
"population",
lazy_fixture("xarr_1_uc"),
None,
1,
pytest.raises(
TypeError,
match="^`aoi_crs` expected .*str.*. Got .*float.*",
Expand All @@ -496,6 +499,7 @@ def test_rasterpop_init_raises(
"population",
lazy_fixture("xarr_1_uc"),
None,
1,
pytest.raises(
TypeError,
match="^`round` expected .*bool.*. Got .*str.*",
Expand All @@ -510,6 +514,7 @@ def test_rasterpop_init_raises(
"population",
lazy_fixture("xarr_1_uc"),
None,
1,
pytest.raises(
TypeError,
match=(
Expand All @@ -527,6 +532,7 @@ def test_rasterpop_init_raises(
1.0,
lazy_fixture("xarr_1_uc"),
None,
1,
pytest.raises(
TypeError,
match="^`var_name` expected .*str.*. Got .*float.*",
Expand All @@ -541,6 +547,7 @@ def test_rasterpop_init_raises(
"population",
"test",
None,
1,
pytest.raises(
TypeError,
match=(
Expand All @@ -558,13 +565,32 @@ def test_rasterpop_init_raises(
"population",
lazy_fixture("xarr_1_uc"),
1.0,
1,
pytest.raises(
TypeError,
match=(
"^`urban_centre_crs` expected .*str.*. Got .*float.*"
),
),
),
# test non-existent band
(
lazy_fixture("xarr_1_aoi"),
None,
False,
None,
"population",
lazy_fixture("xarr_1_uc"),
None,
0,
pytest.raises(
IndexError,
match=(
"Band number .* not contained in raster. Bands "
"available: .*"
),
),
),
],
)
def test_rasterpop_get_pop_raises(
Expand All @@ -577,6 +603,7 @@ def test_rasterpop_get_pop_raises(
var_name,
urban_centre_bounds: tuple,
urban_centre_crs,
band,
expected: Type[RaisesContext],
) -> None:
"""Test raises statements in RasterPop `get_population()` method.
Expand All @@ -601,6 +628,8 @@ def test_rasterpop_get_pop_raises(
for consistency with the `xarr_1_uc` fixture).
urban_centre_crs
see `get_pop()` docstring
band
see `get_pop()` docstring
expected : Type[RaisesContext]
Expected raise result.
Expand All @@ -627,6 +656,7 @@ def test_rasterpop_get_pop_raises(
var_name=var_name,
urban_centre_bounds=urban_centre_bounds[0],
urban_centre_crs=urban_centre_crs,
band=band,
)

def test_rasterpop_crs_conversion(
Expand Down Expand Up @@ -918,7 +948,7 @@ def test_plot_folium_type_defence(
boundary_weight=boundary_weight,
)

def test_plot_foliumn_no_uc(
def test_plot_folium_no_uc(
self,
xarr_1_fpath: str,
xarr_1_aoi: tuple,
Expand Down

0 comments on commit 7aee85f

Please sign in to comment.