+
    QiQ                     l    R t ^ RIHt ^ RIHt ^ RIHtHtHtH	t	 ^RI
HtHt ^RI
Ht  ! R R]4      tR# )	z,
Tests for the public interface of Automat.
)reduce)TestCase)ArgSpec_getArgNames_getArgSpec_filterArgs)MethodicalMachineNoTransition)_methodicalc                      a  ] tR t^t o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tRtV tR# )MethodicalTestsz!
Tests for L{MethodicalMachine}.
c                     ! R R\         4      pV! 4       pV P                  VP                  4       R.4       V P                  VP                  4       R.4       R# )z
L{MethodicalMachine} provides a way for you to declare a state machine
with inputs, outputs, and states as methods.  When you have declared an
input, an output, and a state, calling the input method in that state
will produce the specified output.
c                   b  a  ] tR t^t o ]! 4       t]P                  4       R 4       t]P                  4       R 4       t	]P                  4       R 4       t
]P                  RR7      R 4       t]P                  4       R 4       t]P                  ]]]	.R7       ]P                  ]]]
.R7       R	tV tR
# )7MethodicalTests.test_oneTransition.<locals>.Machinationc                    R# zan inputN selfs   &?/usr/lib/python3/dist-packages/automat/_test/test_methodical.pyanInput?MethodicalTests.test_oneTransition.<locals>.Machination.anInput           c                    R# )z	an outputan-output-valuer   r   s   &r   anOutput@MethodicalTests.test_oneTransition.<locals>.Machination.anOutput!   s     )r   c                    R# )zanother outputanother-output-valuer   r   s   &r   anotherOutputEMethodicalTests.test_oneTransition.<locals>.Machination.anotherOutput&   s     .r   Tinitialc                    R# za stateNr   r   s   &r   anState?MethodicalTests.test_oneTransition.<locals>.Machination.anState+   r   r   c                    R# )zanother stateNr   r   s   &r   anotherStateDMethodicalTests.test_oneTransition.<locals>.Machination.anotherState/   r   r   enteroutputsr   N)__name__
__module____qualname____firstlineno__r   machineinputr   outputr   r    stater&   r)   upon__static_attributes____classdictcell____classdict__s   @r   Machinationr      s     ')G]]_  ^^) ) ^^. . ]]4]( ) ]]_    LLxjLIg\M?SSr   r;   r   r   N)objectassertEqualr   )r   r;   ms   &  r   test_oneTransition"MethodicalTests.test_oneTransition   sM    	T& 	T8 M'8&9:'=&>?r   c                Z  a \        4       o ! V3R lR\        4      pV! 4       pV P                  \        4      ;_uu_ 4       pVP                   RRR4       V P                  R\        XP                  4      4       V P                  VP                  S4       R#   + '       g   i     LS; i)a  
L{MethodicalMachine} is an implementation detail.  If you attempt to
access it on an instance of your class, you will get an exception.
However, since tools may need to access it for the purposes of, for
example, visualization, you may access it on the class itself.
c                      < ] tR t^Ct Z tRtR# )@MethodicalTests.test_machineItselfIsPrivate.<locals>.Machinationr   N)r.   r/   r0   r1   r2   r7   )expectedMachines   r   r;   rC   C   s    %Gr   r;   Nz-MethodicalMachine is an implementation detail)	r   r<   assertRaisesAttributeErrorr2   assertInstr	exceptionassertIs)r   r;   machinationcmrD   s   &   @r   test_machineItselfIsPrivate+MethodicalTests.test_machineItselfIsPrivate:   s|     ,-	&& 	& "m~.." /;S=N	
 	k))?; /.s   BB*	c                    ! R R\         4      pV! 4       pVP                  4        V P                  VP                  ^4       V! 4       pV P	                  \
        4      ;_uu_ 4       pVP                   RRR4       V P                  VP                  ^ 4       V P                  R\        XP                  4      4       R#   + '       g   i     LS; i)aE  
