
    	i9                    *   d Z ddlmZ ddlZddlmc mZ ddl	Z	ddl
mZmZmZ ddlZddlmZmZ ddlmZmZmZ  G d d      Zej.                  j                   G d	 d
             Zej.                  j                   G d d             Z G d d      Zy)zTests for periodic trigger system.

Tests for the PeriodicTrigger and TriggerCondition classes that provide
action execution during navigation operations.
    )annotationsN)	MagicMock	AsyncMockpatch)PeriodicTriggerTriggerCondition)ActionExecutorNavStateNavigationContextc                  @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)TestTriggerConditionzTest TriggerCondition class.c                l   t        d      }|j                  }d}||k(  }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}x}}|j                  }t               }||k(  }|st        j                  d|fd
||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      dt	        j
                         v st        j                  t              rt        j                  t              ndt        j                  |      dz  }dd|iz  }	t        t        j                  |	            d	x}x}}|j                  }d}||u }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            d	x}x}}y	)z+Test creating time-based trigger condition.       @interval_sec==z4%(py2)s
{%(py2)s = %(py0)s.interval_sec
} == %(py5)s	conditionpy0py2py5assert %(py7)spy7NzR%(py2)s
{%(py2)s = %(py0)s.progress_milestones
} == %(py6)s
{%(py6)s = %(py4)s()
}setr   r   py4py6assert %(py8)spy8Tisz8%(py2)s
{%(py2)s = %(py0)s.while_navigating
} is %(py5)s)r   r   
@pytest_ar_call_reprcompare@py_builtinslocals_should_repr_global_name	_safereprAssertionError_format_explanationprogress_milestonesr   while_navigating)
selfr   @py_assert1@py_assert4@py_assert3@py_format6@py_format8@py_assert5@py_format7@py_format9s
             P/home/nelsen/Projects/kognitive/orchestrator/src/executor/tests/test_triggers.pytest_interval_based_conditionz2TestTriggerCondition.test_interval_based_condition!   s   $#6	%%,,%,,,,%,,,,,,y,,,y,,,%,,,,,,,,,,,,55,5555,555555y555y555,5555555555555555555))1T1)T1111)T111111y111y111)111T1111111    c                   t        g d      }|j                  }d}||u }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd	|iz  }t        t        j                  |            dx}x}}|j                  }h d
}||k(  }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd	|iz  }t        t        j                  |            dx}x}}|j                  }d}||u }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd	|iz  }t        t        j                  |            dx}x}}y)z/Test creating progress-based trigger condition.      ?      ?      ?      ?r.   Nr#   z4%(py2)s
{%(py2)s = %(py0)s.interval_sec
} is %(py5)sr   r   r   r   >   r>   r?   r@   rA   r   z;%(py2)s
{%(py2)s = %(py0)s.progress_milestones
} == %(py5)sTr%   )r   r   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r   r1   r2   r3   r4   r5   s          r9   "test_progress_milestones_conditionz7TestTriggerCondition.test_progress_milestones_condition)   sk   $ 6
	 %%--%----%------y---y---%----------,,F0FF,0FFFFF,0FFFFFFFyFFFyFFF,FFF0FFFFFFFF))1T1)T1111)T111111y111y111)111T1111111r;   c                F   t        dddg      }|j                  }d}||k(  }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd	|iz  }t        t        j                  |            d
x}x}}|j                  }ddh}||k(  }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd	|iz  }t        t        j                  |            d
x}x}}y
)z1Test condition with both interval and milestones.rA   r?   )r   r.   r   r   r   r   r   r   NrD   )r   r   r&   r'   r(   r)   r*   r+   r,   r-   r.   rE   s          r9   test_combined_conditionz,TestTriggerCondition.test_combined_condition3   s    $!$c

	
 %%,,%,,,,%,,,,,,y,,,y,,,%,,,,,,,,,,,,:c
:,
::::,
::::::y:::y:::,:::
:::::::r;   c                   t        d      }|j                  }d} ||      }| }|sddt        j                         v st	        j
                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      t	        j                  |      dz  }t        t	        j                  |            dx}x}x}}|j                  }d} ||      }|sddt        j                         v st	        j
                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      t	        j                  |      dz  }t        t	        j                  |            dx}x}}|j                  }d	} ||      }|sddt        j                         v st	        j
                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      t	        j                  |      dz  }t        t	        j                  |            dx}x}}y)
