From 59e66678382aeec5dc64d573db100886b168c7a4 Mon Sep 17 00:00:00 2001 From: Martin Vonk Date: Wed, 13 Mar 2024 11:38:36 +0100 Subject: [PATCH] add more tests --- src/spei/_version.py | 2 +- tests/test_climdex.py | 6 +++--- tests/test_si.py | 12 +++++++++--- tests/test_version.py | 3 ++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/spei/_version.py b/src/spei/_version.py index 066a16b..bcec6f4 100644 --- a/src/spei/_version.py +++ b/src/spei/_version.py @@ -13,4 +13,4 @@ def show_versions() -> None: for dep in deps: msg += f"{dep}: {metadata.version(dep)}\n" - print(msg) + return msg diff --git a/tests/test_climdex.py b/tests/test_climdex.py index 8699369..0d359c6 100644 --- a/tests/test_climdex.py +++ b/tests/test_climdex.py @@ -3,15 +3,15 @@ from spei import climdex -def text_climdex_rxnday(precmm: Series) -> None: +def test_climdex_rxnday(precmm: Series) -> None: climdex.rxnday(series=precmm, interval="10D", period="90D") -def text_climdex_rx1day(precmm: Series) -> None: +def test_climdex_rx1day(precmm: Series) -> None: climdex.rx1day(series=precmm) -def text_climdex_rx5day(precmm: Series) -> None: +def test_climdex_rx5day(precmm: Series) -> None: climdex.rx5day(series=precmm) diff --git a/tests/test_si.py b/tests/test_si.py index e4a20f9..8fad224 100644 --- a/tests/test_si.py +++ b/tests/test_si.py @@ -4,18 +4,24 @@ def test_spi(prec: Series) -> None: - spi(prec.rolling("30D", min_periods=30).sum().dropna(), prob_zero=True) + precr = prec.rolling("30D", min_periods=30).sum().dropna() + spi(precr, freq="ME", prob_zero=True) def test_spei(prec: Series, evap: Series) -> None: n = (prec - evap).rolling("30D", min_periods=30).sum().dropna() - spei(n) + spei(n, freq="ME") def test_sgi(head: Series) -> None: - sgi(head) + sgi(head, freq="ME") def test_sffi(prec: Series) -> None: sf = prec.rolling("30D", min_periods=30).sum().dropna() ssfi(sf) + + +def test_window(prec: Series, evap: Series) -> None: + n = (prec - evap).rolling("30D", min_periods=30).sum().dropna() + spei(n, freq="W", window=3) diff --git a/tests/test_version.py b/tests/test_version.py index 0520036..98fd397 100644 --- a/tests/test_version.py +++ b/tests/test_version.py @@ -7,4 +7,5 @@ def test_version() -> None: def test_show_versions(): - si.show_versions() + msg = si.show_versions() + assert isinstance(msg, str)