bg*dZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZedZede dfdZeddde eeeefddfdZ ede defd ed!edefd"Z d+de e defd ed!ededeffd#Z e d,ddd$eee!eee!dffde eeeefdd%fd&Z"ed$eee!eee!dffde defd ed!edef d'Z"e!fddd$eee!eee!dffd ede eeeefd!eded%eff d(Z"Gd)dej#Z$eGd*d%e$Z%dS)-z/Record warnings during test function execution.Npformat) TracebackType)Any)Callable) Generator)Iterator)List)Optional)Pattern)Tuple)Type)TypeVar)Union)final)overload)check_ispytest)WARNS_NONE_ARG)fixture)failTreturn)WarningsRecorderNNc#Ktd}|5tjd|VddddS#1swxYwYdS)zReturn a :class:`WarningsRecorder` instance that records all warnings emitted by test functions. See https://docs.pytest.org/en/latest/how-to/capture-warnings.html for information on warning categories. T _ispytestdefaultN)rwarnings simplefilter)wrecs `/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/_pytest/recwarn.pyrecwarnr"s d + + +D i((( s ;??.matchr$rcdSNr#s r!deprecated_callr(* CfuncargskwargscdSr&r')r+r,r-s r!r(r(1r)r*cNd}||f|z}tttfg|Ri|S)aAssert that code produces a ``DeprecationWarning`` or ``PendingDeprecationWarning``. This function can be used as a context manager:: >>> import warnings >>> def api_call_v2(): ... warnings.warn('use v3 of this api', DeprecationWarning) ... return 200 >>> import pytest >>> with pytest.deprecated_call(): ... assert api_call_v2() == 200 It can also be used by passing a function and ``*args`` and ``**kwargs``, in which case it will ensure calling ``func(*args, **kwargs)`` produces one of the warnings types above. The return value is the return value of the function. In the context manager form you may use the keyword argument ``match`` to assert that the warning matches a text or regex. The context manager produces a list of :class:`warnings.WarningMessage` objects, one for each warning raised. T)warnsDeprecationWarningPendingDeprecationWarning)r+r,r-__tracebackhide__s r!r(r(8s@4 w~ $&?@ R4 R R R6 R RRr*expected_warningWarningsCheckercdSr&r')r4r$s r!r0r0Xs Cr*cdSr&r')r4r+r,r-s r!r0r0as Cr*cd}|sI|r5dt|}td|dt||dS|d}t |s"t|dt |dt|d 5||d d i|cd d d S#1swxYwYd S) aAssert that code raises a particular class of warning. Specifically, the parameter ``expected_warning`` can be a warning class or sequence of warning classes, and the code inside the ``with`` block must issue at least one warning of that class or classes. This helper produces a list of :class:`warnings.WarningMessage` objects, one for each warning raised (regardless of whether it is an ``expected_warning`` or not). This function can be used as a context manager, which will capture all the raised warnings inside it:: >>> import pytest >>> with pytest.warns(RuntimeWarning): ... warnings.warn("my warning", RuntimeWarning) In the context manager form you may use the keyword argument ``match`` to assert that the warning matches a text or regex:: >>> with pytest.warns(UserWarning, match='must be 0 or None'): ... warnings.warn("value must be 0 or None", UserWarning) >>> with pytest.warns(UserWarning, match=r'must be \d+$'): ... warnings.warn("value must be 42", UserWarning) >>> with pytest.warns(UserWarning, match=r'must be \d+$'): ... warnings.warn("this is not here", UserWarning) Traceback (most recent call last): ... Failed: DID NOT WARN. No warnings of type ...UserWarning... were emitted... **Using with** ``pytest.mark.parametrize`` When using :ref:`pytest.mark.parametrize ref` it is possible to parametrize tests such that some runs raise a warning and others do not. This could be achieved in the same way as with exceptions, see :ref:`parametrizing_conditional_raising` for an example. Tz, z5Unexpected keyword arguments passed to pytest.warns: z" Use context-manager form instead?) match_exprrrz object (type: z) must be callablerN)joinsorted TypeErrorr5callabletype)r4r$r,r-r3argnamesr+s r!r0r0ksA\  -  yy00H6666 /ETRRRRAw~~ VtTTd4jjTTTUU U - > > > - -4abb,V,, - - - - - - - - - - - - - - - - - -sB55B9<B9ceZdZdZdddeddffdZededfd Zd e ddfd Z de dfd Z de fd Z efdeeddfdZddZdfd Zdeeedeedeeddffd ZxZS)raFA context manager to record raised warnings. Each recorded warning is an instance of :class:`warnings.WarningMessage`. Adapted from `warnings.catch_warnings`. .. note:: ``DeprecationWarning`` and ``PendingDeprecationWarning`` are treated differently; see :ref:`ensuring_function_triggers`. FrrrNct|tdd|_g|_dS)NT)recordF)rsuper__init___entered_list)selfr __class__s r!rEzWarningsRecorder.__init__s>y!!! %%% 46 r*zwarnings.WarningMessagec|jS)zThe list of recorded warnings.rGrHs r!listzWarningsRecorder.lists zr*ic|j|S)z Get a recorded warning by index.rK)rHrNs r! __getitem__zWarningsRecorder.__getitem__sz!}r*c*t|jS)z&Iterate through the recorded warnings.)iterrGrLs r!__iter__zWarningsRecorder.__iter__sDJr*c*t|jS)z The number of recorded warnings.)lenrGrLs r!__len__zWarningsRecorder.__len__s4:r*clsct|jD]6\}}t|j|r|j|cS7d}t |d)z>Pop the first recorded warning, raise exception if not exists.Tz not found in warning list) enumeraterG issubclasscategorypopAssertionError)rHrWrNwr3s r!r\zWarningsRecorder.popsodj)) ) )DAq!*c** )z~~a((((( ) AAABBBr*cg|jdd<dS)z$Clear the list of recorded warnings.NrKrLs r!clearzWarningsRecorder.clears 111 r*c|jrd}td|dt}|J||_t jd|S)NTz Cannot enter z twicealways)rF RuntimeErrorrD __enter__rGrr)rHr3rGrIs r!rdzWarningsRecorder.__enter__sk = ? $ =t===>> >!!##    h''' r*exc_typeexc_valexc_tbc|jsd}td|dt|||d|_dS)NTz Cannot exit z without entering firstF)rFrcrD__exit__)rHrerfrgr3rIs r!rizWarningsRecorder.__exit__sY } O $ MdMMMNN N 7F333 r*)rN)rr)__name__ __module__ __qualname____doc__boolrEpropertyr rMintrPr rSrVWarningrr\r`rdr BaseExceptionrri __classcell__rIs@r!rrs  -2777T7d777777d45XS%> (#<=    (/CCtG}C3LCCCC      4 ./-('   r*c eZdZedfdddeeeeeeedffdeeee efde ddffd Z d eee d ee d ee ddffd ZxZS)r5NFrr4.r9rrct|tdd}|tjt dd}nt |tr<|D]6}t|tst|t|z7|}n8t|tr|f}nt|t|z||_ ||_ dS)NTrz/exceptions must be derived from Warning, not %s) stacklevel)rrDrErwarnr isinstancetuplerZrqr=r?r4r9)rHr4r9rmsgexpected_warning_tupexcrIs r!rEzWarningsChecker.__init__s y!!! 4(((?  # M.Q 7 7 7 7#' (% 0 0 :' 5 5!#w//5#C$s))O4445#3 (' 2 2 :$4#6 C$'7"8"8899 9 4$r*rerfrgc 2t|||d}fd}|||jtfdDs'd}t djd|ddSjD]]}t |jjrAtj j t|j rdS^t djdjd|dSdSdSdSdSdS) NTc:tdDdS)Ncg|] }|j Sr')message).0rCs r! z?WarningsChecker.__exit__..found_str..#s>>>vFN>>>r*)indentrrLsr! found_strz+WarningsChecker.__exit__..found_str"s%>>>>>qIII Ir*c3LK|]}t|jjVdSr&)rZr[r4)rrrHs r! z+WarningsChecker.__exit__..(s2WWQ:aj$2GHHWWWWWWr*z"DID NOT WARN. No warnings of type z0 were emitted. The list of emitted warnings is: .z* matching the regex were emitted. Regex: z Emitted warnings: ) rDrir4anyrr9rZr[recompilesearchstrr)rHrerfrgr3rrrIs` r!rizWarningsChecker.__exit__s 7F333  J J J J J  FN$0WWWWRVWWWWW(,%KT=RKKrs55  ######------------$$$$$$!!!!!! GCLL  9:      36uS'#,./0    36 #&25 *.SS 8CH% &S69SEHS s "#SSSS@ HK14DM5g1C+DDE E#ws|+, -   DM5g1C+DDE 36      IP<-15<-<-<-DM5g1C+DDE<- <- E#ws|+, -<- <-  c !" <-<-<-<-~LLLLLx.LLL^?????&?????r*