
    j`                        d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlm	Z	 d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d d	l
mZ d d
l
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dl
mZ d dlZddlmZ ddlmZ  ed          Zej        j         Z!eej        j"        ej        j         ej        j#        f         Z$ G d de%          Z&e G d d                      Z'e G d d                      Z( G d d          Z)ded ee)ddf         fd!Z*  ej+                    e*          Z,  ej+        d"#          e*          Z-  ej+        d$#          e*          Z.  ej+        d%#          e*          Z/  ej+        d&#          e*          Z0g Z1i Z2d'ed(ef         d)ed*ed dfd+Z3d'ed(ef         d)ed*ed dfd,Z4d)ed*ed dfd-Z5d)ed*ed dfd.Z6d)ed*ed dfd/Z7d)ed*ed dfd0Z8d)ed*ed dfd1Z9d)ed*ed dfd2Z:d)ed*ed dfd3Z;d)ed*ed dfd4Z<d)ed*ed dfd5Z=d)ed*ed dfd6Z>d)ed*ed dfd7Z?d)ed*ed dfd8Z@d)ed*ed dfd9ZAd)ed*ed dfd:ZBd;ed dfd<ZCdAd=ZDd>ed dfd?ZEd;ed dfd@ZFdS )B    N)	dataclass)field)Any)Callable)Dict)	Generator)Iterable)Iterator)List)Mapping)Optional)Tuple)Type)TypeVar)Union)cast)overload   )get_mock_module)parse_ini_boolean_Tc                       e Zd ZdZdS )PytestMockWarningz3Base class for all warnings emitted by pytest-mock.N)__name__
__module____qualname____doc__     \/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/pytest_mock/plugin.pyr   r   (   s        ====r   r   c                   4    e Zd ZU eed<   dZee         ed<   dS )MockCacheItemmockNpatch)r   r   r   MockType__annotations__r$   r   r   r   r   r    r"   r"   ,   s/         
NNNE8C=r   r"   c                       e Zd ZU dZ ee          Zee         e	d<   de
defdZde
dedefdZde
dd	fd
ZddZdee         fdZd	S )	MockCachezJ
    Cache MagicMock and Patcher instances so we can undo them later.
    )default_factorycacher#   returnc                 N    | j         D ]}|j        |u r|c S t          d          )Nz"This mock object is not registered)r*   r#   
ValueErrorselfr#   	mock_items      r    _findzMockCache._find:   s@     	! 	!I~%%     &=>>>r   kwargsc                 h    | j                             t          dd|i|           | j         d         S )Nr#   r   )r*   appendr"   )r/   r#   r2   s      r    addzMockCache.add@   s7    
-<<T<V<<===z"~r   Nc                     |                      |          }|j        r|j                                         | j                            |           d S N)r1   r$   stopr*   remover.   s      r    r:   zMockCache.removeD   sM    JJt$$	? 	#O  """
)$$$$$r   c                     t          | j                  D ]"}|j        |j                                         #| j                                         d S r8   )reversedr*   r$   r9   clear)r/   r0   s     r    r=   zMockCache.clearJ   sR    !$*-- 	' 	'I*$$&&&
r   c                 *    t          | j                  S r8   )iterr*   r/   s    r    __iter__zMockCache.__iter__P   s    DJr   r+   N)r   r   r   r   r   listr*   r   r"   r&   r%   r1   r   r6   r:   r=   r
   rA   r   r   r    r(   r(   2   s           "'t!<!<!<E4<<<?( ?} ? ? ? ? C M    %8 % % % % %    (=1            r   r(   c                      e Zd ZdZdeddfdZ	 ddeded	ed
edef
dZddddededdfdZ	ddZ
dej        j        ddfdZdededefdZddee         dej        j        fdZddee         defdZ G d d          ZdS )MockerFixturez
    Fixture that provides the same interface to functions in the mock module,
    ensuring that they are uninstalled at the end of each test.
    configr+   Nc                    t                      | _        t          |          x| _        }|                     | j        |          | _        |j        | _        |j        | _        |j        | _        |j	        | _	        |j
        | _
        t          |d          r|j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        t          |d          r|j        | _        d S d S )N	AsyncMockseal)r(   _mock_cacher   mock_module_Patcherr$   Mock	MagicMockNonCallableMockNonCallableMagicMockPropertyMockhasattrrH   callANYDEFAULTsentinel	mock_openrI   )r/   rF   rK   s      r    __init__zMockerFixture.__init__Z   s    &/kk)8)@)@@;]]4#3[AA
$	$.*:$/$D!'4;,, 	3(2DN$	?"*#,$.;'' 	)#(DIII	) 	)r   Fspecspec_setinstancer2   c                 d     | j         j        |||fi |}| j                            |           |S r8   )rK   create_autospecrJ   r6   )r/   rY   rZ   r[   r2   ms         r    r]   zMockerFixture.create_autospecn   sM     7d&6(H
 
(.
 
 	Qr   return_valueside_effectr`   ra   c                l   t          | d          r| j        | j        f}n| j        f}| j        D ]}t          |j        d          st          |j        d          rg |j        _        t          |j        |          r|j                            ||           k|j                                         dS )z
        Call reset_mock() on all patchers started by this fixture.

        :param bool return_value: Reset the return_value of mocks.
        :param bool side_effect: Reset the side_effect of mocks.
        rH   