z!Test time-based firing condition.r   r   rA   Vassert not %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.should_fire_time
}(%(py4)s)
}r   r   NzRassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.should_fire_time
}(%(py4)s)
}g      @)	r   should_fire_timer(   r)   r&   r*   r+   r,   r-   r0   r   r1   r3   r6   @py_assert7r5   r7   s           r9   test_should_fire_time_basedz0TestTriggerCondition.test_should_fire_time_based=   sk   $#6	 --2c2-c2222222222292229222-222c2222222222 )).#.)#........y...y...)...#.......... )).#.)#........y...y...)...#..........r;   c                   t        g d      }|j                  }d} ||      }| }|sddt        j                         v st	        j
                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      t	        j                  |      dz  }t        t	        j                  |            dx}x}x}}|j                  }d} ||      }|sd	dt        j                         v st	        j
                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      t	        j                  |      dz  }t        t	        j                  |            dx}x}}|j                  }d
} ||      }|sd	dt        j                         v st	        j
                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      t	        j                  |      dz  }t        t	        j                  |            dx}x}}|j                  d
       |j                  }d} ||      }| }|sddt        j                         v st	        j
                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      t	        j                  |      dz  }t        t	        j                  |            dx}x}x}}|j                  }d} ||      }|sd	dt        j                         v st	        j
                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      t	        j                  |      dz  }t        t	        j                  |            dx}x}}y)z%Test progress-based firing condition.r>   r?   r@   rB   皙?Zassert not %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.should_fire_progress
}(%(py4)s)
}r   r   Nr>   Vassert %(py6)s
{%(py6)s = %(py2)s
{%(py2)s = %(py0)s.should_fire_progress
}(%(py4)s)
}333333?g?r?   
r   should_fire_progressr(   r)   r&   r*   r+   r,   r-   mark_milestone_firedrL   s           r9   test_should_fire_progress_basedz4TestTriggerCondition.test_should_fire_progress_basedJ   si   $ 1
	
 116#61#66666666666966696661666#6666666666 --3d3-d33333333y333y333-333d3333333333 --2c2-c22222222y222y222-222c2222222222 	&&s+116#61#66666666666966696661666#6666666666 --2c2-c22222222y222y222-222c2222222222r;   c                   t        g d      }|j                  }d} ||      }|sddt        j                         v st	        j
                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      t	        j                  |      dz  }t        t	        j                  |            dx}x}}|j                  d       |j                  }d} ||      }| }|sddt        j                         v st	        j
                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      t	        j                  |      dz  }t        t	        j                  |            dx}x}x}}|j                  }d	} ||      }|sddt        j                         v st	        j
                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      t	        j                  |      dz  }t        t	        j                  |            dx}x}}y)
z!Test marking milestones as fired.rP   rB   r>   rS   r   r   NrR   r?   rU   )r0   r   r1   r3   r6   r7   rM   r5   s           r9   test_mark_milestone_firedz.TestTriggerCondition.test_mark_milestone_firedb   s|   $ 1
	 --3d3-d33333333y333y333-333d3333333333&&t, 117$71$77777777777977797771777$7777777777 --2c2-c22222222y222y222-222c2222222222r;   c                   t        g d      }|j                  d       |j                  d       |j                  }d} ||      }| }|sddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }t        t        j                  |            dx}x}x}}|j                  }d} ||      }| }|sddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }t        t        j                  |            dx}x}x}}|j                          |j                  }d} ||      }|sd	dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }t        t        j                  |            dx}x}}|j                  }d} ||      }|sd	dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }t        t        j                  |            dx}x}}y)
z+Test reset clears fired milestone tracking.rP   rB   r>   r?   rR   r   r   NrS   )r   rW   rV   r(   r)   r&   r*   r+   r,   r-   resetrL   s           r9   "test_reset_clears_fired_milestonesz7TestTriggerCondition.test_reset_clears_fired_milestonesq   s   $ 1
	 	&&t,&&s+117$71$77777777777977797771777$7777777777116#61#66666666666966696661666#6666666666 --3d3-d33333333y333y333-333d3333333333--2c2-c22222222y222y222-222c2222222222r;   c                   t        dd      }|j                  }d}||u }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd	|iz  }t        t        j                  |            d
