1111import pytest
1212
1313from services .network .tracing .networktrace .test_network_trace_step_path_provider import PathTerminal , _verify_paths
14- from zepben .evolve import AcLineSegment , Clamp , Terminal , NetworkTraceStep , Cut , ConductingEquipment , TraversalQueue , Junction , ngen
14+ from zepben .evolve import AcLineSegment , Clamp , Terminal , NetworkTraceStep , Cut , ConductingEquipment , TraversalQueue , Junction , ngen , NetworkTraceActionType
1515from zepben .evolve .services .network .tracing .networktrace .tracing import Tracing
1616from zepben .evolve .testing .test_network_builder import TestNetworkBuilder
1717
@@ -178,8 +178,7 @@ async def test_can_Stop_on_start_item_when_running_from_conducting_equipment_bra
178178 assert set (map (lambda it : (it .num_equipment_steps , it .path .to_equipment .mrid ), steps )) \
179179 == {(0 , 'b0' )}
180180
181- if 'TOX_ENV_NAME' not in os .environ :
182-
181+ if 'TOX_ENV_NAME' not in os .environ : # Skips the test during tox runs as variable hardware will affect speed
183182 @pytest .mark .asyncio
184183 async def test_can_run_large_branching_traces (self ):
185184 try :
@@ -202,3 +201,27 @@ async def test_can_run_large_branching_traces(self):
202201 except Exception as e :
203202 sys .setrecursionlimit (1000 ) # back to default
204203 raise e
204+
205+ @pytest .mark .asyncio
206+ async def test_multiple_start_items_can_stop_on_start_doesnt_prevent_stop_checks_when_visiting_via_loop (self ):
207+ ns = (TestNetworkBuilder ()
208+ .from_acls () # c0
209+ .to_acls () # c1
210+ .to_acls () # c2
211+ .connect_to ('c0' )
212+ ).network
213+
214+ stop_checks : List [str ] = []
215+ steps : List [str ] = []
216+
217+ def stop_condition (item , _ ):
218+ stop_checks .append (item .path .to_terminal .mrid )
219+ return item .path .to_equipment .mrid == 'c1'
220+
221+ trace = Tracing .network_trace (action_step_type = NetworkTraceActionType .ALL_STEPS ) \
222+ .add_stop_condition (stop_condition ) \
223+ .if_not_stopping (lambda item , _ : steps .append (item .path .to_terminal .mrid ))
224+ await trace .run (ns .get ('c1' , ConductingEquipment ), can_stop_on_start_item = False )
225+
226+ assert stop_checks == ['c2-t1' , 'c2-t2' , 'c0-t1' , 'c0-t2' , 'c1-t1' ]
227+ assert steps == ['c1-t2' , 'c2-t1' , 'c2-t2' , 'c0-t1' , 'c0-t2' ]
0 commit comments