One of the benefits of using a state machine is that your output method
implementations don't need to take invalid state transitions into
account - the methods simply won't be called.  This property would be
broken if client code called output methods directly, so output methods
are not directly visible under their names.
c                      a  ] tR t^Wt o ]! 4       t^ t]P                  4       R 4       t]P                  4       R 4       t
]P                  RR7      R 4       t]P                  ]]]
.R7       RtV tR# )	;MethodicalTests.test_outputsArePrivate.<locals>.Machinationc                    R# r   r   r   s   &r   r   CMethodicalTests.test_outputsArePrivate.<locals>.Machination.anInput[   r   r   c                8    V ;P                   ^,          un         R#    N)counterr   s   &r   r   DMethodicalTests.test_outputsArePrivate.<locals>.Machination.anOutput_   s    !r   Tr"   c                    R# )za machine stateNr   r   s   &r   r5   AMethodicalTests.test_outputsArePrivate.<locals>.Machination.statec   r   r   r+   r   N)r.   r/   r0   r1   r   r2   rW   r3   r   r4   r   r5   r6   r7   r8   r9   s   @r   r;   rQ   W   s}     ')GG]]_  ^^" " ]]4](" )" JJwehZJ@@r   r;   NzlMachination.anOutput is a state-machine output method; to produce this output, call an input method instead.)
r<   r   r=   rW   rE   rF   r   rG   rH   rI   )r   r;   mach1mach2rL   s   &    r   test_outputsArePrivate&MethodicalTests.test_outputsArePrivateN   s    	A& 	A$ *~.."NN /*A	
	 /.s   'B??C	c                     ! R R\         4      pV! 4       pV P                  VP                  4       R.4       V P                  VP                  4       R.4       R# )z_
Two machines may co-exist happily on the same instance; they don't
interfere with each other.
c                     a  ] tR t^}t o ]! 4       t]! 4       t]P                  4       R 4       t]P                  4       R 4       t	]P                  RR7      R 4       t]P                  RR7      R 4       t]P                  4       R 4       t]P                  4       R 4       t]P!                  ]]].4       ]P!                  ]	]].4       R	tV tR
# )8MethodicalTests.test_multipleMachines.<locals>.MultiMachc                    R# )zinput ANr   r   s   &r   inputA?MethodicalTests.test_multipleMachines.<locals>.MultiMach.inputA   r   r   c                    R# )zinput BNr   r   s   &r   inputB?MethodicalTests.test_multipleMachines.<locals>.MultiMach.inputB   r   r   Tr"   c                    R# )z	initial ANr   r   s   &r   initialAAMethodicalTests.test_multipleMachines.<locals>.MultiMach.initialA   r   r   c                    R# )z	initial BNr   r   s   &r   initialBAMethodicalTests.test_multipleMachines.<locals>.MultiMach.initialB   r   r   c                    R # Ar   r   s   &r   outputA@MethodicalTests.test_multipleMachines.<locals>.MultiMach.outputA       r   c                    R # Br   r   s   &r   outputB@MethodicalTests.test_multipleMachines.<locals>.MultiMach.outputB   rs   r   r   N)r.   r/   r0   r1   r   abr3   rc   rf   r5   ri   rl   r4   rq   rw   r6   r7   r8   r9   s   @r   	MultiMachra   }   s     !#A!#AWWY  WWY  WWTW" # WWTW" # XXZ  XXZ  MM&(WI6MM&(WI66r   r{   rp   rv   N)r<   r=   rc   rf   )r   r{   mms   &  r   test_multipleMachines%MethodicalTests.test_multipleMachinesw   sG    	7 	7> [se,se,r   c                   a ^ RI o ! V3R lR\        4      pV! 4       pV P                  VP                  4       R4       R# )zB
Outputs can be combined with the "collector" argument to "upon".
Nc                     <a  ] tR t^t o ]! 4       t]P                  4       R 4       t]P                  4       R 4       t]P                  4       R 4       t	]P                  RR7      R 4       t
]
P                  ]]
]]	.V3R lR7       R	tV tR
# )4MethodicalTests.test_collectOutputs.<locals>.Machinec                    R# r   r   r   s   &r   r3   :MethodicalTests.test_collectOutputs.<locals>.Machine.input   r   r   c                    R # ro   r   r   s   &r   rq   <MethodicalTests.test_collectOutputs.<locals>.Machine.outputA   rs   r   c                    R # ru   r   r   s   &r   rw   <MethodicalTests.test_collectOutputs.<locals>.Machine.outputB   rs   r   Tr"   c                    R# r%   r   r   s   &r   r5   :MethodicalTests.test_collectOutputs.<locals>.Machine.state   r   r   c                0   < \        SP                  V 4      # N)r   add)xoperators   &r   <lambda>=MethodicalTests.test_collectOutputs.<locals>.Machine.<lambda>   s    F8<<$;r   	collectorr   N)r.   r/   r0   r1   r   r>   r3   r4   rq   rw   r5   r6   r7   r8   )r:   r   s   @r   Machiner      s     !#AWWY  XXZ  XXZ  WWTW" # JJ'";	   r   r   AB)r   r<   r=   r3   )r   r   r>   r   s   &  @r   test_collectOutputs#MethodicalTests.test_collectOutputs   s3     		f 	4 ID)r   c                    ! R R\         4      pV! 4       pV P                  \        4      ;_uu_ 4       pVP                  RRR4       RRR4       V P	                  R\        XP                  4      4       R#   + '       g   i     L7; i)z.
Input methods preserve their declared names.
c                      a  ] tR t^t o ]! 4       t]P                  4       R 4       t]P                  RR7      R 4       t	Rt
V tR# )-MethodicalTests.test_methodName.<locals>.Mechc                    R# r   r   r   s   &r   declaredInputName?MethodicalTests.test_methodName.<locals>.Mech.declaredInputName   r   r   Tr"   c                    R# )r5   Nr   r   s   &r   aState4MethodicalTests.test_methodName.<locals>.Mech.aState   r   r   r   N)r.   r/   r0   r1   r   r>   r3   r   r5   r   r7   r8   r9   s   @r   Mechr      sD     !#AWWY  WWTW" #r   r   toomany	argumentsNr   )r<   rE   	TypeErrorr   rG   rH   rI   )r   r   r>   rL   s   &   r   test_methodNameMethodicalTests.test_methodName   sb    
		6 		 Fy))Rv{; *)3r||+<= *)s   A77B	c                     ! R R\         4      pV! 4       pV P                  VP                  ^4      ^.4       V P                  VP                  ^4       R# )zG
