
    g-                     6   d dl Z d dlZd dlZd dlmZ ddlmZmZmZ ddl	m	Z	 dgZ
 ej                  dej                        Zd dlmZmZmZ eej$                  ej&                  f   Z G d	 d
e      Zd Z G d de      Z G d de      Z e       ZddefdZy)    N)deque   )
invocation	signatureutils)mock_registrymockerrisinstance)DequeListUnionc                       e Zd Zd Zy)_Dummyc                 0     | j                  d      |i |S )N__call__)__getattr__)selfargskwargss      D/var/www/openai/venv/lib/python3.12/site-packages/mockito/mocking.pyr   z_Dummy.__call__/   s    +t
+T<V<<    N)__name__
__module____qualname__r    r   r   r   r   +   s    =r   r   c                 >    t        j                  | |      } ||i |S N)r   RememberedInvocation)r	   method_namer   r   invocs        r   remembered_invocation_builderr!   3   s$    ++D+>E$!&!!r   c                   h    e Zd ZddZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd Zy)MockNc                     || _         || _        || _        g | _        t	               | _        i | _        i | _        i | _        y r   )	
mocked_objstrictspecinvocationsr   stubbed_invocations_original_methods_methods_to_unstub_signatures_store)r   r%   r&   r'   s       r   __init__zMock.__init__9   sA    $	13HM !#"$!#r   c                 :    | j                   j                  |       y r   )r(   append)r   r   s     r   rememberzMock.rememberE   s    
+r   c                 :    | j                   j                  |       y r   )r)   
appendleft)r   stubbed_invocations     r   finish_stubbingzMock.finish_stubbingH   s      ++,>?r   c                     g | _         y r   )r(   r   s    r   clear_invocationszMock.clear_invocationsK   s
    r   c                 :    | j                   j                  |d       S r   )r*   getr   r   s     r   get_original_methodzMock.get_original_methodN   s    %%))+t<<r   c                     | j                   y	 | j                   j                  |   dfS # t        t        f$ r t	        | j                   |d      dfcY S w xY w)aR  
        Looks up the original method on the `spec` object and returns it
        together with an indication of whether the method is found
        "directly" on the `spec` object.

        This is used to decide whether the method should be stored as an
        original_method and should therefore be replaced when unstubbing.
        N)NFTF)r'   __dict__AttributeErrorKeyErrorgetattrr:   s     r    _get_original_method_before_stubz%Mock._get_original_method_before_stubS   sa     99	@99%%k2D88) 	@ 499k48%??		@s   * (AAc                 2    t        | j                  ||       y r   )setattrr%   )r   r   
new_methods      r   
set_methodzMock.set_methodg   s    j9r   c                      fd}|_         |r*|j                  |_        ||_        	 |j                  |_        t        j                  |      r t        j                  | j                        }t        |t              rt        |      }n[t        |t              rt        |      }n?t        j                   j                        r t        j                  |      rt        |      } j                  |       y # t        $ r Y w xY w)Nc                  $    t        g| i |S r   )r!   )r   r   r   r   s     r   new_mocked_methodz.Mock.replace_method.<locals>.new_mocked_methodl   s%    0k4$(4,24 4r   )r   __doc____wrapped__r   r>   inspectismethodr   	newmethodr%   
isinstancestaticmethodclassmethodisclassrE   )r   r   original_methodrH   s   ``  r   replace_methodzMock.replace_methodj   s    	4 &1"(7(?(?%,;)/>/I/I!, O, %!4??! o|4 ,-> ?5 +,= >OODOO,0 ,-> ?%67% " s   C; ;	DDc                     	 | j                   |    y # t        $ rY | j                  |      \  }}|r|| j                   |<   nd | j                   |<   || j                  |<   | j	                  ||       Y y w xY wr   )r+   r?   rA   r*   rS   )r   r   rR   was_in_specs       r   stubz	Mock.stub   s    	>##K0 	> 55kB 8G''47;''42AD"";/_=	>s    AA43A4c                    | j                   v sJ t        | j                         dk(  r t        j                  | j                         y | j                   j                         t        fd| j                   D              sB| j                  j                  j                        }| j                  j                  |       y y )Nr   c              3   P   K   | ]  }|j                   j                   k(    y wr   )r   ).0invr   s     r   	<genexpr>z1Mock.forget_stubbed_invocation.<locals>.<genexpr>   s(      
/ OOz555/s   #&)r)   lenr   unstubr%   removeanyr+   popr   restore_method)r   r   rR   s    ` r   forget_stubbed_invocationzMock.forget_stubbed_invocation   s    T55555t''(A-  1  ''
3 
//
 
 #5599&&O 
 6 6H