reset_mockspy_return_listr_   N)rR   rM   rH   rJ   r#   rd   
isinstancerc   )r/   r`   ra   supports_reset_mock_with_argsr0   s        r    resetallzMockerFixture.resetallw   s     4%% 	9-1Y,G))-1YL)) 	, 	,I9><88 y~'899 413	.).*GHH ,))!-; *     ))++++	, 	,r   c                 8    | j                                          dS )zi
        Stop all patchers started by this fixture. Can be safely called multiple
        times.
        N)rJ   r=   r@   s    r    stopallzMockerFixture.stopall   s    
 	     r   r#   c                 :    | j                             |           dS )zp
        Stops a previous patch or spy call by passing the ``MagicMock`` object
        returned by it.
        N)rJ   r:   )r/   r#   s     r    r9   zMockerFixture.stop   s!    
 	%%%%%r   objnamec                 v   t          ||          fd}fd}t          j                  rt          j        |          }nt          j        |          }t          j                  pt          j                  }| j        	                    ||||          d_
        g _        d_        S )a  
        Create a spy of method. It will run method normally, but it is now
        possible to use `mock` call features with it, like call count.

        :param obj: An object.
        :param name: A method in object.
        :return: Spy object.
        c                      d _         d _        	  | i |}|_         j                            |           n# t          $ r}|_         d }~ww xY w|S r8   
spy_returnspy_exceptionrd   r5   BaseExceptionargsr2   remethodspy_objs       r    wrapperz"MockerFixture.spy.<locals>.wrapper   s    !%G$(G!2FD+F++
 &'"'..q1111 !   ()% Hs   ; 
AAAc                     K   d _         d _        	  | i | d {V }|_         j                            |           n# t          $ r}|_         d }~ww xY w|S r8   ro   rs   s       r    async_wrapperz(MockerFixture.spy.<locals>.async_wrapper   s      !%G$(G!2 &$1&11111111
 &'"'..q1111 !   ()% Hs   A 
AAA)ra   autospecN)getattrasyncioiscoroutinefunction	functoolsupdate_wrapperinspectismethod
isfunctionr$   objectrp   rd   rq   )	r/   rk   rl   ry   r{   wrappedr|   rw   rx   s	          @@r    spyzMockerFixture.spy   s     d##	 	 	 	 	 		 	 	 	 	 	 &v.. 	@.}fEEGG.w??G#F++Iw/A&/I/I*##C7X#VV!"$ $r   c                 v    t          t          j        j        | j                            d |                    S )z
        Create a stub method. It accepts any arguments. Ideal to register to
        callbacks in tests.

        :param name: the constructed stub's name as used in repr
        :return: Stub object.
        c                      d S r8   r   rt   r2   s     r    <lambda>z$MockerFixture.stub.<locals>.<lambda>       D r   rY   rl   )r   unittestr#   rN   rK   r/   rl   s     r    stubzMockerFixture.stub   s;     M#&&,H,Ht&TT
 
 	
r   c                 b    t          t          | j                            d |                    S )z
        Create a async stub method. It accepts any arguments. Ideal to register to
        callbacks in tests.

        :param name: the constructed stub's name as used in repr
        :return: Stub object.
        c                      d S r8   r   r   s     r    r   z*MockerFixture.async_stub.<locals>.<lambda>   r   r   r   )r   AsyncMockTyperK   rH   r   s     r    
async_stubzMockerFixture.async_stub   s6     &&,H,Ht&TT
 
 	
r   c                   L   e Zd ZdZ e            Zd Zdedededede	f
dZ
ed	d
d	d	d	fdedededee         dedee         dee         dedede	fdZed	d
d	d	d	fdej        dedej        deej                 dedeej                 deej                 dej        dede	fdZ	 	 	 	 	 d!dej        deej                 dedeej                 deej                 deej                 dedeee	f         fdZ	 	 d"deeeef         ef         deeeef         eeeef                  f         dededef
dZe	 	 	 	 	 	 d#dedd	deej                 dedeej                 deej                 dd	dede	fd            Ze	 	 	 	 	 d$dededeej                 dedeej                 deej                 dd	dedefd            Zededd	deej                 dedeej                 deej                 deg ef         dedefd            Ze	 	 	 	 	 d$dedd	deej                 dedeej                 deej                 deg ef         dedefd            Zed	d
d	d	d	fdedej        deej                 dedeej                 deej                 deeg ef                  dedefd Zd	S )%MockerFixture._Patcherz
        Object to provide the same interface as mock.patch, mock.patch.object,
        etc. We need this indirection to keep the same API of the mock package.
        c                 "    || _         || _        d S r8   )_Patcher__mock_cacherK   )r/   
mock_cacherK   s      r    rX   zMockerFixture._Patcher.__init__   s     *D*Dr   	mock_funcwarn_on_mock_enterrt   r2   r+   c                      ||i |}|                                 }| j                            ||           t          |d          rt          |d          r|rd |j        _        |S )zPatches something by calling the given function from the mock
            module, registering the patch to stop it later and returns the
            mock object resulting from the mock call.
            )r#   r$   rc   	__enter__c                  :    t          j        dt          d          S )Na0  Mocks returned by pytest-mock do not need to be used as context managers. The mocker fixture automatically undoes mocking at the end of a test. This warning can be ignored if it was triggered by mocking a context manager. https://pytest-mock.readthedocs.io/en/latest/remarks.html#usage-as-context-manager   )
stacklevel)warningswarnr   r   r   r    r   z5MockerFixture._Patcher._start_patch.<locals>.<lambda>  s%    8=m *#$< < < r   )startr   r6   rR   r   ra   )r/   r   r   rt   r2   pmockeds          r    _start_patchz#MockerFixture._Patcher._start_patch   s     	4*6**A wwyyF!!vQ!777v|,,  6;// 4F 4 4F$0 Mr   NFtarget	attributenewrY   createrZ   r|   new_callablec	           
      z    || j         u r| j        j         } | j        | j        j        j        d||f||||||d|	S )zAPI to mock.patch.objectTr   rY   r   rZ   r|   r   rU   rK   r   r$   r   
r/   r   r   r   rY   r   rZ   r|   r   r2   s
             r    r   zMockerFixture._Patcher.object  sp     dl""&.$4$ &-	
 !!)    r   c	           
      z    || j         u r| j        j         } | j        | j        j        j        d||f||||||d|	S )zThis is equivalent to mock.patch.object except that the returned mock
            does not issue a warning when used as a context manager.Fr   r   r   s
             r    context_managerz&MockerFixture._Patcher.context_manager/  sp     dl""&.$4$ &-	
 !!)    r   c           	      L     | j         | j        j        j        d|f|||||d|S )zAPI to mock.patch.multipleT)rY   r   rZ   r|   r   )r   rK   r$   multiple)r/   r   rY   r   rZ   r|   r   r2   s           r    r   zMockerFixture._Patcher.multipleM  sR     %4$ &/
 !!)
 
 
 
 
r   r   in_dictvaluesr=   c                 F     | j         | j        j        j        d|f||d|S )zAPI to mock.patch.dictT)r   r=   )r   rK   r$   dict)r/   r   r   r=   r2   s        r    r   zMockerFixture._Patcher.dictd  sI     %4$ &+     r   .c                     d S r8   r   	r/   r   r   rY   r   rZ   r|   r   r2   s	            r    __call__zMockerFixture._Patcher.__call__u  s	     sr   c                     d S r8   r   r   s	            r    r   zMockerFixture._Patcher.__call__  	     r   c                     d S r8   r   r   s	            r    r   zMockerFixture._Patcher.__call__  r   r   c                    d S r8   r   r   s	            r    r   zMockerFixture._Patcher.__call__  s	     r   c           
      n    || j         u r| j        j         } | j        | j        j        d|f||||||d|S )zAPI to mock.patchTr   )rU   rK   r   r$   r   s	            r    r   zMockerFixture._Patcher.__call__  sj     dl""&.$4$ & !!)    r   )NFNNN)r   F)......).....)r   r   r   r   r   rU   rX   r   boolr%   r   strr   builtinsr   r   r   r   r   r	   r   r   r   r   r   r   r   r   r    rL   r      s       	 	
 &((	+ 	+ 	+	 	6:	CF	RU		 	 	 	8 "%) )-)-#'	 		 	 		
 6"	 	 v&	 v&	 !	 	 	 	 	 	B $+.2 2626,0	 	O	 	 		
 8?+	 	 x/	 x/	 #/	 	 	 	 	 	B /3 26266:	 	O	 8?+	 		
 x/	 x/	 #8?3	 	 #x- 	 	 	 	4 KM		 	738,c12	 '#s(+XeCHo-FFG	 		
 	 	 	 	 	" 
 .12525!$
	 
	
	 
	 8?+	
	
 
	 x/
	 x/
	 
	 
	 
	 
	 
	 

	 

 /22525!$
	 
	
	 
	 8?+	
	
 
	 x/
	 x/
	 
	 
	 
	 
	 
	 

	 

	
	 
	 8?+	
	
 
	 x/
	 x/
	 #2r6*
	 
	 
	 
	 
	 

	 
 .12525	 		 	 8?+		
 	 x/	 x/	 #2r6*	 	 	 	 	 
	  $+.2 26268<	 		 	 8?+		
 	 x/	 x/	 #8BG#45	 	 	 	 	 	 	 	r   rL   )FFrB   r8   )r   r   r   r   r   rX   r   r%   r]   rg   ri   r   r#   rN   r9   r   r   r   r   r   r   r   rL   r   r   r    rE   rE   T   s        
)s )t ) ) ) )* CH #';?SV	    ',, , ,#,:>,	, , , ,:! ! ! !&0 &T & & & &0v 0S 0X 0 0 0 0d
 
# 
(-2I 
 
 
 

 
x} 
 
 
 
 
U U U U U U U U U Ur   rE   pytestconfigr+   c              #   X   K   t          |           }|V  |                                 dS )z
    Return an object that has the same interface to the `mock` module, but
    takes care of automatically undoing all patches after each test method.
    N)rE   ri   )r   results     r    _mockerr     s4      
 <((F
LLL
NNr   class)scopemodulepackagesession__wrapped_mock_method__.rt   r2   c                    d}	  | |i | d S # t           $ r}t          |dd          rt          |          }n|d         }t          |          }|j        |j        \  }}d}		 ||dd          k    sJ n,# t           $ r}
|	dt          |
          z   z  }	Y d }
~
nd }
~
ww xY w	 ||k    sJ n,# t           $ r}|	dt          |          z   z  }	Y d }~nd }~ww xY w|	r|d|	z   z  }t          |          }d|_        |d }~ww xY w)	NT_mock_introspection_appliedr    r   
Args:
	
Kwargs:
 

pytest introspection follows:
)AssertionErrorr}   r   	call_argsr   )r   rt   r2   __tracebackhide__rv   msg__mock_selfactual_argsactual_kwargsintrospectione_argse_kwargss               r    assert_wrapperr     s    0000   13Q77 	Qa&&CCq'Ka&&C$0-8-B*] "?&$qrr(22222% ? ? ?![3v;;%>>MMMMMM?C(F22222% C C C!]S]]%BBMMMMMMC  Q@=PPC3(,%+si    
C>AC9$A54C95
B?BC9BC9"B+*C9+
C5C
C9C%C99C>c                    d}	  | |i | d S # t           $ rP}|                    dd          }t          |dd          s|rt          |          }n|d         }t          |          }|j        t          |j                  }|d         }	d}
ddlm}  |||	          D ]\  }}||\  }}nt                      }i }||\  }}}nt                      }i }	 ||k    sJ n,# t           $ r}|
d	t          |          z   z  }
Y d }~nd }~ww xY w	 ||k    sJ v# t           $ r}|
d
t          |          z   z  }
Y d }~d }~ww xY w|
r|d|
z   z  }t          |          }d|_	        |d }~ww xY w)NT	any_orderFr   r   r   r   )zip_longestr   r   r   )
r   getr}   r   call_args_listrC   	itertoolsr   tupler   )r   rt   r2   r   rv   r   r   r   actual_callsexpect_callsr   r   actual_callexpect_callr   r   _expect_argsexpect_kwargsr   r   s                        r    assert_has_calls_wrapperr     s$    )0000 & & &JJ{E22	13Q77 !	Q9 !	Qa&&CCq'Ka&&C)5#K$>??#Aw "1111110;L,0W0W G G,K".5@2]]&+gg(*".8C5;&+gg(*C*k99999) C C C%s6{{)BBCG,=====) G G G%X)FFG  Q@=PPC3(,%M&si    E)B=E$C E$ 
D	*D?E$D		E$DE$
D? D:5E$:D??%E$$E)c                  @    d}t          t          d         g| R i | d S )NTassert_not_calledr   _mock_module_originalsrt   r2   r   s      r    wrap_assert_not_calledr   *  3    )*=>PPPPPPPPPr   c                  @    d}t          t          d         g| R i | d S )NTassert_called_withr   r   s      r    wrap_assert_called_withr   /  3    )*>?Q$QQQ&QQQQQr   c                  @    d}t          t          d         g| R i | d S )NTassert_called_oncer   r   s      r    wrap_assert_called_oncer   4  r   r   c                  @    d}t          t          d         g| R i | d S )NTassert_called_once_withr   r   s      r    wrap_assert_called_once_withr   9  s3    )*CDVtVVVvVVVVVr   c                  @    d}t          t          d         g| R i | d S )NTassert_has_calls)r   r   r   s      r    wrap_assert_has_callsr   >  sG    1259  =C    r   c                  @    d}t          t          d         g| R i | d S )NTassert_any_callr   r   s      r    wrap_assert_any_callr  E  s3    )*;<NtNNNvNNNNNr   c                  @    d}t          t          d         g| R i | d S )NTassert_calledr   r   s      r    wrap_assert_calledr  J  s2    )/:LTLLLVLLLLLr   c                  @    d}t          t          d         g| R i | d S )NTassert_not_awaitedr   r   s      r    wrap_assert_not_awaitedr	  O  r   r   c                  @    d}t          t          d         g| R i | d S )NTassert_awaited_withr   r   s      r    wrap_assert_awaited_withr  T  3    )*?@R4RRR6RRRRRr   c                  @    d}t          t          d         g| R i | d S )NTassert_awaited_oncer   r   s      r    wrap_assert_awaited_oncer  Y  r  r   c                  @    d}t          t          d         g| R i | d S )NTassert_awaited_once_withr   r   s      r    wrap_assert_awaited_once_withr  ^  s4    )*DEWWWWPVWWWWWr   c                  @    d}t          t          d         g| R i | d S )NTassert_has_awaitsr   r   s      r    wrap_assert_has_awaitsr  c  r   r   c                  @    d}t          t          d         g| R i | d S )NTassert_any_awaitr   r   s      r    wrap_assert_any_awaitr  h  s3    )*<=OOOOOOOOOr   c                  @    d}t          t          d         g| R i | d S )NTassert_awaitedr   r   s      r    wrap_assert_awaitedr  m  s3    )*:;MdMMMfMMMMMr   rF   c                    t           rdS t          |           }t          t          t          t
          t          t          t          d}|	                                D ]\  }}	 t          |j        |          }n# t          $ r Y (w xY w|t           |<   |j                            |j        ||          }|                                 t                               |           t%          |d          rt&          t(          t*          t,          t.          t0          t2          d}|	                                D ]\  }}	 t          |j        |          }n# t          $ r Y (w xY w|t           |<   |j                            |j        ||          }|                                 t                               |           |                     t8                     dS )z
    Wrap assert methods of mock module so we can hide their traceback and
    add introspection information to specified argument asserts.
    N)r  r   r   r   r  r   r   rH   )r  r  r  r  r  r  r  )r   r   r  r   r   r   r  r   r   itemsr}   rO   AttributeErrorr$   r   r   _mock_module_patchesr5   rR   r  r  r  r  r  r  r	  rH   add_cleanupunwrap_assert_methods)rF   rK   wrappersrw   ry   originalpatcherasync_wrapperss           r    wrap_assert_methodsr'  r  s     !&))K ,55#?/13 H $>>++ - -	{:FCCHH 	 	 	H	)1v&#**;+FPWXX##G,,,,{K(( 11#;#;(E 5!7"9
 
  .3355 	1 	1OFG";#8&AA!   -5"6*!'..{/DfgVVGMMOOO ''0000
,-----s$    A66
BB7E
EEc                      t           D ]C} 	 |                                  # t          $ r}t          |          dk    rn Y d }~<d }~ww xY wg t           d d <   t                                           d S )Nz stop called on unstarted patcher)r   r9   RuntimeErrorr   r   r=   )r%  rv   s     r    r"  r"    s    '  
	LLNNNN 	 	 	
 1vv;;; 	 !  """""s    
A	AA	parserc                 f    |                      ddd           |                      ddd           d S )Nmock_traceback_monkeypatchzRMonkeypatch the mock library to improve reporting of the assert_called_... methodsTdefaultmock_use_standalone_modulezPUse standalone "mock" (from PyPI) instead of builtin "unittest.mock" on Python 3F)addini)r*  s    r    pytest_addoptionr1    sZ    
MM$	$	     MM$		      r   c                     |                      dd          }t          |                     d                    r|dk    rt          |            d S d S d S )Nz--tbautor-  r,  native)	getoptionr   getinir'  )rF   tbs     r    pytest_configurer8    sc    			&&		1	1B&--(DEEFF$(NNF#####	$ $Nr   rB   )Gr~   r   r   r   unittest.mockr   r   dataclassesr   r   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   pytest_utilr   r   r   r#   rH   r   rN   rP   r%   UserWarningr   r"   r(   rE   r   fixturemockerclass_mockermodule_mockerpackage_mockersession_mockerr   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  r  r  r'  r"  r1  r8  r   r   r    <module>rE     s
               ! ! ! ! ! !                                                                                                  " " " " " " $ $ $ $ $ $WT]]'MMM&(> > > > > > > >                
                Bo o o o o o o od# )M4,E"F     
		'	"	",~v~G,,,W55.X...w770i000990i00099   %c3h/8;GJ	   >-%c3h/-8;-GJ-	- - - -`Q# Q Q Q Q Q Q
R3 R# R$ R R R R
R3 R# R$ R R R R
W Ws Wt W W W W
      O Os Ot O O O O
Mc MS MT M M M M
R3 R# R$ R R R R
SC S3 S4 S S S S
SC S3 S4 S S S S
X X X X X X X
Q# Q Q Q Q Q Q
P P P P P P P
Ns Nc Nd N N N N
2. 2. 2. 2. 2. 2.j# # # #"S T    $S $T $ $ $ $ $ $r   