If an input takes an argument, it will pass that along to its output.
c                      a  ] tR t^t o ]! 4       t]P                  4       RR l4       t]P                  RR7      R 4       t]P                  4       RR l4       t]P                  ]]].4       Rt
V tR# )	:MethodicalTests.test_inputWithArguments.<locals>.Mechanismc                    R# r   r   r   r   ys   &&&r   r3   @MethodicalTests.test_inputWithArguments.<locals>.Mechanism.input   r   r   Tr"   c                    R# r%   r   r   s   &r   r5   @MethodicalTests.test_inputWithArguments.<locals>.Mechanism.state   r   r   c                    Wn         W,           # r   _xr   s   &&&r   r4   AMethodicalTests.test_inputWithArguments.<locals>.Mechanism.output   s    ur   r   NrV   )r.   r/   r0   r1   r   r>   r3   r5   r4   r6   r7   r8   r9   s   @r   	Mechanismr      su     !#AWWY  WWTW" # XXZ  JJuefX..r   r   N)r<   r=   r3   r   r   r   r>   s   &  r   test_inputWithArguments'MethodicalTests.test_inputWithArguments   sE    
	/ 	/$ KaS)q!r   c                    ! R R\         4      pV! 4       pV P                  VP                  ^4      . RO4       V P                  VP                  ^4       V P                  VP                  ^4       V P                  VP                  ^R7      . RO4       V P                  VP                  ^4       V P                  VP                  ^4       V P                  VP                  ^^4      . RO4       V P                  VP                  ^4       V P                  VP                  ^4       V P                  VP                  ^^R7      . R	O4       V P                  VP                  ^4       V P                  VP                  ^4       R# )
z0
Inputs pass arguments that output will accept.
c                   >  a  ] tR t^t o ]! 4       t]P                  4       R
R l4       t]P                  RR7      R 4       t]P                  4       R 4       t	]P                  4       R 4       t
]P                  4       R 4       t]P                  ]]]	]
].4       RtV tR	# )CMethodicalTests.test_outputWithSubsetOfArguments.<locals>.Mechanismc                    R# r   r   r   s   &&&r   r3   IMethodicalTests.test_outputWithSubsetOfArguments.<locals>.Mechanism.input   r   r   Tr"   c                    R# r%   r   r   s   &r   r5   IMethodicalTests.test_outputWithSubsetOfArguments.<locals>.Mechanism.state   r   r   c                    Wn         V# r   r   )r   r   s   &&r   outputXKMethodicalTests.test_outputWithSubsetOfArguments.<locals>.Mechanism.outputX      r   c                    Wn         V# r   )_y)r   r   s   &&r   outputYKMethodicalTests.test_outputWithSubsetOfArguments.<locals>.Mechanism.outputY  r   r   c                    R # r   r   r   s   &r   outputNoArgsPMethodicalTests.test_outputWithSubsetOfArguments.<locals>.Mechanism.outputNoArgs      r   )r   r   Nr   )r.   r/   r0   r1   r   r>   r3   r5   r4   r   r   r   r6   r7   r8   r9   s   @r   r   r      s     !#AWWY  WWTW" # XXZ  XXZ  XXZ  JJuegw%EFFr   r   Nr   )r   )   rV   N)   rV   N)   r   N)      N)r<   r=   r3   r   r   r   s   &  r    test_outputWithSubsetOfArguments0MethodicalTests.test_outputWithSubsetOfArguments   s)   
	G 	G6 K 	\2q!q! 	1|4q!q! 	A5q!q! 	a,7q!q!r   c                  a  \         P                  ! 4        \         P                  ! 4         ! V 3R lR\        4      p ! R R\        4      pV! 4       P	                  4         ! R R\        4      pV! 4       P	                  4         ! R R\        4      pV! 4       P	                  4         ! R	 R
