
    iw^                         S r SSKJr  SSKrSSKJr  SSKJrJrJ	r	J
r
JrJr  SSKJrJr   " S S\5      r " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)zUnit tests for kgb.ops.    )unicode_literalsN)UnexpectedCallError)SpyOpMatchAnySpyOpMatchInOrder
SpyOpRaiseSpyOpRaiseInOrderSpyOpReturnSpyOpReturnInOrder)	MathClassTestCasec                   T    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rSrg)SpyOpMatchAnyTests   z%Unit tests for kgb.ops.SpyOpMatchAny.c                     [        5       nU R                  R                  UR                  [	        SSS.S S./5      S9  U R                  UR                  SSS9S5        g)	z9Testing SpyOpMatchAny set up with op=SpyOpMatchAny([...])      abc                 
    X-
  $ N r   s     Q/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/kgb/tests/test_ops.py<lambda>=SpyOpMatchAnyTests.test_setup_with_instance.<locals>.<lambda>        ae    kwargs	call_fakeopN)r   agencyspy_ondo_mathr   assertEqualselfobjs     r   test_setup_with_instance+SpyOpMatchAnyTests.test_setup_with_instance   sj    kKK  "4  	 
	 	qA.3r   c                 Z   [        5       nU R                  R                  UR                  [	        SSS.[        SSSS.[        S5      S.SSSS.[        S5      S./5      S./5      S9  U R                  UR                  SSSS9S5        U R                  UR                  SSSS9S5        g	)
z@Testing SpyOpMatchAny set up with op=SpyOpMatchAny([...]) and opr   r   r   r   r   x{   r   r"     r!   Nr   r$   r%   r&   r   r   r	   r'   r(   s     r   test_setup_with_instance_and_op2SpyOpMatchAnyTests.test_setup_with_instance_and_op&   s    kKK  , &'%&%&'
 #.c"2 &'%&%&'
 #.c"2-   	 	: 	qA3S9qA3S9r   c                     S nU R                   R                  U[        SS/S S./5      S9  U R                  U" SS5      S5        g)	z#Testing SpyOpMatchAny with functionc                 
    X-   $ r   r   r   s     r   r&   6SpyOpMatchAnyTests.test_with_function.<locals>.do_mathL   	    5Lr         c                 
    X-
  $ r   r   r   s     r   r   7SpyOpMatchAnyTests.test_with_function.<locals>.<lambda>T   r   r   argsr    r!   r   N)r$   r%   r   r'   r)   r&   s     r   test_with_function%SpyOpMatchAnyTests.test_with_functionJ   sW    	 	F!3  	 	 	A*r   c                    SS jnU R                   R                  U[        SS/[        SS/SS0[	        S5      S.SS/SS0[	        S	5      S./5      S
./5      S9  U R                  U" SSSS9S5        U R                  U" SSSS9S	5        g)z*Testing SpyOpMatchAny with function and opc                 
    X-   $ r   r   r.   s      r   r&   =SpyOpMatchAnyTests.test_with_function_and_op.<locals>.do_math\   r9   r   r:   r;   r/   r   r0   )r?   r   r"   r   r2   r?   r"   r!   r.   N)r   )r$   r%   r   r   r	   r'   r@   s     r   test_with_function_and_op,SpyOpMatchAnyTests.test_with_function_and_opZ   s    	 	F+%&F #Q' #.c"2 &'F #Q' #.c"2-   	 	0 	1Q/51Q/5r   c           	          U R                   R                  [        R                  [        [	        SSS.S S./5      S9  U R                  [        R                  " SSS9S5        g)	z&Testing SpyOpMatchAny with classmethodr:   r;   r   c                 
    X-
  $ r   r   r   s     r   r   :SpyOpMatchAnyTests.test_with_classmethod.<locals>.<lambda>   r   r   r   ownerr"   r   N)r$   r%   r   class_do_mathr   r'   r)   s    r   test_with_classmethod(SpyOpMatchAnyTests.test_with_classmethodz   sh    ##  "4  	 	 	001:A>r   c                 l   U R                   R                  [        R                  [        [	        SSS.[        SSSS.[        S5      S.SSSS.[        S	5      S./5      S./5      S
9  U R                  [        R                  " SSSS9S5        U R                  [        R                  " SSSS9S	5        g)z-Testing SpyOpMatchAny with classmethod and opr:   r;   r   r   r.   r0   r1   r   r2   rL   N)r$   r%   r   rN   r   r   r	   r'   rO   s    r   test_with_classmethod_and_op/SpyOpMatchAnyTests.test_with_classmethod_and_op   s    ##  , &'%&%&'
 #.c"2 &'%&%&'
 #.c"2-   	 	< 	001Q?E001Q?Er   c           
          U R                   R                  [        R                  [        [	        SSSS.0/5      S9  [        5       nU R                  UR                  SSS9S5        g)z)Testing SpyOpMatchAny with unbound methodr      r;   r   rL      N)r$   r%   r   r&   r   r'   r(   s     r   test_with_unbound_method+SpyOpMatchAnyTests.test_with_unbound_method   sk      	 
	 kqA.2r   c                 l   U R                   R                  [        R                  [        [	        SSS.[        SSSS.[        S5      S.SSSS.[        S	5      S./5      S./5      S
9  [        5       nU R                  UR                  SSSS9S5        U R                  UR                  SSSS9S	5        g)z0Testing SpyOpMatchAny with unbound method and oprV   r;   r   r   r.   r0   r1   r   r2   rL   N)r$   r%   r   r&   r   r   r	   r'   r(   s     r   test_with_unbound_method_and_op2SpyOpMatchAnyTests.test_with_unbound_method_and_op   s      , &'%&%&'
 #.c"2 &'%&%&'
 #.c"2-   	 	< kqA3S9qA3S9r   c                    [        5       nU R                  R                  UR                  [	        SSSS.0SSS.SS.S	S
S.[        S	S
SS.[        S5      S.S	S
SS.[        S5      S./5      S.SSS.S S.SS S./5      S9  UR                  SSS9UR                  SSS9UR                  S	S
SS9UR                  S	S
SS9UR                  SSS9UR                  SS5      /nU R                  U/ SQ5        g)z-Testing SpyOpMatchAny with all expected callsr   rV   rW   r   r      Fr   call_originald      r   r.   r0   r1   r2   r:   	   c                     X-   S-   $ N
   r   r   s     r   r   =SpyOpMatchAnyTests.test_with_expected_calls.<locals>.<lambda>  
    aebjr   r   c                     gN  r   r   s     r   r   rg         dr   )r   r    r!   r   )   Nr0   r2   rk      Nr3   r)   r*   valuess      r   test_with_expected_calls+SpyOpMatchAnyTests.test_with_expected_calls   sa   kKK  &+ !  , &)%(%&'
 #.c"2 &)%(%&'
 #.c"2- 4  "9 !2[1 1 	 3	l KKQKKK!qK!KK#K*KK#K*KK!qK!KK1
 	!?@r   c           	      *   [        5       nU R                  R                  UR                  [	        SSSS.0/5      S9  [
        R                  " S5      nU R                  [        U5         UR                  SSS9  SSS5        g! , (       d  f       g= f)	z*Testing SpyOpMatchAny with unexpected callr   rV   rW   r   r!   z3do_math was not called with any expected arguments.rc   N)	r   r$   r%   r&   r   reescapeassertRaisesRegexAssertionErrorr)   r*   expected_messages      r   test_with_unexpected_call,SpyOpMatchAnyTests.test_with_unexpected_call'  s    kKK  	 		 99A
 ##N4DEKK!qK! FEE   *B
Br   N)__name__
__module____qualname____firstlineno____doc__r+   r4   rA   rG   rP   rS   rX   r[   rr   r{   __static_attributes__r   r   r   r   r      s?    /4$":H+ 6@?"!FF3"":HBAH"r   r   c                   Z    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rSrg)SpyOpMatchInOrderTestsi>  z)Unit tests for kgb.ops.SpyOpMatchInOrder.c           	          [        5       nU R                  R                  UR                  [	        SSSS.0/5      S9  U R                  UR                  SSS9S5        g)zATesting SpyOpMatchInOrder set up with op=SpyOpMatchInOrder([...])r   r   r   r   r!   r;   N)r   r$   r%   r&   r   r'   r(   s     r   r+   /SpyOpMatchInOrderTests.test_setup_with_instanceA  sf    kKK "  	 		 	qA.2r   c           	          [        5       nU R                  R                  UR                  [	        SSS.[        S5      S./5      S9  U R                  UR                  SSS9S5        g)zITesting SpyOpMatchInOrder set up with op=SpyOpMatchInOrder([...])
and op
r   r   r   r0   r1   r!   Nr   r$   r%   r&   r   r	   r'   r(   s     r   r4   6SpyOpMatchInOrderTests.test_setup_with_instance_and_opR  sq     kKK   &c*"  	 
	 	qA.4r   c                     S nU R                   R                  U[        SS/S S./5      S9  U R                  U" SS5      S5        g)	z'Testing SpyOpMatchInOrder with functionc                 
    X-   $ r   r   r   s     r   r&   :SpyOpMatchInOrderTests.test_with_function.<locals>.do_mathh  r9   r   r:   r;   c                 
    X-
  $ r   r   r   s     r   r   ;SpyOpMatchInOrderTests.test_with_function.<locals>.<lambda>p  r   r   r>   r!   r   N)r$   r%   r   r'   r@   s     r   rA   )SpyOpMatchInOrderTests.test_with_functionf  sW    	 	 F!3"  	 	 	A*r   c           	          S nU R                   R                  U[        SS/[        S5      S./5      S9  U R	                  U" SS5      S5        g)z.Testing SpyOpMatchInOrder with function and opc                 
    X-   $ r   r   r   s     r   r&   ASpyOpMatchInOrderTests.test_with_function_and_op.<locals>.do_mathx  r9   r   r:   r;   r0   rF   r!   N)r$   r%   r   r	   r'   r@   s     r   rG   0SpyOpMatchInOrderTests.test_with_function_and_opv  s\    	 	 F%c*"  	 	 	A,r   c           	          U R                   R                  [        R                  [        [	        SSS.S S./5      S9  U R                  [        R                  " SSS9S5        g)	z*Testing SpyOpMatchInOrder with classmethodr:   r;   r   c                 
    X-
  $ r   r   r   s     r   r   >SpyOpMatchInOrderTests.test_with_classmethod.<locals>.<lambda>  r   r   r   rL   r   N)r$   r%   r   rN   r   r'   rO   s    r   rP   ,SpyOpMatchInOrderTests.test_with_classmethod  sh    ##   "4"  	 	 	001:A>r   c           
          U R                   R                  [        R                  [        [	        SSS.[        S5      S./5      S9  U R                  [        R                  " SSS9S5        g)z1Testing SpyOpMatchInOrder with classmethod and opr:   r;   r   r0   r1   rL   N)r$   r%   r   rN   r   r	   r'   rO   s    r   rS   3SpyOpMatchInOrderTests.test_with_classmethod_and_op  sm    ##   &c*"  	 	 	001:C@r   c           
          U R                   R                  [        R                  [        [	        SSSS.0/5      S9  [        5       nU R                  UR                  SSS9S5        g)z-Testing SpyOpMatchInOrder with unbound methodr   rV   r;   r   rL   rW   N)r$   r%   r   r&   r   r'   r(   s     r   rX   /SpyOpMatchInOrderTests.test_with_unbound_method  sk     "  	 
	 kqA.2r   c           
          U R                   R                  [        R                  [        [	        SSS.[        S5      S./5      S9  [        5       nU R                  UR                  SSS9S5        g)z4Testing SpyOpMatchInOrder with unbound method and oprV   r;   r   r0   r1   rL   N)r$   r%   r   r&   r   r	   r'   r(   s     r   r[   6SpyOpMatchInOrderTests.test_with_unbound_method_and_op  st       &c*"  	 	 kqA.4r   c                    [        5       nU R                  R                  UR                  [	        SSSS.0SSS.SS.S	S
S.[        S5      S.SSS.S S.SS 0/5      S9  UR                  SS5      UR                  SSS9UR                  S	S
S9UR                  SSS9UR                  SSS9/nU R                  U/ SQ5        g)z1Testing SpyOpMatchInOrder with all expected callsr   rV   rW   r   r   r^   Fr_   ra   rb   r0   r1   r:   rc   c                     X-   S-   $ re   r   r   s     r   r   ASpyOpMatchInOrderTests.test_with_expected_calls.<locals>.<lambda>  rh   r   r   r    c                     grj   r   r   s     r   r   r     rl   r   r!   rm   r   )ro   Nr0   rn   rk   Nr   rp   s      r   rr   /SpyOpMatchInOrderTests.test_with_expected_calls  s	   kKK   &+ !  &c*  "9  !29"  	 !	H KK1KK!qK!KK#K%KKQKKK!qK!
 	!:;r   c           	      *   [        5       nU R                  R                  UR                  [	        SSSS.0/5      S9  [
        R                  " S5      nU R                  [        U5         UR                  SSS9  SSS5        g! , (       d  f       g= f)	z.Testing SpyOpMatchInOrder with unexpected callr   rV   rW   r   r!   z{This call to do_math was not passed args=(), kwargs={'a': 4, 'b': 7}.

It was called with:

args=()
kwargs={'a': 4, 'b': 9}rc   N)	r   r$   r%   r&   r   ru   rv   rw   rx   ry   s      r   r{   0SpyOpMatchInOrderTests.test_with_unexpected_call  s    kKK "  	 		 99&
 ##N4DEKK!qK! FEEr}   c           	      j   [        5       nU R                  R                  UR                  [	        SSSS.0/5      S9  U R                  UR                  SSS9S5        [        R                  " S5      nU R                  [        U5         UR                  SSS9  S	S	S	5        g	! , (       d  f       g	= f)
z4Testing SpyOpMatchInOrder with extra unexpected callr   rV   rW   r   r!   ro   zdo_math was called 2 time(s), but only 1 call(s) were expected. Latest call: <SpyCall(args=(), kwargs={'a': 4, 'b': 9}, returned=None, raised=None)>rc   N)
r   r$   r%   r&   r   r'   ru   rv   rw   r   ry   s      r   test_with_extra_call+SpyOpMatchInOrderTests.test_with_extra_call  s    kKK "  	 		 	qA.399+
 ##$79IJKK!qK! KJJs   
B$$
B2r   N)r~   r   r   r   r   r+   r4   rA   rG   rP   rS   rX   r[   rr   r{   r   r   r   r   r   r   r   >  s>    33"5(+ - ?"A"3$5&/<b"8"r   r   c                   *    \ rS rSrSrS rS rS rSrg)SpyOpRaiseTestsi5  z"Unit tests for kgb.ops.SpyOpRaise.c                     S nU R                   R                  U[        [        S5      5      S9  U R	                  [        S5         U" SS5        SSS5        g! , (       d  f       g= f)z Testing SpyOpRaise with functionc                 
    X-   $ r   r   r   s     r   r&   3SpyOpRaiseTests.test_with_function.<locals>.do_math:  r9   r   foor!   r:   r;   N)r$   r%   r   
ValueErrorrw   r@   s     r   rA   "SpyOpRaiseTests.test_with_function8  sW    	 	*U+, 	 	. ##J6AqM 766s   
A
A'c           	         U R                   R                  [        R                  [        [	        [        S5      5      S9  U R                  [
        S5         [        R                  " SS5        SSS5        g! , (       d  f       g= f)z#Testing SpyOpRaise with classmethodr   rL   r:   r;   N)r$   r%   r   rN   r   r   rw   rO   s    r   rP   %SpyOpRaiseTests.test_with_classmethodD  s`    ##*U+, 	 	.
 ##J6##Aq) 766s   A77
Bc           	         U R                   R                  [        R                  [        [	        [        S5      5      S9  [        5       nU R                  [
        S5         UR                  SSS9  SSS5        g! , (       d  f       g= f)z&Testing SpyOpRaise with unbound methodr   rL   rV   r;   r   N)r$   r%   r   r&   r   r   rw   r(   s     r   rX   (SpyOpRaiseTests.test_with_unbound_methodN  sg    *U+, 	 	.
 k##J6KK!qK! 766s    A::
Br   N	r~   r   r   r   r   rA   rP   rX   r   r   r   r   r   r   5  s    ,
*
"r   r   c                   *    \ rS rSrSrS rS rS rSrg)SpyOpRaiseInOrderTestsi[  z)Unit tests for kgb.ops.SpyOpRaiseInOrder.c           
         S nU R                   R                  U[        [        S5      [	        S5      [        S5      /5      S9  U R                  [        S5         U" SS5        SSS5        U R                  [        S5         U" SS5        SSS5        U R                  [
        S5         U" SS5        SSS5        [        R                  " S	5      nU R                  [        U5         U" SS5        SSS5        g! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       No= f! , (       d  f       g= f)
z'Testing SpyOpRaiseInOrder with functionc                 
    X-   $ r   r   r   s     r   r&   :SpyOpRaiseInOrderTests.test_with_function.<locals>.do_math`  r9   r   r   barfoobarr!   r:   r;   Ndo_math was called 4 time(s), but only 3 call(s) were expected. Latest call: <SpyCall(args=(5, 3), kwargs={}, returned=None, raised=None)>)
r$   r%   r   r   KeyErrorAttributeErrorrw   ru   rv   r   r)   r&   messages      r   rA   )SpyOpRaiseInOrderTests.test_with_function^  s   	 	 5!x("  	 	 ##J6AqM 7 ##He4AqM 5 ##NH=AqM > ))
 ##$7AAqM BA 76 54 >= BAs0   
C<
D+
D)
D/<
D

D
D,/
D=c                    U R                   R                  [        R                  [        [	        [        S5      [        S5      [        S5      /5      S9  U R                  [
        S5         [        R                  " SS5        SSS5        U R                  [        S5         [        R                  " SS5        SSS5        U R                  [        S5         [        R                  " SS5        SSS5        [        R                  " S5      nU R                  [        U5         [        R                  " SS5        SSS5        g! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       N}= f! , (       d  f       g= f)	z*Testing SpyOpRaiseInOrder with classmethodr   r   r   rL   r:   r;   Nclass_do_math was called 4 time(s), but only 3 call(s) were expected. Latest call: <SpyCall(args=(), kwargs={'a': 5, 'b': 3}, returned=None, raised=None)>)r$   r%   r   rN   r   r   r   r   rw   ru   rv   r   r)   r   s     r   rP   ,SpyOpRaiseInOrderTests.test_with_classmethod}  s$   ## 5!x("  	 	 ##J6##Aq) 7 ##He4##Aq) 5 ##NH=##Aq) > ))4
 ##$7A##Aq) BA 76 54 >= BAs0   +E!EE&#E7
E
E#&
E47
Fc                    U R                   R                  [        R                  [        [	        [        S5      [        S5      [        S5      /5      S9  [        5       nU R                  [
        S5         UR                  SSS9  SSS5        U R                  [        S5         UR                  SSS9  SSS5        U R                  [        S5         UR                  SSS9  SSS5        [        R                  " S	5      nU R                  [        U5         UR                  S
S5        SSS5        g! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       Nx= f! , (       d  f       g= f)z-Testing SpyOpRaiseInOrder with unbound methodr   r   r   rL   rV   r;   r   Nzdo_math was called 4 time(s), but only 3 call(s) were expected. Latest call: <SpyCall(args=(), kwargs={'a': 5, 'b': 3}, returned=None, raised=None)>r:   )r$   r%   r   r&   r   r   r   r   rw   ru   rv   r   r)   r*   r   s      r   rX   /SpyOpRaiseInOrderTests.test_with_unbound_method  s)    5!x("  	 	 k##J6KK!qK! 7 ##He4KK!qK! 5 ##NH=KK!qK! > ))+
 ##$7AKK1 BA 76 54 >= BAs0   5D4$EEE'4
E
E
E$'
E5r   Nr   r   r   r   r   r   [  s    3>*:r   r   c                   *    \ rS rSrSrS rS rS rSrg)SpyOpReturnTestsi  z#Unit tests for kgb.ops.SpyOpReturn.c                     S nU R                   R                  U[        S5      S9  U R                  U" SS5      S5        g)z!Testing SpyOpReturn with functionc                 
    X-   $ r   r   r   s     r   r&   4SpyOpReturnTests.test_with_function.<locals>.do_math  r9   r   abc123r!   r:   r;   N)r$   r%   r	   r'   r@   s     r   rA   #SpyOpReturnTests.test_with_function  sC    	 	8$ 	 	& 	A1r   c                     U R                   R                  [        R                  [        [	        S5      S9  U R                  [        R                  " SS5      S5        g)z$Testing SpyOpReturn with classmethodr   rL   r:   r;   N)r$   r%   r   rN   r	   r'   rO   s    r   rP   &SpyOpReturnTests.test_with_classmethod  sL    ##8$ 	 	&
 	00A6Ar   c                     U R                   R                  [        R                  [        [	        S5      S9  [        5       nU R                  UR                  SSS9S5        g)z'Testing SpyOpReturn with unbound methodr   rL   rV   r;   r   N)r$   r%   r   r&   r	   r'   r(   s     r   rX   )SpyOpReturnTests.test_with_unbound_method  sS    8$ 	 	&
 kqA.9r   r   Nr   r   r   r   r   r     s    -	2B	:r   r   c                   *    \ rS rSrSrS rS rS rSrg)SpyOpReturnInOrderTestsi  z*Unit tests for kgb.ops.SpyOpReturnInOrder.c                    S nU R                   R                  U[        / SQ5      S9  U R                  U" SS5      S5        U R                  U" SS5      S5        U R                  U" SS5      S5        [        R
                  " S	5      nU R                  [        U5         U" SS5        S
S
S
5        g
! , (       d  f       g
= f)z(Testing SpyOpReturnInOrder with functionc                 
    X-   $ r   r   r   s     r   r&   ;SpyOpReturnInOrderTests.test_with_function.<locals>.do_math  r9   r   r   def456ghi789r!   r:   r;   r   r   r   r   N)r$   r%   r
   r'   ru   rv   rw   r   r   s      r   rA   *SpyOpReturnInOrderTests.test_with_function  s    	 	! #  	 	 	A1A1A1))
 ##$7AAqM BAAs    
B33
Cc                    U R                   R                  [        R                  [        [	        / SQ5      S9  U R                  [        R                  " SS5      S5        U R                  [        R                  " SS5      S5        U R                  [        R                  " SS5      S5        [        R                  " S5      nU R                  [        U5         [        R                  " SS5        S	S	S	5        g	! , (       d  f       g	= f)
z+Testing SpyOpReturnInOrder with classmethodr   rL   r:   r;   r   r   r   r   N)
r$   r%   r   rN   r
   r'   ru   rv   rw   r   r   s     r   rP   -SpyOpReturnInOrderTests.test_with_classmethod  s    ##! #  	 	 	00A6A00A6A00A6A))4
 ##$7A##Aq) BAAs   C;;
D	c                    U R                   R                  [        R                  [        [	        / SQ5      S9  [        5       nU R                  UR                  SSS9S5        U R                  UR                  SSS9S5        U R                  UR                  SSS9S5        [        R                  " S	5      nU R                  [        U5         UR                  SSS9  S
S
S
5        g
! , (       d  f       g
= f)z.Testing SpyOpReturnInOrder with unbound methodr   rL   rV   r;   r   r   r   r   zdo_math was called 4 time(s), but only 3 call(s) were expected. Latest call: <SpyCall(args=(), kwargs={'a': 4, 'b': 3}, returned=None, raised=None)>N)
r$   r%   r   r&   r
   r'   ru   rv   rw   r   r   s      r   rX   0SpyOpReturnInOrderTests.test_with_unbound_method  s    ! #  	 	 kqA.9qA.9qA.9))4
 ##$7AKK!qK! BAAs   C))
C7r   Nr   r   r   r   r   r     s    44*0"r   r   )r   
__future__r   ru   
kgb.errorsr   kgb.opsr   r   r   r   r	   r
   kgb.tests.baser   r   r   r   r   r   r   r   r   r   r   <module>r      su     ' 	 *) ) /j" j"Z	t"X t"n#"h #"L\X \~ :x  :FM"h M"r   