
    g'                     ^   d Z ddlmZmZ ddlZeZg dZ G d de      Z	 e	       Z
e
gxZZdZedixZZ G d	 d
e      Z G d d      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z G d% d&e      Z G d' d(e      Z  G d) d*e      Z! G d+ d,ee      Z"d<d-ZexZ#Z$d. Z%d/ Z&d0 Z'd1 Z(d2 Z)d3 Z*d4 Z+d5 Z,d6 Z-d7 Z.d8 Z/d=d9Z0d<d:Z1d; Z2y)>a6  Argument matchers for stubbing and verifications.

In general the call signature you specify when stubbing or verifying in mockito
is as concrete as possible: it consists of values only::

    when(os.path).exists('/foo/bar.txt').thenReturn(True)

This is for a reason. In controlled test environments, for the scope of a
single test, you should usually know exactly how you use a function, and what
you expect its outcome to be. In mockito usually (in `strict` mode) all
invocations you did not specify upfront will throw at call time.

If you reason about your code, the above `when` tirade turns - for the time
of the test - the specific stubbed function into a constant.

You can use so called argument matchers below if you can't or don't
want to specify a single concrete value for an argument, but a type or class of
possible values. E.g.::

    when(os.path).exists(...).thenReturn(True)
    when(os.path).exists(ANY).thenReturn(True)
    when(os.path).exists(ANY(str)).thenReturn(True)

    when(requests).get(ANY(str), **kwargs)
    when(requests).get('https://example.com', ...)

    when(math).sqrt(not_(_or(ANY(float), ANY(int)))).thenRaise(TypeError)

Now what you get each time is a function that up to a degree takes various
arguments and responds with the same outcome each time. Now that's a weird
thing. So use the matchers for a reason, they're powerful.

The one usage you should not care about is a loose signature when using
:func:`verify`. Since mockito will throw for unexpected calls, a very loose
`verify` should be ok::

    verify(requests, times=1).get(...)


    )ABCabstractmethodN)and_or_not_eqneqltltegtgteanyany_ANYarg_thatcontainsmatchescaptortimesargsARGSkwargsKWARGSc                       e Zd Zd Zy)_ArgsSentinelc                      y)Nz*args selfs    E/var/www/openai/venv/lib/python3.12/site-packages/mockito/matchers.py__repr__z_ArgsSentinel.__repr__S   s        N)__name__
__module____qualname__r!   r   r"   r    r   r   R   s    r"   r   z**_c                       e Zd ZdZy)MatcherErrorzFIndicates generic runtime error raised by mockito-python matchers
    N)r#   r$   r%   __doc__r   r"   r    r(   r(   p   s
    r"   r(   c                       e Zd Zd Zy)Matcherc                      y Nr   r   args     r    r   zMatcher.matchesw   s    r"   Nr#   r$   r%   r   r   r"   r    r+   r+   v   s    r"   r+   c                       e Zd Zed        Zy)	Capturingc                      y r-   r   r   values     r    capture_valuezCapturing.capture_value{   s    r"   N)r#   r$   r%   r   r6   r   r"   r    r2   r2   z   s     r"   r2   c                        e Zd ZddZd Zd Zy)AnyNc                     || _         y r-   wanted_type)r   r;   s     r    __init__zAny.__init__   s
    &r"   c                 H    | j                   rt        || j                         S yNT)r;   