\        4      pV! 4       P	                  4         ! R R\        4      pV! 4       P	                  4        R# )z5
The wrapped input function must have an empty body.
c                     <a  ] tR tRt o ]! 4       t ZP                  ]4      ;_uu_ 4       t]P                  4       R 4       t	RRR4        ZP                  ]! ]P                  4      R4       RtV tR#   + '       g   i     L9; i)AMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.Mechanismi3  c                    \        4        R# r   listr   s   &r   r3   GMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.Mechanism.input7  s	     Fr   Nzfunction body must be emptyr   )r.   r/   r0   r1   r   r>   rE   
ValueErrorrL   r3   r=   rH   rI   r7   r8   r:   r   s   @r   r   r   3  se     !#A"":.."  / S.0MNN /.s   A44B	r   c                      a  ] tR tRt o ]! 4       t]P                  4       R 4       t]P                  RR7      R 4       t]P                  ]]. R7       Rt
V tR# )	NMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismWithDocstringiA  c                    R# r   r   r   s   &r   r3   TMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismWithDocstring.inputD  r   r   Tr"   c                    R# zstarting stateNr   r   s   &r   startTMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismWithDocstring.startH  r   r   r+   r   Nr.   r/   r0   r1   r   r>   r3   r5   r   r6   r7   r8   r9   s   @r   MechanismWithDocstringr   A  s[     !#AWWY  WWTW"! #! JJuE2J66r   r   c                      a  ] tR tRt o ]! 4       t]P                  4       R 4       t]P                  RR7      R 4       t]P                  ]]. R7       Rt
V tR# )	IMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismWithPassiP  c                    R # r   r   r   s   &r   r3   OMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismWithPass.inputS  s    r   Tr"   c                    R# r   r   r   s   &r   r   OMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismWithPass.startW  r   r   r+   r   Nr   r9   s   @r   MechanismWithPassr   P  s[     !#AWWY  WWTW"! #! JJuE2J66r   r   c                      a  ] tR tRt o ]! 4       t]P                  4       R 4       t]P                  RR7      R 4       t]P                  ]]. R7       Rt
V tR# )	UMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismWithDocstringAndPassi_  c                    R# r   r   r   s   &r   r3   [MethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismWithDocstringAndPass.inputb  s     r   Tr"   c                    R# r   r   r   s   &r   r   [MethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismWithDocstringAndPass.startg  r   r   r+   r   Nr   r9   s   @r   MechanismWithDocstringAndPassr   _  s[     !#AWWY  WWTW"! #! JJuE2J66r   r   c                      a  ] tR tRt o ]! 4       t]P                  4       R 4       t]P                  RR7      R 4       t]P                  ]]. R7       Rt
V tR# )	LMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismReturnsNoneio  c                    R # r   r   r   s   &r   r3   RMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismReturnsNone.inputr  r   r   Tr"   c                    R# r   r   r   s   &r   r   RMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismReturnsNone.startv  r   r   r+   r   Nr   r9   s   @r   MechanismReturnsNoner   o  s[     !#AWWY  WWTW"! #! JJuE2J66r   r   c                      a  ] tR tRt o ]! 4       t]P                  4       R 4       t]P                  RR7      R 4       t]P                  ]]. R7       Rt
V tR# )	\MethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismWithDocstringAndReturnsNonei~  c                    R# r   r   r   s   &r   r3   bMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismWithDocstringAndReturnsNone.input  s     r   Tr"   c                    R# r   r   r   s   &r   r   bMethodicalTests.test_inputFunctionsMustBeEmpty.<locals>.MechanismWithDocstringAndReturnsNone.start  r   r   r+   r   Nr   r9   s   @r   $MechanismWithDocstringAndReturnsNoner   ~  s[     !#AWWY  WWTW"! #! JJuE2J66r   r  N)r
   _empty
