Skip to content

Commit 9e3ef4e

Browse files
change assert that centroid warning is not raised
1 parent 7d6007a commit 9e3ef4e

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

climada/engine/test/test_cost_benefit.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,21 +1129,30 @@ def test_measure_exposure_no_centroids(self):
11291129
entity.exposures.ref_year = 2018
11301130

11311131
# test that warning is not raised when centroid are assigned
1132-
with self.assertLogs(ILOG, level="WARNING") as logs:
1133-
cost_ben = CostBenefit()
1134-
cost_ben.calc(
1135-
hazard,
1136-
entity,
1137-
future_year=2040,
1138-
risk_func=risk_aai_agg,
1139-
imp_time_depen=None,
1140-
save_imp=True,
1141-
)
1142-
ILOG.warning("Dummy warning")
1143-
self.assertEqual(
1144-
["WARNING:climada.entity.measures.base:Dummy warning"],
1145-
logs.output,
1146-
)
1132+
try:
1133+
with self.assertLogs(ILOG, level="WARNING") as logs:
1134+
cost_ben = CostBenefit()
1135+
cost_ben.calc(
1136+
hazard,
1137+
entity,
1138+
future_year=2040,
1139+
risk_func=risk_aai_agg,
1140+
imp_time_depen=None,
1141+
save_imp=True,
1142+
)
1143+
if logs.output:
1144+
for log in logs.output:
1145+
self.assertNotIn(
1146+
"No assigned hazard centroids in exposure object after",
1147+
log,
1148+
"Centroids are already assinged in Measure Exposure object"
1149+
"and should not be reassigned.",
1150+
)
1151+
except AssertionError as e:
1152+
if "no logs" in str(e).lower():
1153+
pass
1154+
else:
1155+
raise
11471156

11481157
# add measure with exposure without assigned centroids
11491158
exp_no_assigned_centroids = entity.exposures.copy()

0 commit comments

Comments
 (0)