
    g                     P    d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	 dgZ
d Zd
d	Zy)zSpying on real objects.    N   )when2RememberedProxyInvocation)Mock_Dummymock_registryspyc                     t        j                  |       st        j                  |       rdn| j                   G fddt              } |       }t        |d|       t        j                  |       |S )aV  Spy an object.

    Spying means that all functions will behave as before, so they will
    be side effects, but the interactions can be verified afterwards.

    Returns Dummy-like, almost empty object as proxy to `object`.

    The *returned* object must be injected and used by the code under test;
    after that all interactions can be verified as usual.
    T.i. the original object **will not be patched**, and has no further
    knowledge as before.

    E.g.::

        import time
        time = spy(time)
        # inject time
        do_work(..., time)
        verify(time).time()

    Nc                   .    e Zd ZW  rW  ZfdZ fdZy)spy.<locals>.Spyc                     t        |      S )Nr   )selfmethod_nametheMocks     C/var/www/openai/venv/lib/python3.12/site-packages/mockito/spying.py__getattr__zspy.<locals>.Spy.__getattr__?   s    ,WkBB    c                 N    d}r|j                   z  }d|dt        |       dS )NSpied<z id=>)__name__id)r   nameclass_s     r   __repr__zspy.<locals>.Spy.__repr__B   s)    D'#'D22r   N)r   
__module____qualname__	__class__r   r   )r   r   s   r   Spyr   ;   s    I	C	3r   r!   T)strictspec)inspectisclassismoduler    r   r   r	   register)objectr!   objr   r   s      @@r   r
   r
       sf    , v'"2"26":!!3f 3 %C3t&1G3(Jr   c                 @    t        | t              j                          y)a  Spy usage of given `fn`.

    Patches the module, class or object `fn` lives in, so that all
    interactions can be recorded; otherwise executes `fn` as before, so
    that all side effects happen as before.

    E.g.::

        import time
        spy2(time.time)
        do_work(...)  # nothing injected, uses global patched `time` module
        verify(time).time()

    Note that builtins often cannot be patched because they're read-only.


    N)r   EllipsisthenCallOriginalImplementation)fns    r   spy2r.   P   s    $ 
"h668r   )returnN)__doc__r$   mockitor   
invocationr   mockingr   r   r	   __all__r
   r.    r   r   <module>r6      s+   *    1 0 0'-`9r   