_docstringr<   r3   )r   r   r   r   r   r   r  s   f      r   test_inputFunctionsMustBeEmpty.MethodicalTests.test_inputFunctionsMustBeEmpty)  s     	 		O 		O	7V 	7 	 &&(	7 	7 	!!#	7F 	7 	&'--/	76 	7 	$$&	76 	7 	-.446r   c                ,   a   ! V 3R lR\         4      pR# )z
All the argument lists of the outputs for a given input must match; if
one does not the call to C{upon} will raise a C{TypeError}.
c                     <a  ] tR tRt o ]! 4       t]P                  4       R 4       t]P                  4       R 4       t	]P                  4       R 4       t
]P                  4       R 4       t ZP                  ]4      ;_uu_ 4       t]P                  ]]]	]
.4       RRR4        ZP!                  R]! ]P$                  4      4        ZP!                  R]! ]P$                  4      4       R	tV tR#   + '       g   i     L\; i)
;MethodicalTests.test_inputOutputMismatch.<locals>.Mechanismi  c                    R# r   r   r   ry   s   &&r   nameOfInputGMethodicalTests.test_inputOutputMismatch.<locals>.Mechanism.nameOfInput  r   r   c                    R# )zan output that matchesNr   r  s   &&r   outputThatMatchesMMethodicalTests.test_inputOutputMismatch.<locals>.Mechanism.outputThatMatches  r   r   c                    R# )zan output that doesn't matchNr   )r   rz   s   &&r   outputThatDoesntMatchQMethodicalTests.test_inputOutputMismatch.<locals>.Mechanism.outputThatDoesntMatch  r   r   c                    R# r%   r   r   s   &r   r5   AMethodicalTests.test_inputOutputMismatch.<locals>.Mechanism.state  r   r   Nr  r  r   )r.   r/   r0   r1   r   r>   r3   r  r4   r  r  r5   rE   r   rL   r6   rG   rH   rI   r7   r8   r   s   @r   r   r	    s     !#AWWY  XXZ) ) XXZ/ / WWY  ""9--

):<Q(R . MM-R\\):;MM13r||3DEE .-s   C..C>	r   Nr<   r   r   s   f r   test_inputOutputMismatch(MethodicalTests.test_inputOutputMismatch  s    	F 	Fr   c                z     ! R R\         4      pV! 4       pVP                  4       w  pV P                  VR4       R# )z9
It is possible to write a self-loop by omitting "enter"
c                   6  a  ] tR tRt o ]! 4       t]P                  4       R 4       t]P                  4       R 4       t]P                  4       R 4       t	]P                  RR7      R 4       tR t]P                  ]. R	7       ]P                  ]]	.R	7       R
tV tR# )1MethodicalTests.test_stateLoop.<locals>.Mechanismi  c                    R# r   r   r   s   &r   r3   7MethodicalTests.test_stateLoop.<locals>.Mechanism.input  r   r   c                    R# r   r   r   s   &r   say_hi8MethodicalTests.test_stateLoop.<locals>.Mechanism.say_hi  r   r   c                    R # )hir   r   s   &r   _start_say_hi?MethodicalTests.test_stateLoop.<locals>.Mechanism._start_say_hi  r   r   Tr"   c                    R# r%   r   r   s   &r   r   7MethodicalTests.test_stateLoop.<locals>.Mechanism.start  r   r   c                    R# )za state with no inputsNr   r   s   &r   said_hi9MethodicalTests.test_stateLoop.<locals>.Mechanism.said_hi  r   r   )r-   r   N)r.   r/   r0   r1   r   r>   r3   r   r4   r$  r5   r   r)  r6   r7   r8   r9   s   @r   r   r    s     !#AWWY  WWY  XXZ  WWTW" #) JJubJ)JJvJ77r   r   r#  N)r<   r   r=   )r   r   a_mechanism
a_greetings   &   r   test_stateLoopMethodicalTests.test_stateLoop  s7    
	8 	82  k"))+T*r   c                N     ! R R\         4      pV! 4       P                  4        R# )z6
It is possible to write a transition with no outputs
c                      a  ] tR tRt o ]! 4       t]P                  4       R 4       t]P                  RR7      R 4       t	]P                  4       R 4       t
]	P                  ]]
R7       RtV tR	# )
6MethodicalTests.test_defaultOutputs.<locals>.Mechanismi  c                    R# )zfinal transitionNr   r   s   &r   finish=MethodicalTests.test_defaultOutputs.<locals>.Mechanism.finish  r   r   Tr"   c                    R# )za start stateNr   r   s   &r   r   <MethodicalTests.test_defaultOutputs.<locals>.Mechanism.start  r   r   c                    R# )za final stateNr   r   s   &r   finished?MethodicalTests.test_defaultOutputs.<locals>.Mechanism.finished  r   r   )r,   r   N)r.   r/   r0   r1   r   r>   r3   r3  r5   r   r8  r6   r7   r8   r9   s   @r   r   r1    ss     !#AWWY# # WWTW"  #  WWY    JJvXJ..r   r   N)r<   r3  r  s   & r   test_defaultOutputs#MethodicalTests.test_defaultOutputs  s    
	/ 	/" 	r   c                    \        RRRRRRR\        3R\        33R7      pV P                  \	        V4      RRR\        3R\        304       R# )z3
Type annotations should be included in the set of
ry   rz   N)argsvarargsvarkwdefaults
kwonlyargskwonlydefaultsannotations)ry   rz   r   )r   intrH   r=   r   )r   specs   & r   test_getArgNames MethodicalTests.test_getArgNames  s\     sc3Z0
 	#SzC:.	
r   c                z    \        R 4      p\        R 4      pRp\        V/ W4      w  rEV P                  W44       R# )zT
filterArgs() should not filter the `args` parameter
if outputSpec accepts `*args`.
c                      R # r   r   r=  kwargss   *,r   r   1MethodicalTests.test_filterArgs.<locals>.<lambda>  s    r   c                      R # r   r   rJ  s   *,r   r   rL     s    r   Nr   )r   r   rJ   )r   	inputSpec
outputSpecargsInargsOut_s   &     r   test_filterArgsMethodicalTests.test_filterArgs  s;    
   <=	 !=>
 YC
f&r   c                ,   a   ! V 3R lR\         4      pR# )z9
A L{MethodicalMachine} can only have one initial state.
c                     <a  ] tR tRt o ]! 4       t]P                  RR7      R 4       t ZP                  ]	4      ;_uu_ 4        ]P                  RR7      R 4       t
RRR4       RtV tR#   + '       g   i     RtT tR# ; i)CMethodicalTests.test_multipleInitialStatesFailure.<locals>.WillFaili
  Tr"   c                    R# )z&The first initial state -- this is OK.Nr   r   s   &r   firstInitialStateUMethodicalTests.test_multipleInitialStatesFailure.<locals>.WillFail.firstInitialState  r   r   c                    R# )z4The second initial state -- results in a ValueError.Nr   r   s   &r   secondInitialStateVMethodicalTests.test_multipleInitialStatesFailure.<locals>.WillFail.secondInitialState  r   r   Nr   )r.   r/   r0   r1   r   r>   r5   rY  rE   r   r\  r7   r8   r   s   @r   WillFailrW  
  sn     !#AWWTW"9 #9 "":..&K 'K /....s   A++B 	r^  Nr  r   r^  s   f r   !test_multipleInitialStatesFailure1MethodicalTests.test_multipleInitialStatesFailure  s    
	Kv 	Kr   c                ,   a   ! V 3R lR\         4      pR# )zK
A L{MethodicalMachine} can only have one transition per start/event
pair.
c                   ~  <a  ] tR tRt o ]! 4       t]P                  RR7      R 4       t]P                  4       R 4       t]P                  4       R 4       t
]P                  ]
]. R7        ZP                  ]4      ;_uu_ 4        ]P                  ]
]. R7       RRR4       R	tV tR#   + '       g   i     R	tT tR# ; i)
AMethodicalTests.test_multipleTransitionsFailure.<locals>.WillFaili  Tr"   c                    R# )zWe start here.Nr   r   s   &r   r   GMethodicalTests.test_multipleTransitionsFailure.<locals>.WillFail.start   r   r   c                    R# )zRainbows end.Nr   r   s   &r   endEMethodicalTests.test_multipleTransitionsFailure.<locals>.WillFail.end$  r   r   c                    R# )z	An event.Nr   r   s   &r   eventGMethodicalTests.test_multipleTransitionsFailure.<locals>.WillFail.event(  r   r   r+   Nr   )r.   r/   r0   r1   r   r>   r5   r   rh  r3   rk  r6   rE   r   r7   r8   r   s   @r   r^  rd    s     !#AWWTW"! #! WWY    WWY  JJuCJ4"":..

