Skip to content

Commit 33d0ad9

Browse files
committed
Rename fixture
1 parent 86c9d93 commit 33d0ad9

File tree

1 file changed

+46
-20
lines changed

1 file changed

+46
-20
lines changed

climada/hazard/test/test_forecast.py

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,22 @@
3131

3232

3333
@pytest.fixture
34-
def hazard_kwargs_fixture():
35-
from climada.hazard.test.test_base import hazard_kwargs as get_hazard_kwargs
36-
37-
return get_hazard_kwargs()
34+
def haz_kwargs():
35+
return hazard_kwargs()
3836

3937

4038
@pytest.fixture
41-
def dummy_hazard(hazard_kwargs_fixture):
42-
return Hazard(**hazard_kwargs_fixture)
39+
def dummy_hazard(haz_kwargs):
40+
return Hazard(**haz_kwargs)
4341

4442

45-
def test_init_hazard_forecast(hazard_kwargs_fixture):
43+
def test_init_hazard_forecast(haz_kwargs):
4644
haz_fc = HazardForecast(
4745
lead_time=np.array(
4846
["2024-01-01T00:00:00", "2024-01-01T00:01:00"], dtype="datetime64[s]"
4947
),
5048
member=np.array([0, 1]),
51-
**hazard_kwargs_fixture,
49+
**haz_kwargs,
5250
)
5351
assert isinstance(haz_fc, HazardForecast)
5452
npt.assert_array_equal(
@@ -57,21 +55,49 @@ def test_init_hazard_forecast(hazard_kwargs_fixture):
5755
)
5856
assert haz_fc.lead_time.dtype == "datetime64[s]"
5957
npt.assert_array_equal(haz_fc.member, np.array([0, 1]))
60-
assert haz_fc.haz_type == hazard_kwargs_fixture["haz_type"]
61-
assert haz_fc.pool == hazard_kwargs_fixture["pool"]
62-
assert haz_fc.units == hazard_kwargs_fixture["units"]
63-
assert haz_fc.centroids == hazard_kwargs_fixture["centroids"]
64-
npt.assert_array_equal(haz_fc.event_id, hazard_kwargs_fixture["event_id"])
65-
npt.assert_array_equal(haz_fc.frequency, hazard_kwargs_fixture["frequency"])
66-
assert haz_fc.frequency_unit == hazard_kwargs_fixture["frequency_unit"]
67-
npt.assert_array_equal(haz_fc.event_name, hazard_kwargs_fixture["event_name"])
68-
npt.assert_array_equal(haz_fc.date, hazard_kwargs_fixture["date"])
69-
npt.assert_array_equal(haz_fc.orig, hazard_kwargs_fixture["orig"])
58+
assert haz_fc.haz_type == haz_kwargs["haz_type"]
59+
assert haz_fc.pool == haz_kwargs["pool"]
60+
assert haz_fc.units == haz_kwargs["units"]
61+
assert haz_fc.centroids == haz_kwargs["centroids"]
62+
npt.assert_array_equal(haz_fc.event_id, haz_kwargs["event_id"])
63+
npt.assert_array_equal(haz_fc.frequency, haz_kwargs["frequency"])
64+
assert haz_fc.frequency_unit == haz_kwargs["frequency_unit"]
65+
npt.assert_array_equal(haz_fc.event_name, haz_kwargs["event_name"])
66+
npt.assert_array_equal(haz_fc.date, haz_kwargs["date"])
67+
npt.assert_array_equal(haz_fc.orig, haz_kwargs["orig"])
68+
npt.assert_array_equal(
69+
haz_fc.intensity.todense(), haz_kwargs["intensity"].todense()
70+
)
71+
npt.assert_array_equal(haz_fc.fraction.todense(), haz_kwargs["fraction"].todense())
72+
73+
74+
def test_from_hazard(dummy_hazard):
75+
lead_time = np.array(
76+
["2024-01-01T00:00:00", "2024-01-01T00:01:00"], dtype="datetime64[s]"
77+
)
78+
member = np.array([0, 1])
79+
haz_fc_from_haz = HazardForecast.from_hazard(
80+
dummy_hazard, lead_time=lead_time, member=member
81+
)
82+
83+
assert isinstance(haz_fc_from_haz, HazardForecast)
84+
npt.assert_array_equal(haz_fc_from_haz.lead_time, lead_time)
85+
npt.assert_array_equal(haz_fc_from_haz.member, member)
86+
assert haz_fc_from_haz.haz_type == dummy_hazard.haz_type
87+
assert haz_fc_from_haz.pool == dummy_hazard.pool
88+
assert haz_fc_from_haz.units == dummy_hazard.units
89+
assert haz_fc_from_haz.centroids == dummy_hazard.centroids
90+
npt.assert_array_equal(haz_fc_from_haz.event_id, dummy_hazard.event_id)
91+
npt.assert_array_equal(haz_fc_from_haz.frequency, dummy_hazard.frequency)
92+
assert haz_fc_from_haz.frequency_unit == dummy_hazard.frequency_unit
93+
npt.assert_array_equal(haz_fc_from_haz.event_name, dummy_hazard.event_name)
94+
npt.assert_array_equal(haz_fc_from_haz.date, dummy_hazard.date)
95+
npt.assert_array_equal(haz_fc_from_haz.orig, dummy_hazard.orig)
7096
npt.assert_array_equal(
71-
haz_fc.intensity.todense(), hazard_kwargs_fixture["intensity"].todense()
97+
haz_fc_from_haz.intensity.todense(), dummy_hazard.intensity.todense()
7298
)
7399
npt.assert_array_equal(
74-
haz_fc.fraction.todense(), hazard_kwargs_fixture["fraction"].todense()
100+
haz_fc_from_haz.fraction.todense(), dummy_hazard.fraction.todense()
75101
)
76102

77103

0 commit comments

Comments
 (0)