@@ -5480,7 +5480,8 @@ def select_outlets(self, event):
54805480 return outlets
54815481
54825482
5483- def test_regular_step_with_choice ():
5483+ @pytest .mark .parametrize ("fn_select_outlets" , [True , False ])
5484+ def test_regular_step_with_choice (fn_select_outlets ):
54845485 class MyStep (Map ):
54855486 def select_outlets (self , event ):
54865487 outlets = ["all_events" ]
@@ -5490,7 +5491,60 @@ def select_outlets(self, event):
54905491 outlets .append ("up_to_five" )
54915492 return outlets
54925493
5494+ def select (event ):
5495+ outlets = ["all_events" ]
5496+ if event > 5 :
5497+ outlets .append ("more_than_five" )
5498+ else :
5499+ outlets .append ("up_to_five" )
5500+ return outlets
5501+
5502+ source = SyncEmitSource ()
5503+ if fn_select_outlets :
5504+ my_step = Map (fn = lambda x : x , termination_result_fn = lambda x , y : x + y , fn_select_outlets = select )
5505+ else :
5506+ my_step = MyStep (fn = lambda x : x , termination_result_fn = lambda x , y : x + y )
5507+
5508+ all_events = Map (lambda x : x , name = "all_events" )
5509+ more_than_five = Map (lambda x : x * 10 , name = "more_than_five" )
5510+ up_to_five = Map (lambda x : x * 100 , name = "up_to_five" )
5511+ sum_up_all_events = Reduce (0 , lambda acc , x : acc + x )
5512+ sum_up_more_than_five = Reduce (0 , lambda acc , x : acc + x )
5513+ sum_up_up_to_five = Reduce (0 , lambda acc , x : acc + x )
5514+
5515+ source .to (my_step )
5516+ my_step .to (all_events )
5517+ my_step .to (more_than_five )
5518+ my_step .to (up_to_five )
5519+ all_events .to (sum_up_all_events )
5520+ more_than_five .to (sum_up_more_than_five )
5521+ up_to_five .to (sum_up_up_to_five )
5522+
5523+ controller = source .run ()
5524+
5525+ for i in range (4 , 8 ):
5526+ controller .emit (i )
5527+
5528+ controller .terminate ()
5529+ termination_result = controller .await_termination ()
5530+
5531+ expected = sum (range (4 , 8 )) + sum (range (6 , 8 )) * 10 + sum (range (4 , 6 )) * 100
5532+ assert termination_result == expected
5533+
5534+
5535+ def test_regular_step_with_set_next ():
5536+ class MyStep (MapClass ):
5537+ def do (self , event ):
5538+ outlets = ["all_events" ]
5539+ if event > 5 :
5540+ outlets .append ("more_than_five" )
5541+ else :
5542+ outlets .append ("up_to_five" )
5543+ self .set_next_outlets (outlets )
5544+ return event
5545+
54935546 source = SyncEmitSource ()
5547+
54945548 my_step = MyStep (fn = lambda x : x , termination_result_fn = lambda x , y : x + y )
54955549 all_events = Map (lambda x : x , name = "all_events" )
54965550 more_than_five = Map (lambda x : x * 10 , name = "more_than_five" )
0 commit comments