5R
8 /....s   B''B<	r^  Nr  r_  s   f r   test_multipleTransitionsFailure/MethodicalTests.test_multipleTransitionsFailure  s    	9v 	9r   c                    ! R R\         4      pV! 4       pV P                  \        4      ;_uu_ 4       pVP                  4        RRR4       V P	                  R\        XP                  4      4       V P	                  R\        VP                  4      4       VP                  4        V P                  \        4      ;_uu_ 4       pVP                  4        RRR4       V P	                  R\        VP                  4      4       V P	                  R\        VP                  4      4       R#   + '       g   i     L; i  + '       g   i     Lo; i)zy
Calling any input method that lacks a transition for the machine's
current state raises an informative L{NoTransition}.
c                     a  ] tR tRt o ]! 4       t]P                  RR7      R 4       t]P                  4       R 4       t]P                  4       R 4       t
]P                  4       R 4       t]P                  ]
]. 4       RtV tR	# )
FMethodicalTests.test_badTransitionForCurrentState.<locals>.OnlyOnePathi6  Tr"   c                    R# )zStart state.Nr   r   s   &r   r   LMethodicalTests.test_badTransitionForCurrentState.<locals>.OnlyOnePath.start9  r   r   c                    R# )z
End state.Nr   r   s   &r   rh  JMethodicalTests.test_badTransitionForCurrentState.<locals>.OnlyOnePath.end=  r   r   c                    R# )zMove from start to end.Nr   r   s   &r   advanceNMethodicalTests.test_badTransitionForCurrentState.<locals>.OnlyOnePath.advanceA  r   r   c                    R# )z%A transition from nowhere to nowhere.Nr   r   s   &r   deadEndNMethodicalTests.test_badTransitionForCurrentState.<locals>.OnlyOnePath.deadEndE  r   r   r   N)r.   r/   r0   r1   r   r>   r5   r   rh  r3   rw  rz  r6   r7   r8   r9   s   @r   OnlyOnePathrq  6  s     !#AWWTW" # WWY  WWY* * WWY8 8 JJwR((r   r|  Nrz  r   rh  )r<   rE   r	   rz  rG   rH   rI   rw  )r   r|  r2   rL   s   &   r   !test_badTransitionForCurrentState1MethodicalTests.test_badTransitionForCurrentState0  s    	)& 	)* -|,,OO -iR\\!23gs2<<01|,,OO -iR\\!23eS./ -,
 -,s   D)D<)D9	<E	c                v     ! R R\         4      pV P                  V! 4       P                  4       RRR^/4       R# )z
L{MethodicalMachine.serializer} is a decorator that modifies its
decoratee's signature to take a "state" object as its first argument,
which is the "serialized" argument to the L{MethodicalMachine.state}
decorator.
c                      a  ] tR tRt o ]! 4       tR t]P                  RRR7      R 4       t]P                  RR7      R	 4       t	]P                  4       R
 4       tRtV tR# )1MethodicalTests.test_saveState.<locals>.Mechanismi^  c                    ^V n         R# rU   valuer   s   &r   __init__:MethodicalTests.test_saveState.<locals>.Mechanism.__init__a  s	    
r   first-stateT
serializedr#   c                    R# zFirst state.Nr   r   s   &r   first7MethodicalTests.test_saveState.<locals>.Mechanism.firstd  r   r   second-stater  c                    R# zSecond state.Nr   r   s   &r   second8MethodicalTests.test_saveState.<locals>.Mechanism.secondh  r   r   c                "    R VRV P                   /# machine-state
some-valuer  r   r5   s   &&r   save6MethodicalTests.test_saveState.<locals>.Mechanism.savel       $U $** r   r  N)r.   r/   r0   r1   r   r>   r  r5   r  r  
serializerr  r7   r8   r9   s   @r   r   r  ^  sl     !#A WWtW< = WWW/  0  \\^ r   r   r  r  r  N)r<   r=   r  r  s   & r   test_saveStateMethodicalTests.test_saveStateV  s;    	 	* 	Ka	
r   c                T    ! R R\         4      pV! 4       pVP                  4        VP                  4       pVP                  V4      pV P	                  VP
                  R4       V P	                  VP                  4       ^4       V P	                  VP                  4       RRR^/4       R# )a  
L{MethodicalMachine.unserializer} decorates a function that becomes a
machine-state unserializer; its return value is mapped to the
C{serialized} parameter to C{state}, and the L{MethodicalMachine}
associated with that instance's state is updated to that state.
c                     a  ] tR tRt o ]! 4       tR t]P                  RRR7      R 4       t]P                  RR7      R	 4       t	]P                  4       R
 4       t
]P                  4       R 4       t]P                  4       R 4       t]P                  ]
]	].R R7       ]	P                  ]
]	].R R7       ]P                  4       R 4       t]P!                  4       R 4       t]R 4       tRtV tR# )4MethodicalTests.test_restoreState.<locals>.Mechanismi  c                "    ^V n         RV n        R# )rV   FNr  	ranOutputr   s   &r   r  =MethodicalTests.test_restoreState.<locals>.Mechanism.__init__  s    
!&r   r  Tr  c                    R# r  r   r   s   &r   r  :MethodicalTests.test_restoreState.<locals>.Mechanism.first  r   r   r  r  c                    R# r  r   r   s   &r   r  ;MethodicalTests.test_restoreState.<locals>.Mechanism.second  r   r   c                    R# r   r   r   s   &r   r3   :MethodicalTests.test_restoreState.<locals>.Mechanism.input  r   r   c                "    ^V n         RV n        ^# )r   Tr  r   s   &r   r4   ;MethodicalTests.test_restoreState.<locals>.Mechanism.output  s    
!%r   c                    ^# )r   r   r   s   &r   output2<MethodicalTests.test_restoreState.<locals>.Mechanism.output2  s    r   c                &    \        V 4      ^ ,          #     r   r   s   &r   r   =MethodicalTests.test_restoreState.<locals>.Mechanism.<lambda>  s    DGAJr   r   c                &    \        V 4      ^ ,          # r  r   r   s   &r   r   r    s    d1gajr   c                "    R VRV P                   /# r  r  r  s   &&r   r  9MethodicalTests.test_restoreState.<locals>.Mechanism.save  r  r   c                0    VR ,          V n         VR,          # )r  r  r  )r   blobs   &&r   _restore=MethodicalTests.test_restoreState.<locals>.Mechanism._restore  s    !,/
O,,r   c                6    V ! 4       pVP                  V4       V# r   )r  )clsr  r   s   && r   fromBlob=MethodicalTests.test_restoreState.<locals>.Mechanism.fromBlob  s    ud#r   )r  r  N)r.   r/   r0   r1   r   r>   r  r5   r  r  r3   r4   r  r6   r  r  unserializerr  classmethodr  r7   r8   r9   s   @r   r   r    s    !#A' WWtW< = WWW/  0  WWY  XXZ 
 XXZ  JJufvh:NJOKKvy<PKQ\\^  ^^- -  r   r   Fr  r  r  N)r<   r3   r  r  r=   r  )r   r   m1r  m2s   &    r   test_restoreState!MethodicalTests.test_restoreState{  s    0	 0	d [

wwy%u-Q'GGIa	
r   c                d     ! R R\         4      pV! 4       pVP                  ^4      ^.8X  g   Q hR# )zO
L{MethodicalMachine} can operate with type annotations on inputs and outputs.
c                      a  ] tR tRt o ]! 4       t]P                  4       V 3R lR l4       t]P                  4       V 3R lR l4       t	]P                  RR7      R 4       t
]
P                  ]]
]	.R	7       R
tV tR# )AMethodicalTests.test_allowBasicTypeAnnotations.<locals>.Mechanismi  c                    < V ^8  d   QhRS[ /# )r   argrD  )formatr:   s   "r   __annotate__NMethodicalTests.test_allowBasicTypeAnnotations.<locals>.Mechanism.__annotate__  s      C r   c                    R# )zAn inputNr   r   r  s   &&r   an_inputJMethodicalTests.test_allowBasicTypeAnnotations.<locals>.Mechanism.an_input  r   r   c                &   < V ^8  d   QhRS[ RS[ /# )r   r  returnr  )r  r:   s   "r   r  r    s      S S r   c                    V^,           # r   r   r  s   &&r   	an_outputKMethodicalTests.test_allowBasicTypeAnnotations.<locals>.Mechanism.an_output  s    Qwr   Tr"   c                    R# )zA stateNr   r   s   &r   r5   GMethodicalTests.test_allowBasicTypeAnnotations.<locals>.Mechanism.state  r   r   r+   r   N)r.   r/   r0   r1   r   r>   r3   r  r4   r  r5   r6   r7   r8   r9   s   @r   r   r    sw     !#AWWY  XXZ  WWTW" # JJxuykJBBr   r   N)r<   r  )r   r   	mechanisms   &  r   test_allowBasicTypeAnnotations.MethodicalTests.test_allowBasicTypeAnnotations  s4    
	C 	C" K	!!!$+++r   r   N)r.   r/   r0   r1   __doc__r?   rM   r]   r}   r   r   r   r   r  r  r-  r:  rF  rS  r`  rm  r}  r  r  r  r7   r8   r9   s   @r   r   r      s     &@P<('
R'-R!*F>*"64"lc7JF@ +D0
$	'K$92$0L#
JF
P, ,r   r   N)r  	functoolsr   unittestr   automat._methodicalr   r   r   r    r   r	   r
   r   r   r   r   <module>r     s,      O O . M,h M,r   