Skip to content

Commit c6f0986

Browse files
committed
Improve test_producer output
Change the name from "test case" to "test step" in the fallback test, as they are not really isolated test cases, but steps in one long test (as next steps depend on the previous step to have happened). This makes it more clear that steps are connected and need to run in sequence. Also the index was made part of the test steps definition, so we can show more clearly which (sub-)stop failed, and we also add a print line indicating which step is being ran. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 1f06955 commit c6f0986

File tree

1 file changed

+44
-32
lines changed

1 file changed

+44
-32
lines changed

tests/timeseries/test_producer.py

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -112,63 +112,75 @@ async def test_producer_fallback_formula(self, mocker: MockerFixture) -> None:
112112
# * if the meter value is None, it should be treated as None.
113113
# * for other components None is treated as 0.
114114

115-
# fmt: off
116115
expected_input_output: list[
117-
tuple[list[float | None], list[float | None], list[float | None], Power | None]
118-
] = [
119-
# ([pv_meter_power], [pv_inverter_power], [chp_power], expected_power)
116+
tuple[
117+
float,
118+
list[float | None],
119+
list[float | None],
120+
list[float | None],
121+
Power | None,
122+
]
123+
]
124+
# fmt: off
125+
expected_input_output = [
126+
# (test number, [pv_meter_power], [pv_inverter_power], [chp_power], expected_power)
127+
# Step 1: All components are available
120128
# Add power from meters and chp
121-
([-1.0, -2.0], [None, -200.0], [300], Power.from_watts(297.0)),
122-
([-1.0, -10], [-100.0, -200.0], [400], Power.from_watts(389.0)),
123-
# Case 2: The first meter is unavailable (None).
129+
(1.1, [-1.0, -2.0], [None, -200.0], [300], Power.from_watts(297.0)),
130+
(1.2, [-1.0, -10], [-100.0, -200.0], [400], Power.from_watts(389.0)),
131+
# Step 2: The first meter is unavailable (None).
124132
# Subscribe to the fallback inverter, but return None as the result,
125133
# according to the "nones-are-zero" rule
126-
([None, -2.0], [-100, -200.0], [400], None),
127-
# Case 3: First meter is unavailable (None). Fallback inverter provides
134+
(2.1, [None, -2.0], [-100, -200.0], [400], None),
135+
# Step 3: First meter is unavailable (None). Fallback inverter provides
128136
# a value.
129137
# Add second meter, first inverter and chp power
130-
([None, -2.0], [-100, -200.0], [400], Power.from_watts(298.0)),
131-
([None, -2.0], [-50, -200.0], [300], Power.from_watts(248.0)),
132-
# Case 4: Both first meter and its fallback inverter are unavailable
138+
(3.1, [None, -2.0], [-100, -200.0], [400], Power.from_watts(298.0)),
139+
(3.2, [None, -2.0], [-50, -200.0], [300], Power.from_watts(248.0)),
140+
# Step 4: Both first meter and its fallback inverter are unavailable
133141
# (None). Return 0 from failing component according to the
134142
# "nones-are-zero" rule.
135-
([None, -2.0], [None, -200.0], [300], Power.from_watts(298.0)),
136-
([None, -10.0], [-20.0, -200.0], [300], Power.from_watts(270.0)),
137-
# Case 5: CHP is unavailable. Return 0 from failing component
143+
(4.1, [None, -2.0], [None, -200.0], [300], Power.from_watts(298.0)),
144+
(4.2, [None, -10.0], [-20.0, -200.0], [300], Power.from_watts(270.0)),
145+
# Step 5: CHP is unavailable. Return 0 from failing component
138146
# according to the "nones-are-zero" rule.
139-
([None, -10.0], [-20.0, -200.0], [None], Power.from_watts(-30.0)),
140-
# Case 6: Both meters are unavailable (None). Subscribe for fallback inverter
141-
([None, None], [-20.0, -200.0], [None], None),
142-
([None, None], [-20.0, -200.0], [None], Power.from_watts(-220.0)),
143-
([None, None], [None, -200.0], [None], Power.from_watts(-200.0)),
144-
# Case 7: All components are unavailable (None). Return 0 according to the
147+
(5.1, [None, -10.0], [-20.0, -200.0], [None], Power.from_watts(-30.0)),
148+
# Step 6: Both meters are unavailable (None). Subscribe for fallback inverter
149+
(6.1, [None, None], [-20.0, -200.0], [None], None),
150+
(6.2, [None, None], [-20.0, -200.0], [None], Power.from_watts(-220.0)),
151+
(6.3, [None, None], [None, -200.0], [None], Power.from_watts(-200.0)),
152+
# Step 7: All components are unavailable (None). Return 0 according to the
145153
# "nones-are-zero" rule.
146-
([None, None], [None, None], [None], Power.from_watts(0)),
147-
([None, None], [None, None], [None], Power.from_watts(0)),
148-
([None, None], [None, None], [300.0], Power.from_watts(300.0)),
149-
([-200.0, None], [None, -100.0], [50.0], Power.from_watts(-250.0)),
150-
([-200.0, -200.0], [-10.0, -20.0], [50.0], Power.from_watts(-350.0)),
151-
# Case 8: Meter is unavailable, start fallback formula.
152-
([None, -200.0], [-10.0, -100.0], [50.0], None),
153-
([None, -200.0], [-10.0, -100.0], [50.0], Power.from_watts(-160)),
154+
(7.1, [None, None], [None, None], [None], Power.from_watts(0)),
155+
(7.2, [None, None], [None, None], [None], Power.from_watts(0)),
156+
(7.3, [None, None], [None, None], [300.0], Power.from_watts(300.0)),
157+
(7.4, [-200.0, None], [None, -100.0], [50.0], Power.from_watts(-250.0)),
158+
(7.5, [-200.0, -200.0], [-10.0, -20.0], [50.0], Power.from_watts(-350.0)),
159+
# Step 8: Meter is unavailable, start fallback formula.
160+
(8.1, [None, -200.0], [-10.0, -100.0], [50.0], None),
161+
(8.2, [None, -200.0], [-10.0, -100.0], [50.0], Power.from_watts(-160)),
154162

155163
]
156164
# fmt: on
157165

158-
for idx, (
166+
for (
167+
idx,
159168
meter_power,
160169
pv_inverter_power,
161170
chp_power,
162171
expected_power,
163-
) in enumerate(expected_input_output):
172+
) in expected_input_output:
173+
print("----------------------------------------------------")
174+
print(f" Test step {idx}")
175+
print("----------------------------------------------------")
164176
await mockgrid.mock_resampler.send_chp_power(chp_power)
165177
await mockgrid.mock_resampler.send_meter_power(meter_power)
166178
await mockgrid.mock_resampler.send_pv_inverter_power(pv_inverter_power)
167179
mockgrid.mock_resampler.next_ts()
168180

169181
result = await producer_power_receiver.receive()
170182
assert result.value == expected_power, (
171-
f"Test case {idx} failed:"
183+
f"Test step {idx} failed:"
172184
+ f" meter_power: {meter_power}"
173185
+ f" pv_inverter_power {pv_inverter_power}"
174186
+ f" chp_power {chp_power}"

0 commit comments

Comments
 (0)