Skip to content

Commit

Permalink
clean up test_iterate_over_time with a fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
docNord committed May 4, 2024
1 parent a9142f3 commit a44a234
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions tests/unit/test_unit_smhi.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@ def __init__(self, station: MockMetobsStationLink):
self.station = station


@pytest.fixture
def setup_test_x():
"""Pytest fixture"""
df = pd.DataFrame(
{
"date": [
"2024-04-21 10:00",
"2024-04-21 11:00",
"2024-04-21 12:00",
"2024-04-22 12:00",
],
"Temperatur": [1, 1, 1, 12],
}
)
df["date"] = pd.to_datetime(df["date"])
df = df.set_index("date")

nearby_df = pd.DataFrame(
{"date": ["2024-04-22 10:00", "2024-04-22 11:00"], "Temperatur": [8, 9]}
)
nearby_df["date"] = pd.to_datetime(nearby_df["date"])
nearby_df = nearby_df.set_index("date")

missing_df = df[df.index.to_series().diff() > df.index.to_series().diff().median()]

return df, nearby_df, missing_df


class TestUnitSMHI:
"""Unit tests for SMHI class."""

Expand Down Expand Up @@ -234,34 +262,9 @@ def test_interpolate(
else:
mock_find_from_gps.assert_called_once()

def test_iterate_over_time(
self,
):
def test_iterate_over_time(self, setup_test_x):
"""Unit test for SMHI _iterate_over_time method."""
df = pd.DataFrame(
{
"date": [
"2024-04-21 10:00",
"2024-04-21 11:00",
"2024-04-21 12:00",
"2024-04-22 12:00",
],
"Temperatur": [1, 1, 1, 12],
}
)
df["date"] = pd.to_datetime(df["date"])
df = df.set_index("date")

nearby_df = pd.DataFrame(
{"date": ["2024-04-22 10:00", "2024-04-22 11:00"], "Temperatur": [8, 9]}
)
nearby_df["date"] = pd.to_datetime(nearby_df["date"])
nearby_df = nearby_df.set_index("date")

missing_df = df[
df.index.to_series().diff() > df.index.to_series().diff().median()
]

df, nearby_df, missing_df = setup_test_x
client = SMHI()

data = client._iterate_over_time(df, nearby_df, missing_df)
Expand Down

0 comments on commit a44a234

Please sign in to comment.