x}x}}y
)zTest while_navigating flag.rA   F)r   r/   r#   r%   r   r   r   r   N)
r   r/   r&   r'   r(   r)   r*   r+   r,   r-   rE   s          r9   test_while_navigating_flagz/TestTriggerCondition.test_while_navigating_flag   s    $"
	
 ))2U2)U2222)U222222y222y222)222U2222222r;   N)__name__
__module____qualname____doc__r:   rF   rH   rN   rX   rZ   r]   r_    r;   r9   r   r      s-    &22;/3033$3r;   r   c                  @    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)TestPeriodicTriggerzTest PeriodicTrigger dataclass.c                  K   t        d      }g fd}t        d||d      }|j                  }d}||k(  }|st        j                  d|fd||f      d	t        j                         v st        j                  |      rt        j                  |      nd	t        j                  |      t        j                  |      d
z  }dd|iz  }t        t        j                  |            dx}x}}|j                  }||u }|st        j                  d|fd||f      d	t        j                         v st        j                  |      rt        j                  |      nd	t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }	dd|	iz  }
t        t        j                  |
            dx}}|j                  }||u }|st        j                  d|fd||f      d	t        j                         v st        j                  |      rt        j                  |      nd	t        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }	dd|	iz  }
t        t        j                  |
            dx}}|j                  }| }|sydd	t        j                         v st        j                  |      rt        j                  |      nd	t        j                  |      dz  }t        t        j                  |            dx}}yw)z!Test creating a periodic trigger.rA   r   c                 (     j                  d       y N   append
fire_counts   r9   on_firez:TestPeriodicTrigger.test_trigger_creation.<locals>.on_fire       a r;   	SCAN_AREAN	action_idr   ro   loggerr   )z1%(py2)s
{%(py2)s = %(py0)s.action_id
} == %(py5)striggerr   r   r   r#   )z1%(py2)s
{%(py2)s = %(py0)s.condition
} is %(py4)sr   )r   r   r   zassert %(py6)sr    )z/%(py2)s
{%(py2)s = %(py0)s.on_fire
} is %(py4)sro   0assert not %(py2)s
{%(py2)s = %(py0)s._running
}r   r   )r   r   rs   r&   r'   r(   r)   r*   r+   r,   r-   r   ro   _running)r0   r   ro   ru   r1   r2   r3   r4   r5   @py_format5r7   @py_format4rn   s               @r9   test_trigger_creationz)TestPeriodicTrigger.test_trigger_creation   s    $#6	
	! "!	
   /K/ K//// K//////w///w/// ///K///////  - I---- I------w---w--- ------I---I-------)'))))'))))))w)))w)))))))))')))')))))))############7###7##########s   MMc                  K   t        d      }g fd}t        d||d      }|j                          |j                  }d}||u}|st	        j
                  d|fd||f      d	t        j                         v st	        j                  |      rt	        j                  |      nd	t	        j                  |      t	        j                  |      d
z  }dd|iz  }t        t	        j                  |            dx}x}}t        j                  d       d{    |j                          t              }	d}
|	|
k\  }|st	        j
                  d|fd|	|
f      dt        j                         v st	        j                  t              rt	        j                  t              nddt        j                         v st	        j                        rt	        j                        ndt	        j                  |	      t	        j                  |
      dz  }dd|iz  }t        t	        j                  |            dx}	x}}
y7 &w)z%Test starting and stopping a trigger.皙?r   c                 (     j                  d       y ri   rk   rm   s   r9   ro   z<TestPeriodicTrigger.test_start_stop_trigger.<locals>.on_fire   rp   r;   TEST_ACTIONNrr   )is not)z4%(py2)s
{%(py2)s = %(py0)s._running
} is not %(py5)sru   r   r   r   rT   rj   >=z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} >= %(py6)slenrn   r   py1py3r    r!   r"   )r   r   startrx   r&   r'   r(   r)   r*   r+   r,   r-   asynciosleepstopr   )r0   r   ro   ru   r1   r2   r3   r4   r5   @py_assert2r6   r7   r8   rn   s                @r9   test_start_stop_triggerz+TestPeriodicTrigger.test_start_stop_trigger   s^    $#6	
	! "#	
 	+t+t++++t++++++w+++w++++++t+++++++ mmC   :#!#!####!######s###s######:###:######!####### 	!s   DH>H;D&H>c                  	K   t        g d      }g 		fd}t        d||d      }|j                          |j                  d       t	        j
                  d       d{    |j                  d	       t	        j
                  d       d{    |j                  d
       t	        j
                  d       d{    |j                          t        	      }d}||k\  }|st        j                  d|fd||f      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  	      rt        j                  	      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}y7 7 W7 ,w)z&Test trigger with progress milestones.r=   rB   c                 (     j                  d       y ri   rk   rm   s   r9   ro   zJTestPeriodicTrigger.test_trigger_with_progress_milestones.<locals>.on_fire   rp   r;   PROGRESS_TRIGGERNrr   r>   r}   r?   rA      r   r   r   rn   r   r!   r"   r   r   r   update_progressr   r   r   r   r&   r'   r(   r)   r*   r+   r,   r-   
