Skip to content

Commit c10a4b3

Browse files
committed
Fix error in test fixtures
1 parent d2f035f commit c10a4b3

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

climada/engine/test/test_impact_calc.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ def hazard_fixture(exposure_fixture):
7575
lat=exposure_fixture.gdf.geometry.x,
7676
lon=exposure_fixture.gdf.geometry.y,
7777
)
78-
intensity = (
78+
intensity = sparse.csr_matrix(
7979
np.ones((n_events, exposure_fixture.gdf.shape[0])) * 50
8080
) # uniform intensity
8181
haz = Hazard()
82+
haz.event_id = np.arange(n_events)
83+
haz.event_name = haz.event_id
8284
haz.haz_type = "TC"
85+
haz.date = haz.event_id
86+
haz.frequency_unit = "m/s"
8387
haz.centroids = centroids
8488
haz.intensity = intensity
8589
haz.frequency = 1 / 10 * np.ones(n_events) # uniform frequency (10 n_events)
@@ -696,13 +700,16 @@ class TestImpactCalcForecast:
696700
"""Test impact calc for forecast hazard"""
697701

698702
def test_impactForecast_type(
703+
self,
699704
exposure_fixture,
700705
hazard_forecast_fixture,
701706
impact_func_set_fixture,
702707
impact_calc_fixture,
703708
):
704709
"""Test that ImpactForecast is returned correctly"""
705-
710+
impact = ImpactCalc(
711+
exposure_fixture, impact_func_set_fixture, hazard_forecast_fixture
712+
).impact(assign_centroids=True, save_mat=True)
706713
# check that impact is indeed ImpactForecast
707714
assert isinstance(impact, ImpactForecast)
708715
np.testing.assert_array_equal(
@@ -712,29 +719,28 @@ def test_impactForecast_type(
712719
np.testing.assert_array_equal(impact.member, hazard_forecast_fixture.member)
713720

714721
def test_impact_forecast_empty_impmat_error(
715-
hazard_forecast_fixture, exposure_fixture, impact_func_set_fixture
722+
self, hazard_forecast_fixture, exposure_fixture, impact_func_set_fixture
716723
):
717724
"""Test that error is raised when trying to compute impact forecast
718725
without saving impact matrix
719726
"""
720727
icalc = ImpactCalc(
721728
exposure_fixture, impact_func_set_fixture, hazard_forecast_fixture
722729
)
723-
with self.assertRaises(ValueError) as cm:
724-
icalc.impact(assign_centroids=False, save_mat=False)
725-
no_impmat_exception = cm.exception
726-
self.assertEqual(
727-
no_impmat_exception.args[0],
730+
no_impmat_exception = (
728731
"Saving impact matrix is required when using HazardForecast."
729-
"Please set save_mat=True.",
732+
"Please set save_mat=True."
730733
)
734+
with pytest.raises(ValueError) as cm:
735+
icalc.impact(assign_centroids=True, save_mat=False)
736+
assert no_impmat_exception == str(cm.value)
731737

732738
def test_impact_forecast_blocked_nonsense_attrs(
733-
hazard_forecast_fixture, exposure_fixture, impact_func_set_fixture
739+
self, hazard_forecast_fixture, exposure_fixture, impact_func_set_fixture
734740
):
735741
"""Test that nonsense attributes are blocked when computing impact forecast"""
736-
lead_time = hazard_fixture.lead_time
737-
member = hazard_fixture.member
742+
lead_time = hazard_forecast_fixture.lead_time
743+
member = hazard_forecast_fixture.member
738744

739745
impact = ImpactCalc(
740746
exposure_fixture, impact_func_set_fixture, hazard_forecast_fixture

0 commit comments

Comments
 (0)