cL ibUddlZddlmcmZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZddl mZddl mZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlZddlmZddlmZedZ e jBjDZ#ee jBjHe jBjDe jBjJfZ&Gdde'Z(eGddZ)eGddZ*GddZ+dede e+ddffdZ,ejZe,Z.ejZde,Z/ejZd e,Z0ejZd!e,Z1ejZd"e,Z2gZ3e4ee5d#<iZ6e7e8efe5d$<d%ed&efd'ed(eddfd)Z9d%ed&efd'ed(eddfd*Z:d'ed(eddfd+Z;d'ed(eddfd,Zd'ed(eddfd/Z?d'ed(eddfd0Z@d'ed(eddfd1ZAd'ed(eddfd2ZBd'ed(eddfd3ZCd'ed(eddfd4ZDd'ed(eddfd5ZEd'ed(eddfd6ZFd'ed(eddfd7ZGd'ed(eddfd8ZHd9eddfd:ZId?d;ZJdZLy)@N) Generator)Iterable)Iterator)Mapping) dataclass)field)Any)Callable)Optional)TypeVar)Union)cast)overload)get_mock_module)parse_ini_boolean_TceZdZdZy)PytestMockWarningz3Base class for all warnings emitted by pytest-mock.N)__name__ __module__ __qualname____doc__X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pytest_mock/plugin.pyrr$s=rrc,eZdZUeed<dZeeed<y) MockCacheItemmockNpatch)rrrMockType__annotations__r r r rrrrr(s NE8C=rrceZdZUdZeeZeeed<de defdZ de de defdZ de dd fd Z d d Zdeefd Zy ) MockCachezJ Cache MagicMock and Patcher instances so we can undo them later. )default_factorycacherreturnc^|jD]}|j|us|cStd)Nz"This mock object is not registered)r&r ValueErrorselfr mock_items r_findzMockCache._find6s5 !I~~%   !=>>rkwargsc l|jjtdd|i||jdS)Nrr)r&appendr)r+rr.s raddz MockCache.add<s/ -><8y~~'8913 .y~~'8915 .)..*GH))!-;*))+ ,rc8|jjy)zi Stop all patchers started by this fixture. Can be safely called multiple times. N)rFr9r<s rstopallzMockerFixture.stopalls  rrc:|jj|y)zp Stops a previous patch or spy call by passing the ``MagicMock`` object returned by it. N)rFr6)r+rs rr5zMockerFixture.stops %robjnameduplicate_iteratorsc t|| fd} fd}tjrtj|}ntj|}tj xstj }|jj|||| d _ d _ g _ d _ S)ak 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. :param duplicate_iterators: Whether to keep a copy of the returned iterator in `spy_return_iter`. :return: Spy object. c d_d_ |i|}r1t|tr!t j |d\}}|_nd_|_jj||S#t$r }|_d}~wwxYw)N) spy_return spy_exceptionrbr itertoolsteerar`r1 BaseException)argsr.rduplicated_iteratorerjmethodspy_objs rwrapperz"MockerFixture.spy..wrappers!%G $(G ! 2D+F+ ':a+B-6]]1a-@*A*.AG+.2G+%&"''..q1H! ()% sA77 B BB cKd_d_ |i|d{}|_jj||S7(#t$r }|_d}~wwxYwwr4)rnror`r1rr)rsr.rtrvrwrxs r async_wrapperz(MockerFixture.spy..async_wrappersp!%G $(G ! 2 $1&11 &'"''..q1H2  ()% s7A" A AA $A"A AAAA")r]autospecN) getattrinspectiscoroutinefunction functoolsupdate_wrapperismethod isfunctionr objectrnrar`ro) r+rhrirjryr{wrappedr|rwrxs ` @@rspyzMockerFixture.spysd# &   & &v ...}fEG..w?G##F+Iw/A/A&/I**##C7X#V!"&"$ $rcttjj|jjd|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. cyr4rrsr.s rz$MockerFixture.stub..rrUri)runittestrrJrGr+ris rstubzMockerFixture.stubs8 MM # #    & &,Ht & T  rcZtt|jjd|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. cyr4rrs rrz*MockerFixture.async_stub..rrr)r AsyncMockTyperGrDrs r async_stubzMockerFixture.async_stubs.     & &,Ht & T  rcbeZdZdZeZdZdedededede f dZ ed d d d d fd ed e d ede edede ede ededede fdZed d d d d fd e jd e d e jde e jdede e jde e jde jdede fdZ dd e jde e jdede e jde e jde e jdedee e ffdZ d deeeefe fdeeeefeeeeffdededef dZe d!d e d d de e jdede e jde e jdd dede fdZe d"d e d ede e jdede e jde e jdd dedefdZed e d d de e jdede e jde e jdegefdedefdZe d"d e d d de e jdede e jde e jdegefdedefdZed d d d d fd e d e jde e jdede e jde e jde egefdedefdZy )#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 ||_||_yr4)_Patcher__mock_cacherG)r+ mock_cacherGs rrTzMockerFixture._Patcher.__init__s *D *D r mock_funcwarn_on_mock_enterrsr.r'c||i|}|j}|jj||t|dr t|dr|rd|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. )rr r_ __enter__c:tjdtdS)Na.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/usage.html#usage-as-context-manager) stacklevel)warningswarnrrrrrz5MockerFixture._Patcher._start_patch..s8==k*#$ <r)startrr2rNrr])r+rrrsr.pmockeds r _start_patchz#MockerFixture._Patcher._start_patchsg4*6*A wwyF    ! !vQ ! 7v|,6;/4F4F$$0MrNFtarget attributenewrUcreaterVr| new_callablec ||jur|jj}|j|jjjd||f||||||d| S)zAPI to mock.patch.objectTrrUrrVr|rrQrGrr r r+rrrrUrrVr|rr.s rrzMockerFixture._Patcher.objectswdll"&&..$4$$  &&--  !!)   rc ||jur|jj}|j|jjjd||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.Frrrs rcontext_managerz&MockerFixture._Patcher.context_manager7swdll"&&..$4$$  &&--  !!)   rc t|j|jjjd|f|||||d|S)zAPI to mock.patch.multipleT)rUrrVr|r)rrGr multiple)r+rrUrrVr|rr.s rrzMockerFixture._Patcher.multipleUsT%4$$  &&// !!)   rin_dictvaluesr9c n|j|jjjd|f||d|S)zAPI to mock.patch.dictT)rr9)rrGr dict)r+rrr9r.s rrzMockerFixture._Patcher.dictlsK%4$$  &&++    rc yr4r r+rrrUrrVr|rr.s r__call__zMockerFixture._Patcher.__call__}src yr4rrs rrzMockerFixture._Patcher.__call__rc yr4rrs rrzMockerFixture._Patcher.__call__rrc yr4rrs rrzMockerFixture._Patcher.__call__src ||jur|jj}|j|jjd|f||||||d|S)zAPI to mock.patchTr)rQrGrr rs rrzMockerFixture._Patcher.__call__sndll"&&..$4$$  && !!)   r)NFNNN)rF)......).....)rrrrrrQrTr boolr!rstrr builtinsrrrr rrtuplerrrr rrrrHrsy ( +   6: CF RU   8"%) )-)-#'      6"     v& v& !   B$+.2 2626,0 OO     8??+     x/ x/ #//   B/3 26266: OO 8??+    x/   x/  #8??3  #x-  4KM  738,c12 '#s(+XeCHo-FFG         " .12525!$   8??+    x/ x/        /22525!$   8??+    x/ x/          8??+    x/ x/ #2r6*      .12525   8??+    x/ x/ #2r6*      $+.2 26268<   8??+      x/  x/ #8BG#45   rrH)FFr>)Fr4)rrrrr rTrr!rYrdrfrrrJr5rrrr rrrrHrrrrArAPs )s)t)*CH#';?SV ',,#,:>, ,>!&00&T&CH::!$:;?: :x  #  (--2I2I    x}   UUrrA pytestconfigr'c#JKt|}||jyw)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)rArf)rresults r_mockerrs! < (F L NNs!#class)scopemodulepackagesession_mock_module_patches_mock_module_originals__wrapped_mock_method__.rsr.cd} ||i|y#t$r5}t|ddr t|}n|d}t|}|j|j\}}d} |dd} || k(} | st j d| fd|| fdt jvst j|rt j|ndt j| d z} d d | iz} tt j| dx} } n'#t$r}| d t|zz } Yd}~nd}~wwxYw ||k(} | st j d| fd ||fdt jvst j|rt j|nddt jvst j|rt j|nddz}dd|iz}tt j|d} n'#t$r}| dt|zz } Yd}~nd}~wwxYw| r|d| zz }t|}d|_ |d}~wwxYw)NT_mock_introspection_appliedrr==)z%(py0)s == %(py3)s actual_args)py0py3zassert %(py5)spy5 Args: z%(py0)s == %(py2)s actual_kwargsr.rpy2assert %(py4)spy4 Kwargs: pytest introspection follows: ) AssertionErrorr}r call_args @pytest_ar_call_reprcompare @py_builtinslocals_should_repr_global_name _saferepr_format_explanationr)rrsr.__tracebackhide__rvmsg __mock_selfrr introspection @py_assert2 @py_assert1 @py_format4 @py_format6e_args @py_format3 @py_format5e_kwargss rassert_wrapperrs00  13Q 7a&Cq'Ka&C$$0-8-B-B* ] " ?*.qr(2;(2222;(222222;222;222(2222222%?![3v;%>>M?C(F2222=F222222=222=222222F222F2222222%C!]S]%BBMC @=PPC 3 (,%+sk I AI B)D  I D.D)$I)D..I2CHI H& H!I!H&&!II c d} ||i|y#t$r}|jdd}t|dds|r t|}nu|d}t|}|jXt |j}|d} d} ddlm} | || D]\} } | | \}}n t}i}| | \}}}n t}i} ||k(}|stjd |fd ||fd tjvstj|rtj|nd d tjvstj|rtj|nd d z}dd|iz}ttj|d}n'#t$r}| dt|zz } Yd}~nd}~wwxYw ||k(}|stjd |fd ||fdtjvstj|rtj|nddtjvstj|rtj|ndd z}dd|iz}ttj|d}#t$r}| dt|zz } Yd}~d}~wwxYw| r|d| zz }t|}d|_|d}~wwxYw)NT any_orderFrrrr) zip_longestrrr expect_argsrrrrr expect_kwargsrr)rgetr}rcall_args_listr?rprrrrrrrrrr)rrsr.rrvrrr actual_calls expect_callsrr actual_call expect_callrr_rrrrrrrs rassert_has_calls_wrapperrs@)00 &JJ{E2 13Q 79a&Cq'Ka&C))5#K$>$>? #Aw " 10;L,0WG,K".5@2 ]&+g (* ".8C5; &+g (* C*k9999{k999999{999{999999k999k9999999)C%s6{)BB CG, ====} ======}===}====== === =======)G%X)FF G'G*!@=PPC 3 (,%M&sk KB&K>CF K F2F-(K-F22K6CJK J,J'!K'J,,"KKc4d}ttdg|i|y)NTassert_not_calledrrrsr.rs rwrap_assert_not_calledr2!)*=>PPPrc4d}ttdg|i|y)NTassert_called_withrrs rwrap_assert_called_withr 7!)*>?Q$Q&Qrc4d}ttdg|i|y)NTassert_called_oncerrs rwrap_assert_called_oncer<r rc4d}ttdg|i|y)NTassert_called_once_withrrs rwrap_assert_called_once_withrAs!)*CDVtVvVrc4d}ttdg|i|y)NTassert_has_calls)rrrs rwrap_assert_has_callsrFs)1259=Crc4d}ttdg|i|y)NTassert_any_callrrs rwrap_assert_any_callrMs!)*;<NtNvNrc4d}ttdg|i|y)NT assert_calledrrs rwrap_assert_calledrRs )/:LTLVLrc4d}ttdg|i|y)NTassert_not_awaitedrrs rwrap_assert_not_awaitedrWr rc4d}ttdg|i|y)NTassert_awaited_withrrs rwrap_assert_awaited_withr"\!)*?@R4R6Rrc4d}ttdg|i|y)NTassert_awaited_oncerrs rwrap_assert_awaited_oncer&ar#rc4d}ttdg|i|y)NTassert_awaited_once_withrrs rwrap_assert_awaited_once_withr)fs")*DEWWPVWrc4d}ttdg|i|y)NTassert_has_awaitsrrs rwrap_assert_has_awaitsr,kr rc4d}ttdg|i|y)NTassert_any_awaitrrs rwrap_assert_any_awaitr/ps!)*<=OOOrc4d}ttdg|i|y)NTassert_awaitedrrs rwrap_assert_awaitedr2us!)*:;MdMfMrrBcPtryt|}tttt t ttd}|jD]q\}} t|j|}|t|<|jj|j||}|jt j#|st%|drt&t(t*t,t.t0t2d}|jD]q\}} t|j4|}|t|<|jj|j4||}|jt j#|s|j7t8y#t$rYLwxYw#t$rYwxYw)z Wrap assert methods of mock module so we can hide their traceback and add introspection information to specified argument asserts. N)rrr rrrrrD)r1r%r!r(r.r+r)rrrrr rrrritemsr}rKAttributeErrorr rrrr1rNr2r&r"r)r/r,rrD add_cleanupunwrap_assert_methods)rBrGwrappersrwryoriginalpatcherasync_wrapperss rwrap_assert_methodsr<zs !&)K,55#?/13H$>>+- {::FCH*2v&##**;+F+FPWX ##G,-{K(1#;#;(E 5!7"9  .335 1OFG ";#8#8&A.6 "6 *!''..{/D/DfgVG MMO ' ' 0 1 ,-7   ("  s$F F FF F%$F%ctD]} |jgtddtj y#t$r}t|dk(rnYd}~Rd}~wwxYw)Nz stop called on unstarted patcher)rr5 RuntimeErrorrrr9)r:rvs rr7r7sd'   LLN !  "  1v;;  s; AAAparsercT|jddd|jdddy)Nmock_traceback_monkeypatchzRMonkeypatch the mock library to improve reporting of the assert_called_... methodsTdefaultmock_use_standalone_modulezPUse standalone "mock" (from PyPI) instead of builtin "unittest.mock" on Python 3F)addini)r?s rpytest_addoptionrFs< MM$ $   MM$  rc|jdd}t|jdr|dk7r t|yyy)Nz--tbautorBrAnative) getoptionrgetinir<)rBtbs rpytest_configurerMsC   &&  1B&--(DEF (NF#  Grr>)Mrr_pytest.assertion.rewrite assertionrewriterrr~rp unittest.mockrrcollections.abcrrrr dataclassesrrtypingr r r r r rrpytest_utilrrrrrDrrJrLr! UserWarningrrr$rArfixturemocker class_mocker module_mockerpackage_mockersession_mockerrr?r"rrrrrrr rrrrrrr"r&r)r,r/r2r<r7rFrMrrrr^s%$$#! "$ T] ''  MM MM MM&&( > >          B{{| #)M4,E"F  ' ",~v~~G,W5 .X.w7 0i090i09#%d3i$)+S#X+%c3h/8;GJ >-%c3h/-8;-GJ- -`Q#QQQ R3R#R$R R3R#R$R WWsWtW OOsOtO McMSMTM R3R#R$R SCS3S4S SCS3S4S XXXX Q#QQQ PPPP NsNcNdN 2.2.2.j#" S T $S$T$r