r0   r   ro   ru   r   r6   r2   r7   r8   rn   s
            @r9   %test_trigger_with_progress_milestonesz9TestPeriodicTrigger.test_trigger_with_progress_milestones   sM    $ 6
	 
	! "(	
 	 	%mmC   $mmC   $mmC    :#!#!####!######s###s######:###:######!####### 	! 	! 	!s7   AG,!G#"-G,G&-G,=G)>D&G,&G,)G,c                  	K   t        d      }g 		fd}t        d||d      }|j                          t        j                  d       d{    t        	      }|j                          t        j                  d       d{    t        	      }||k(  }|s#t        j                  d|fd	||f      d
t        j                         v st        j                  t
              rt        j                  t
              nd
dt        j                         v st        j                  	      rt        j                  	      ndt        j                  |      dt        j                         v st        j                  |      rt        j                  |      nddz  }dd|iz  }t        t        j                  |            dx}}y7 x7 Cw)z*Test on_navigation_complete stops trigger.rQ   r   c                 (     j                  d       y ri   rk   rm   s   r9   ro   z@TestPeriodicTrigger.test_on_navigation_complete.<locals>.on_fire   rp   r;   NAV_TRIGGERNrr   r}   r   )z0%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} == %(py5)sr   rn   initial_count)r   r   r   r   r   r   )r   r   r   r   r   r   on_navigation_completer&   r'   r(   r)   r*   r+   r,   r-   )
r0   r   ro   ru   r   r   r2   r4   r5   rn   s
            @r9   test_on_navigation_completez/TestPeriodicTrigger.test_on_navigation_complete   s    $#6	
	! "#	
 	mmC   J&&( mmC   :/-////-//////s///s//////:///://///////-///-/////// 	! 	!s%   AGG7GG	E G	Gc                z  	K   t        ddg      }g 		fd}t        d||d      }|j                          |j                  d       t	        j
                  d	       d{    |j                  d
       t	        j
                  d	       d{    |j                          t        	      }d}||k\  }|st        j                  d|fd||f      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  	      rt        j                  	      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}y7 T7 )w)zTest update_progress method.r?   rA   rB   c                 (     j                  d       y ri   rk   rm   s   r9   ro   z9TestPeriodicTrigger.test_update_progress.<locals>.on_fire  rp   r;   r   Nrr   rT   333333?g333333?rj   r   r   r   rn   r   r!   r"   r   r   s
            @r9   test_update_progressz(TestPeriodicTrigger.test_update_progress   s)    $!$c

	 
	! "(	
 	$mmD!!!$mmD!!! :#!#!####!######s###s######:###:######!####### 	" 	"s%   AF;!F5"-F;F8D&F;8F;c                  	K   t        d      }g 		fd}t        d||d      }|j                          t        j                  d       d{    |j                          t        	      }d}||k\  }|st        j                  d	|fd
||f      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  	      rt        j                  	      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}y7 &w)z!Test trigger with async callback.rQ   r   c                 n   K    j                  d       t        j                  d       d {    y 7 w)Nrj   g{Gz?)rl   r   r   rm   s   r9   ro   zETestPeriodicTrigger.test_trigger_with_async_callback.<locals>.on_fire   s'     a --%%%s   *535ASYNC_TRIGGERNrr   rT   rj   r   r   r   rn   r   r!   r"   r   r   r   r   r   r   r   r&   r'   r(   r)   r*   r+   r,   r-   r   s
            @r9    test_trigger_with_async_callbackz4TestPeriodicTrigger.test_trigger_with_async_callback  s     $#6	
	& "%	
 	mmC   :#!#!####!######s###s######:###:######!####### 	!s   AE7E4D&E7c           	       