r   c                 Z    |r| j                  ||       y t        | j                  |       y r   )rE   delattrr%   r   r   rR   s      r   ra   zMock.restore_method   s#     OOK9DOO[1r   c                     | j                   r<| j                   j                         \  }}| j                  ||       | j                   r<t               | _        g | _        y r   )r+   popitemra   r   r)   r(   re   s      r   r]   zMock.unstub   sS    %%+/+B+B+J+J+L(K_= %% $)7 r   c                 H    | j                   yt        | j                   |      S )NT)r'   hasattrr:   s     r   
has_methodzMock.has_method   s     99tyy+..r   c                     | j                   y 	 | j                  |   S # t        $ r4 t        j                  | j                   |      }|| j                  |<   |cY S w xY wr   )r'   r,   r?   r   get_signature)r   r   sigs      r   rl   zMock.get_signature   s_    99	))+66 	))$))[AC25D"";/J	s    :AAc                    	 | j                   |   }t        j                  |      xsJ t        j                  | j                        xr) t        |t               xr t        j                  |       S # t        $ r Y yw xY w)zKReturns if the method will have a prepended self/class arg on call
        F)r*   rK   rL   rQ   r%   rN   rO   r?   re   s      r   eat_selfzMock.eat_self   s{    	"44[AO   1 OODOO4 =&EE=#OOO<<  		s   A2 2	A>=A>)TN)r   r   r   r-   r0   r4   r7   r;   rA   rE   rS   rV   rb   ra   r]   rj   rl   ro   r   r   r   r#   r#   8   sQ    
$,@=
@(:8@>$I$2/	r   r#   c                       e Zd Zd Zy)_OMITTEDc                      y)NOMITTEDr   r6   s    r   __repr__z_OMITTED.__repr__   s    r   N)r   r   r   rt   r   r   r   rq   rq      s    r   rq   c                    t        |       t        u r| c}n	i xs | c}t        u rdnd G fddt              } |       }t	        |      |j                         D ]W  \  }}t        j                  |      r0 t        j                  |      t              j                  |       Kt        |||       Y t        j                  |       |S )a1  Create 'empty' objects ('Mocks').

    Will create an empty unconfigured object, that you can pass
    around. All interactions (method calls) will be recorded and can be
    verified using :func:`verify` et.al.

    A plain `mock()` will be not `strict`, and thus all methods regardless
    of the arguments will return ``None``.

    .. note:: Technically all attributes will return an internal interface.
        Because of that a simple ``if mock().foo:`` will surprisingly pass.

    If you set strict to ``True``: ``mock(strict=True)`` all unexpected
    interactions will raise an error instead.

    You configure a mock using :func:`when`, :func:`when2` or :func:`expect`.
    You can also very conveniently just pass in a dict here::

        response = mock({'text': 'ok', 'raise_for_status': lambda: None})

    You can also create an empty Mock which is specced against a given
    `spec`: ``mock(requests.Response)``. These mock are by default strict,
    thus they raise if you want to stub a method, the spec does not implement.
    Mockito will also match the function signature.

    You can pre-configure a specced mock as well::

        response = mock({'json': lambda: {'status': 'Ok'}},
                        spec=requests.Response)

    Mocks are by default callable. Configure the callable behavior using
    `when`::

        dummy = mock()
        when(dummy).__call__(1).thenReturn(2)

    All other magic methods must be configured this way or they will raise an
    AttributeError.


    See :func:`verify` to verify your interactions after usage.

    FTc                   0    e Zd ZW  rW  ZfdZ fdZy)mock.<locals>.Dummyc                     r(t        j                  dt              }t        d|z        t        j                  t
        |      S )Nr
   z&'Dummy' has no attribute %r configured)operatormethodcallerr>   	functoolspartialr!   )r   r   __tracebackhide__r&   theMocks      r   r   zmock.<locals>.Dummy.__getattr__%  sQ    $,$9$9#^%! %<{JL L$$-wE Er   c                 N    d}r|j                   z  }d|dt        |       dS )NDummy<z id=>)r   id)r   namer'   s     r   rt   zmock.<locals>.Dummy.__repr__0  s)    D%#'D22r   N)r   r   r   	__class__r   rt   )r'   r&   r~   s   r   r   rw   !  s    I		E	3r   r   )r&   r'   )typedictrs   r   r#   itemsrK   
isfunctionr   StubbedInvocationEllipsis
thenAnswerrC   r   register)	config_or_specr'   r&   configr   objnvr~   s	    ``     @r   r	   r	      s    Z Nt#%t41>,D3 3 32 'C5d3G1a 4J((!4X>II!LE1a 	  3(Jr   )r{   rK   ry   collectionsr    r   r   r   r   __all__rz   InvocationErrorr}   typingr   r   r   r   RememberedProxyInvocationRealInvocationobjectr   r!   r#   rq   rs   r	   r   r   r   <module>r      s   *     * * (()H)) 
 & %##(()=V ="
i6 iXv 
 *4 Yr   