isinstancer.   s     r    r   zAny.matches   s!    c4#3#344r"   c                      d| j                   z  S )Nz	<Any: %s>r:   r   s    r    r!   zAny.__repr__   s    T----r"   r-   r#   r$   r%   r<   r   r!   r   r"   r    r8   r8      s    '.r"   r8   c                       e Zd Zd Zd Zy)ValueMatcherc                     || _         y r-   r5   r4   s     r    r<   zValueMatcher.__init__   s	    
r"   c                 P    d| j                   j                  d| j                  dS )N<z: >)	__class__r#   r5   r   s    r    r!   zValueMatcher.__repr__   s    !^^44djjAAr"   N)r#   r$   r%   r<   r!   r   r"   r    rC   rC      s    Br"   rC   c                       e Zd Zd Zy)Eqc                      || j                   k(  S r-   rE   r.   s     r    r   z
Eq.matches       djj  r"   Nr0   r   r"   r    rK   rK          !r"   rK   c                       e Zd Zd Zy)Neqc                      || j                   k7  S r-   rE   r.   s     r    r   zNeq.matches   rM   r"   Nr0   r   r"   r    rP   rP      rN   r"   rP   c                       e Zd Zd Zy)Ltc                      || j                   k  S r-   rE   r.   s     r    r   z
Lt.matches       TZZr"   Nr0   r   r"   r    rS   rS           r"   rS   c                       e Zd Zd Zy)Ltec                      || j                   k  S r-   rE   r.   s     r    r   zLte.matches   rM   r"   Nr0   r   r"   r    rX   rX      rN   r"   rX   c                       e Zd Zd Zy)Gtc                      || j                   kD  S r-   rE   r.   s     r    r   z
Gt.matches   rU   r"   Nr0   r   r"   r    r[   r[      rV   r"   r[   c                       e Zd Zd Zy)Gtec                      || j                   k\  S r-   rE   r.   s     r    r   zGte.matches   rM   r"   Nr0   r   r"   r    r^   r^      rN   r"   r^   c                       e Zd Zd Zd Zd Zy)Andc                 n    |D cg c]  }t        |t              r|n
t        |      ! c}| _        y c c}w r-   r?   r+   rK   matchersr   rd   matchers      r    r<   zAnd.__init__   :     $%# "'73GGD#% %   $2c                 @    t        fd| j                  D              S )Nc              3   @   K   | ]  }|j                          y wr-   )r   ).0rf   r/   s     r    	<genexpr>zAnd.matches.<locals>.<genexpr>   s     E}G7??3'}s   )allrd   r.   s    `r    r   zAnd.matches   s    Et}}EEEr"   c                      d| j                   z  S )Nz	<And: %s>rd   r   s    r    r!   zAnd.__repr__   s    T]]**r"   NrA   r   r"   r    ra   ra      s    %
F+r"   ra   c                       e Zd Zd Zd Zd Zy)Orc                 n    |D cg c]  }t        |t              r|n
t        |      ! c}| _        y c c}w r-   rc   re   s      r    r<   zOr.__init__   rg   rh   c                 p    t        | j                  D cg c]  }|j                  |       c}      S c c}w r-   )builtin_anyrd   r   )r   r/   rf   s      r    r   z
Or.matches   s,    NWGOOC0NOONs   3c                      d| j                   z  S )Nz<Or: %s>ro   r   s    r    r!   zOr.__repr__   s    DMM))r"   NrA   r   r"   r    rq   rq      s    %
P*r"   rq   c                       e Zd Zd Zd Zd Zy)Notc                 T    t        |t              r|| _        y t        |      | _        y r-   )r?   r+   rK   rf   r   rf   s     r    r<   zNot.__init__   s    ",Wg">wBwKr"   c                 :    | j                   j                  |       S r-   rf   r   r.   s     r    r   zNot.matches   s    <<'',,,r"   c                      d| j                   z  S )Nz	<Not: %s>rf   r   s    r    r!   zNot.__repr__   s    T\\))r"   NrA   r   r"   r    rw   rw      s    P-*r"   rw   c                       e Zd Zd Zd Zd Zy)ArgThatc                     || _         y r-   	predicate)r   r   s     r    r<   zArgThat.__init__   s	    "r"   c                 $    | j                  |      S r-   r   r.   s     r    r   zArgThat.matches   s    ~~c""r"   c                      y)Nz	<ArgThat>r   r   s    r    r!   zArgThat.__repr__   s    r"   NrA   r   r"   r    r   r      s    ##r"   r   c                       e Zd Zd Zd Zd Zy)Containsc                     || _         y r-   sub)r   r   s     r    r<   zContains.__init__   s	    r"   c                     t        |d      sy | j                  xr8 t        | j                        dkD  xr |j                  | j                        dkD  S )Nfindr   )hasattrr   lenr   r.   s     r    r   zContains.matches   sB    sF#xxICMA-I#((4882Dr2IIr"   c                      d| j                   z  S )Nz<Contains: '%s'>r   r   s    r    r!   zContains.__repr__   s    !DHH,,r"   NrA   r   r"   r    r   r      s    J
-r"   r   c                        e Zd ZddZd Zd Zy)Matchesc                 :    t        j                  ||      | _        y r-   )recompileregex)r   r   flagss      r    r<   zMatches.__init__   s    ZZu-
r"   c                 ^    t        |t              sy | j                  j                  |      d uS r-   )r?   strr   matchr.   s     r    r   zMatches.matches   s)    #s#zz$D00r"   c                     | j                   j                  r/d| j                   j                  | j                   j                  fz  S d| j                   j                  z  S )Nz<Matches: %s flags=%d>z<Matches: %s>)r   r   patternr   s    r    r!   zMatches.__repr__   sT    ::+tzz/A/A/3zz/?/?/A A A #TZZ%7%777r"   Nr   rA   r   r"   r    r   r      s    .1
8r"   r   c                   6    e Zd ZddZd Zed        Zd Zd Zy)ArgumentCaptorNc                 8    |xs
 t               | _        g | _        y r-   )r8   rf   
all_valuesry   s     r    r<   zArgumentCaptor.__init__  s    '#%r"   c                 @    | j                   j                  |      }|sy yr>   r{   )r   r/   results      r    r   zArgumentCaptor.matches  s    %%c*r"   c                 N    | j                   st        d      | j                   d   S )NzNo argument value was captured!r   )r   r(   r   s    r    r5   zArgumentCaptor.value  s$    @AAr""r"   c                 :    | j                   j                  |       y r-   )r   appendr4   s     r    r6   zArgumentCaptor.capture_value  s    u%r"   c                 N    dt        | j                        d| j                  dS )Nz<ArgumentCaptor: matcher=z values=rH   )reprrf   r   r   s    r    r!   zArgumentCaptor.__repr__  s    
 	
r"   r-   )	r#   r$   r%   r<   r   propertyr5   r6   r!   r   r"   r    r   r     s*     # #
&
r"   r   c                     t        |       S )zMatches against type of argument (`isinstance`).

    If you want to match *any* type, use either `ANY` or `ANY()`.

    Examples::

        when(mock).foo(any).thenReturn(1)
        verify(mock).foo(any(int))

    )r8   r:   s    r    r   r     s     {r"   c                     t        |       S )zMatches particular value (`==`))rK   rE   s    r    r   r   -      e9r"   c                     t        |       S )z"Matches any but given value (`!=`))rP   rE   s    r    r	   r	   2      u:r"   c                     t        |       S )z5Matches any value that is less than given value (`<`))rS   rE   s    r    r
   r
   7  r   r"   c                     t        |       S )zBMatches any value that is less than or equal to given value (`<=`))rX   rE   s    r    r   r   <  r   r"   c                     t        |       S )z8Matches any value that is greater than given value (`>`))r[   rE   s    r    r   r   A  r   r"   c                     t        |       S )zEMatches any value that is greater than or equal to given value (`>=`))r^   rE   s    r    r   r   F  r   r"   c                      t        |       S )zqMatches if all given matchers match

    Example::

        when(mock).foo(and_(ANY(str), contains('foo')))

    )ra   ro   s    r    r   r   K  s     x=r"   c                      t        |       S )zjMatches if any given matcher match

    Example::

        when(mock).foo(or_(ANY(int), ANY(float)))

    )rq   ro   s    r    r   r   V  s     h<r"   c                     t        |       S )zyMatches if given matcher does not match

    Example::

        when(mock).foo(not_(ANY(str))).thenRaise(TypeError)

    )rw   r}   s    r    r   r   a  s     w<r"   c                     t        |       S )zMatches any argument for which predicate returns True

    Example::

        verify(mock).foo(arg_that(lambda arg: arg > 3 and arg < 7))

    )r   r   s    r    r   r   l  s     9r"   c                     t        |       S )zMatches any string containing given substring

    Example::

        mock.foo([120, 121, 122, 123])
        verify(mock).foo(contains(123))

    )r   r   s    r    r   r   w  s     C=r"   c                     t        | |      S )z+Matches any string that matches given regex)r   )r   r   s     r    r   r     s    5%  r"   c                     t        |       S )a  Returns argument captor that captures values for further assertions

    Example::

        arg = captor()
        mock.do_something(123)
        mock.do_something(456)
        verify(mock).do_something(arg)
        assert arg.value == 456
        assert arg.all_values == [123, 456]

    You can restrict what the captor captures using the other matchers
    shown herein::

        arg = captor(any(str))
        arg = captor(contains("foo"))

    )r   r}   s    r    r   r     s    & '""r"   c                     | S r-   r   )counts    r    r   r     s    Lr"   r-   r   )3r)   abcr   r   r   r   rt   __all__objectr   ARGS_SENTINELr   r   KWARGS_SENTINELr   r   RuntimeErrorr(   r+   r2   r8   rC   rK   rP   rS   rX   r[   r^   ra   rq   rw   r   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r"   r    <module>r      s  *'R $ 	 F 
 o t "C( (	< 	  .' .B7 B! !
!, !
   
!, !
   
!, !

+' 
+
* 
**' *g 
-w 
-8g 8"
Wi 
4  d





	!
#,r"   