K   t        d      }t        d      }g 
g t        d|
fdd      }t        d|fd	d      }|j                          |j                          t        j                  d
       d{    |j                          |j                          t        
      }t              }||kD  }|st        j                  d|fd||f      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  
      rt        j                  
      ndt        j                  |      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                        rt        j                        ndt        j                  |      dz  }dd|iz  }	t        t        j                  |	            dx}x}}y7 ʭw)z)Test multiple triggers run independently.rQ   r   r}   	TRIGGER_1c                 &     j                  d      S ri   rk   )fire_count1s   r9   <lambda>zHTestPeriodicTrigger.test_multiple_triggers_independent.<locals>.<lambda><      K..q1 r;   Nrr   	TRIGGER_2c                 &     j                  d      S ri   rk   )fire_count2s   r9   r   zHTestPeriodicTrigger.test_multiple_triggers_independent.<locals>.<lambda>C  r   r;   gffffff?)>)zM%(py3)s
{%(py3)s = %(py0)s(%(py1)s)
} > %(py8)s
{%(py8)s = %(py5)s(%(py6)s)
}r   r   r   )r   r   r   r   r    r"   assert %(py10)spy10r   )r0   
condition1
condition2trigger1trigger2r   rM   r2   r8   @py_format11r   r   s             @@r9   "test_multiple_triggers_independentz6TestPeriodicTrigger.test_multiple_triggers_independent1  sj    %37
%37
"! 1	
 #! 1	
 	mmD!!! ;2#k"22"22222"2222222s222s222222;222;222222222#222#222222k222k222"22222222 	"s   A9I
=I>G
I
c                p  K   t        d      }t        d|d d      }|j                          |j                  }|j                          |j                  }||u }|st	        j
                  d|fd||f      d	t        j                         v st	        j                  |      rt	        j                  |      nd	d
t        j                         v st	        j                  |      rt	        j                  |      nd
dz  }dd|iz  }t        t	        j                  |            d}|j                          yw)z7Test multiple start calls don't create duplicate tasks.rA   r   TESTc                      y Nrd   rd   r;   r9   r   zGTestPeriodicTrigger.test_multiple_start_calls_ignored.<locals>.<lambda>X      r;   Nrr   r#   )z%(py0)s is %(py2)s
first_tasksecond_taskrw   zassert %(py4)sr   )r   r   r   _taskr&   r'   r(   r)   r*   r+   r,   r-   r   )r0   r   ru   r   r   r1   @py_format3ry   s           r9   !test_multiple_start_calls_ignoredz5TestPeriodicTrigger.test_multiple_start_calls_ignoredR  s     $#6	! 	
 	]]
mm[((((z[((((((z(((z(((((([((([(((((((s   D4D6N)r`   ra   rb   rc   r{   r   r   r   r   r   r   r   rd   r;   r9   rf   rf      s/    )$($0 $D02$<$,3Br;   rf   c                  (    e Zd ZdZd Zd Zd Zd Zy)$TestActionExecutorTriggerIntegrationz1Test integration of triggers with ActionExecutor.c                  K   t               }t        d      }t        d|d d      }|j                  |       |j                  }t        |      }d}||k(  }|s
t        j                  d|fd	||f      d
t        j                         v st        j                  t
              rt        j                  t
              nd
dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }dd|iz  }	t        t        j                  |	            dx}x}x}}yw)z"Test adding a trigger to executor.rA   r   r   c                      y r   rd   rd   r;   r9   r   zGTestActionExecutorTriggerIntegration.test_add_trigger.<locals>.<lambda>v  r   r;   Nrr   rj   r   zO%(py5)s
{%(py5)s = %(py0)s(%(py3)s
{%(py3)s = %(py1)s._triggers
})
} == %(py8)sr   executorr   r   r   r   r"   r   r   )r	   r   r   add_trigger	_triggersr   r&   r'   r(   r)   r*   r+   r,   r-   )
r0   r   r   ru   r   r2   rM   @py_assert6r8   r   s
             r9   test_add_triggerz5TestActionExecutorTriggerIntegration.test_add_triggern  s     !#$#6	! 	
 	W%%%+s%&+!+&!++++&!++++++s+++s++++++8+++8+++%+++&+++!+++++++s   E,E.c                  K   t               }t        d      }t        d|d d      }t        d|d d      }|j                  |       |j                  |       |j                  }t        |      }d	}||k(  }|s
t        j                  d
|fd||f      dt        j                         v st        j                  t
              rt        j                  t
              nddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }	dd|	iz  }
t        t        j                  |
            dx}x}x}}|j                          |j                  }t        |      }d}||k(  }|s
t        j                  d
|fd||f      dt        j                         v st        j                  t
              rt        j                  t
              nddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }	dd|	iz  }
t        t        j                  |
            dx}x}x}}yw)zTest clearing all triggers.rA   r   TEST1c                      y r   rd   rd   r;   r9   r   zJTestActionExecutorTriggerIntegration.test_clear_triggers.<locals>.<lambda>  r   r;   Nrr   TEST2c                      y r   rd   rd   r;   r9   r   zJTestActionExecutorTriggerIntegration.test_clear_triggers.<locals>.<lambda>  r   r;   r   r   r   r   r   r   r   r   r   )r	   r   r   r   r   r   r&   r'   r(   r)   r*   r+   r,   r-   clear_triggers)r0   r   r   r   r   r   r2   rM   r   r8   r   s              r9   test_clear_triggersz8TestActionExecutorTriggerIntegration.test_clear_triggers}  s    !#$#6	" 	
 # 	
 	X&X&%%+s%&+!+&!++++&!++++++s+++s++++++8+++8+++%+++&+++!+++++++!%%+s%&+!+&!++++&!++++++s+++s++++++8+++8+++%+++&+++!+++++++s   KKc                  K   t               }g fd}t        d      }t        d||d      }|j                  |       |j                  }t        |      }d}||k(  }|s
t        j                  d|fd	||f      d
t        j                         v st        j                  t
              rt        j                  t
              nd
dt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }	dd|	iz  }
t        t        j                  |
            dx}x}x}}|j                          d{    |j                  }|syddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }t        t        j                  |            d}t!        j"                  d       d{    |j%                          d{    |j                  }| }|syddt        j                         v st        j                  |      rt        j                  |      ndt        j                  |      dz  }t        t        j                  |            dx}}t              }d}||k\  }|st        j                  d|fd||f      d
t        j                         v st        j                  t
              rt        j                  t
              nd
dt        j                         v st        j                        rt        j                        ndt        j                  |      t        j                  |      dz  }dd|iz  }	t        t        j                  |	            dx}x}}y7 b7 7 w)z-Test triggers start and stop with navigation.c                 (     j                  d       y ri   rk   rm   s   r9   ro   z`TestActionExecutorTriggerIntegration.test_triggers_start_stop_during_navigation.<locals>.on_fire  rp   r;   rQ   r   NAV_SCANNrr   rj   r   r   r   r   r   r   r   z,assert %(py2)s
{%(py2)s = %(py0)s._running
}ru   rw   r   rv   r   r   rn   r   r!   r"   )r	   r   r   r   r   r   r&   r'   r(   r)   r*   r+   r,   r-   _start_triggersrx   r   r   _stop_triggers)r0   r   ro   r   ru   r   r2   rM   r   r8   r   r1   r   r3   rz   r6   r7   rn   s                    @r9   *test_triggers_start_stop_during_navigationzOTestActionExecutorTriggerIntegration.test_triggers_start_stop_during_navigation  se    !#
	! %#6	! 	
 	W% %%+s%&+!+&!++++&!++++++s+++s++++++8+++8+++%+++&+++!+++++++ &&(((wwmmD!!!%%'''############7###7########## :#!#!####!######s###s######:###:######!####### 	) 	"'s8   FO2O)B%O2-O,.O2O/F$O2,O2/O2c                `  	K   t               }t        ddg      }g 	t        d|	fdd      }|j                  |       |j	                          |j                  d       d{    t        j                  d       d{    |j                          t        	      }d	}||k\  }|st        j                  d
|fd||f      dt        j                         v st        j                  t              rt        j                  t              nddt        j                         v st        j                  	      rt        j                  	      ndt        j                  |      t        j                  |      dz  }dd|iz  }t!        t        j"                  |            dx}x}}y7 C7 )w)z,Test progress updates propagate to triggers.r?   rA   rB   r   c                 &     j                  d      S ri   rk   rm   s   r9   r   zSTestActionExecutorTriggerIntegration.test_update_trigger_progress.<locals>.<lambda>  s    J--a0 r;   Nrr   r   rj   r   r   r   rn   r   r!   r"   )r	   r   r   r   r   _update_trigger_progressr   r   r   r   r&   r'   r(   r)   r*   r+   r,   r-   )
r0   r   r   ru   r   r6   r2   r7   r8   rn   s
            @r9   test_update_trigger_progresszATestActionExecutorTriggerIntegration.test_update_trigger_progress  s    !#$!$c

	 
!(0	
 	W% //444mmD!!! :#!#!####!######s###s######:###:######!####### 	5!s%   A"F.%F(&F.F+D&F.+F.N)r`   ra   rb   rc   r   r   r   r   rd   r;   r9   r   r   j  s    ;,,2$B$r;   r   c                  "    e Zd ZdZd Zd Zd Zy)TestTriggerEdgeCasesz#Test edge cases and error handling.c                   t               }|j                  }d}||u }|st        j                  d|fd||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      dz  }dd|iz  }t        t        j                  |            dx}x}}|j                  }t               }||k(  }|st        j                  d|fd	||f      dt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      d
t	        j
                         v st        j                  t              rt        j                  t              nd
t        j                  |      dz  }dd|iz  }	t        t        j                  |	            dx}x}}|j                  }d} ||      }| }
|
sddt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }t        t        j                  |            dx}x}x}}
|j                  }d} ||      }| }
|
sddt	        j
                         v st        j                  |      rt        j                  |      ndt        j                  |      t        j                  |      t        j                  |      dz  }t        t        j                  |            dx}x}x}}
y)z4Test condition with neither interval nor milestones.Nr#   rC   r   r   r   r   r   r   r   r   r!   r"   g      Y@rJ   rA   rR   )r   r   r&   r'   r(   r)   r*   r+   r,   r-   r.   r   rK   rV   )r0   r   r1   r2   r3   r4   r5   r6   r7   r8   rM   s              r9   test_condition_with_no_criteriaz4TestTriggerEdgeCases.test_condition_with_no_criteria  s   $&	%%--%----%------y---y---%----------,,55,5555,555555y555y555,5555555555555555555 --4e4-e4444444444494449444-444e4444444444116#61#66666666666966696661666#6666666666r;   c                   t        d      }t        d|d d      }|j                  d       |j                  }d}||k(  }|st	        j
                  d	|fd
||f      dt        j                         v st	        j                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      dz  }dd|iz  }t        t	        j                  |            dx}x}}|j                  d       |j                  }d}||k(  }|st	        j
                  d	|fd
||f      dt        j                         v st	        j                  |      rt	        j                  |      ndt	        j                  |      t	        j                  |      dz  }dd|iz  }t        t	        j                  |            dx}x}}y)z,Test progress values are clamped to 0.0-1.0.rA   r   r   c                      y r   rd   rd   r;   r9   r   z=TestTriggerEdgeCases.test_progress_clamping.<locals>.<lambda>  r   r;   Nrr   g      g        r   )z9%(py2)s
{%(py2)s = %(py0)s._current_progress
} == %(py5)sru   r   r   r   g      ?)r   r   r   _current_progressr&   r'   r(   r)   r*   r+   r,   r-   )r0   r   ru   r1   r2   r3   r4   r5   s           r9   test_progress_clampingz+TestTriggerEdgeCases.test_progress_clamping  s&   $#6	! 	
 	%((/C/(C////(C//////w///w///(///C/////// 	$((/C/(C////(C//////w///w///(///C///////r;   c                |    t        d      }t        d|d d      }|j                          |j                          y)z/Test stopping a trigger that was never started.rA   r   r   c                      y r   rd   rd   r;   r9   r   zCTestTriggerEdgeCases.test_stop_without_start_safe.<locals>.<lambda>  r   r;   Nrr   )r   r   r   r   )r0   r   ru   s      r9   test_stop_without_start_safez1TestTriggerEdgeCases.test_stop_without_start_safe  s9    $#6	! 	
 	&&(r;   N)r`   ra   rb   rc   r   r   r   rd   r;   r9   r   r     s    -	70$)r;   r   )rc   
__future__r   builtinsr(   _pytest.assertion.rewrite	assertionrewriter&   r   unittest.mockr   r   r   pytestexecutor.triggersr   r   executor.action_executorr	   r
   r   r   markrf   r   r   rd   r;   r9   <module>r      s    #    5 5  l3 l3h O O On f$ f$ f$\,) ,)r;   