Commit 34eb056b authored by Niklas Selke's avatar Niklas Selke
Browse files

Fixed the current tests.

parent bac01398
......@@ -135,14 +135,15 @@ def create_sample_data(sample_data_dir):
values[np.random.default_rng().choice(values.size,
size=int(0.085*values.size),
replace=False)] = np.nan
pd.Series(values, datetime_index).to_csv(
pd.Series(values, datetime_index).dropna().to_csv(
Path(sample_data_dir, "sample_data.csv"), header=False
)
Path(sample_data_dir, "sample_metadata.cfg").write_text(
"[METADATA]\n"
"station_lat: 50.906389\n"
"station_lon: 6.403889\n"
"station_climatic_zone: 3\n"
"station_climatic_zone: 3\n",
encoding="utf-8"
)
......
......@@ -23,7 +23,7 @@ import numpy as np
import pandas as pd
import pytest
from toarstats import toarstats
from toarstats.interface import calculate_statistics
def get_all_statistics():
......@@ -82,7 +82,8 @@ def sample_metadata():
"""
parser = ConfigParser()
with open(Path(Path(__file__).resolve().parent,
"sample_data/sample_metadata.cfg")) as file:
"sample_data/sample_metadata.cfg"),
encoding="utf-8") as file:
parser.read_file(file)
Metadata = namedtuple("Metadata", ["station_lat", "station_lon",
"station_climatic_zone"])
......@@ -110,19 +111,22 @@ def test_results_match_reference_results(statistic, sampling, sample_data,
sample_metadata):
"""Test if the results match old package versions."""
if statistic == "drmdmax1h" and sampling == "monthly":
with pytest.raises(ValueError, match="Invalid mtype"):
result = toarstats(sampling, [statistic], sample_data,
sample_metadata)
with pytest.raises(ValueError, match="The drmdmax1h statistic cannot"
" be evaluated with monthly"
" sampling"):
result = calculate_statistics(sampling, statistic, sample_data,
sample_metadata)
else:
result = toarstats(sampling, [statistic], sample_data, sample_metadata)
result = calculate_statistics(sampling, statistic, sample_data,
sample_metadata)
for file in Path(
Path(__file__).resolve().parent, "reference_results"
Path(__file__).resolve().parent, "reference_results"
).rglob(f"{statistic}-{sampling}.csv"):
expected_result = pd.read_csv(file, header=None, index_col=0,
parse_dates=True)
pd.testing.assert_index_equal(result.index, expected_result.index,
check_names=False)
if statistic == "w90":
if statistic == "w90" and sampling == "seasonal":
with pytest.raises(AssertionError):
np.testing.assert_allclose(result.values,
expected_result.values,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment