Skip to content

Commit 9c94c9f

Browse files
committed
tests: cleaning up
1 parent 622c8f6 commit 9c94c9f

File tree

1 file changed

+0
-55
lines changed

1 file changed

+0
-55
lines changed

climada/trajectories/test/test_risk_trajectory.py

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222

2323
import datetime
2424
import unittest
25-
26-
# Dummy Measure Enum for testing
27-
from enum import Enum
2825
from itertools import product
2926
from unittest.mock import Mock, PropertyMock, call, patch
3027

@@ -46,23 +43,11 @@
4643
)
4744
from climada.trajectories.riskperiod import ( # ImpactComputationStrategy, # If needed to mock its base class directly
4845
AllLinearStrategy,
49-
CalcRiskPeriod,
5046
ImpactCalcComputation,
5147
)
5248
from climada.trajectories.snapshot import Snapshot
5349

5450

55-
class Measure(Enum):
56-
SOME_MEASURE = 1
57-
ANOTHER_MEASURE = 2
58-
NO_MEASURE = 3 # For cases with no measure
59-
60-
61-
# --- Helper functions or classes for common mock objects ---
62-
# You might want to define some reusable mock setups if they are complex
63-
# E.g., a mock Snapshot or CalcRiskPeriod that always returns consistent data
64-
65-
6651
class TestRiskTrajectory(unittest.TestCase):
6752
def setUp(self):
6853
# Common setup for all tests
@@ -1091,39 +1076,6 @@ def test_get_risk_periods(self):
10911076
result = RiskTrajectory._get_risk_periods(
10921077
all_risk_periods, datetime.date(2021, 6, 1), datetime.date(2022, 6, 1)
10931078
)
1094-
# The condition `start_date >= period.snapshot0.date or end_date <= period.snapshot1.date`
1095-
# means it includes periods that *overlap* with the range, not strictly *within*.
1096-
# So for 2021-06-01 to 2022-06-01:
1097-
# rp1: (2020-01-01 to 2021-01-01) -> end_date (2022-06-01) is not <= 2021-01-01. start_date (2021-06-01) is not >= 2020-01-01. So this condition is OR.
1098-
# This condition seems to be designed to return periods that are *outside* or *partially outside* the range,
1099-
# which is counter-intuitive for "get_risk_periods". Let's re-evaluate the original logic.
1100-
1101-
# Original condition: start_date >= period.snapshot0.date or end_date <= period.snapshot1.date
1102-
# This condition is true if the query start date is after or equal to period's start date
1103-
# OR if the query end date is before or equal to period's end date.
1104-
# This is essentially: (period_starts_before_or_at_query_start) OR (period_ends_after_or_at_query_end)
1105-
# This seems to be a filter for periods that are *partially or fully contained* by the query range,
1106-
# or that *start before* the query range, or *end after* the query range.
1107-
# It's an "overlapping or encompassing" filter.
1108-
1109-
# Let's test with the provided dates and the OR condition
1110-
# Range: 2021-06-01 to 2022-06-01
1111-
# mock_rp1 (2020-01-01 to 2021-01-01):
1112-
# start_date (2021-06-01) >= period.snapshot0.date (2020-01-01) -> True
1113-
# end_date (2022-06-01) <= period.snapshot1.date (2021-01-01) -> False
1114-
# Result: True (due to OR) -> mock_rp1 IS included. This is correct based on the code, but unusual for 'get_risk_periods'.
1115-
1116-
# mock_rp2 (2021-01-01 to 2022-01-01):
1117-
# start_date (2021-06-01) >= period.snapshot0.date (2021-01-01) -> True
1118-
# end_date (2022-06-01) <= period.snapshot1.date (2022-01-01) -> False
1119-
# Result: True (due to OR) -> mock_rp2 IS included.
1120-
1121-
# mock_rp3 (2022-01-01 to 2023-01-01):
1122-
# start_date (2021-06-01) >= period.snapshot0.date (2022-01-01) -> False
1123-
# end_date (2022-06-01) <= period.snapshot1.date (2023-01-01) -> True
1124-
# Result: True (due to OR) -> mock_rp3 IS included.
1125-
1126-
# Based on the current logic, all periods should be returned given these examples.
11271079
result = RiskTrajectory._get_risk_periods(
11281080
all_risk_periods, datetime.date(2021, 6, 1), datetime.date(2022, 6, 1)
11291081
)
@@ -1140,13 +1092,6 @@ def test_get_risk_periods(self):
11401092
self.assertEqual(len(result), 3)
11411093
self.assertListEqual(result, all_risk_periods)
11421094

1143-
# This method's logic seems to include all periods unless a period is strictly *outside* the given range,
1144-
# which is not what the current condition `(start_date >= period.snapshot0.date or end_date <= period.snapshot1.date)` does.
1145-
# It seems the intent might be `period.snapshot0.date < end_date and period.snapshot1.date > start_date` for true overlap.
1146-
# However, testing against the *current implementation* is the goal of unit testing.
1147-
# So these tests reflect the current (potentially unusual) behavior.
1148-
11491095

1150-
# To run the tests
11511096
if __name__ == "__main__":
11521097
unittest.main(argv=["first-arg-is-ignored"], exit=False)

0 commit comments

Comments
 (0)