gL i ddlmZddlmZmZddlZddlZddlZddlm Z m Z m Z ddl Z ddl mZe rddlmZmZeeddddf dd Zdd Z dd Z dd Z dd Z ddZy)) annotations)contextmanager nullcontextN) TYPE_CHECKINGLiteralcast)PY311) GeneratorSequencealwaysTc #Kd}tjd5}tj| ||r&ttt |}t |||||rt|| dddy#|r&ttt |}t |||||rt||wwxYw#1swYyxYww)a$ Context manager for running code expected to either raise a specific warning, multiple specific warnings, or not raise any warnings. Verifies that the code raises the expected warning(s), and that it does not raise any other unexpected warnings. It is basically a wrapper around ``warnings.catch_warnings``. Parameters ---------- expected_warning : {Warning, False, tuple[Warning, ...], None}, default Warning The type of Exception raised. ``exception.Warning`` is the base class for all warnings. To raise multiple types of exceptions, pass them as a tuple. To check that no warning is returned, specify ``False`` or ``None``. filter_level : str or None, default "always" Specifies whether warnings are ignored, displayed, or turned into errors. Valid values are: * "error" - turns matching warnings into exceptions * "ignore" - discard the warning * "always" - always emit a warning * "default" - print the warning the first time it is generated from each location * "module" - print the warning the first time it is generated from each module * "once" - print the warning the first time it is generated check_stacklevel : bool, default True If True, displays the line that called the function containing the warning to show were the function is called. Otherwise, the line that implements the function is displayed. raise_on_extra_warnings : bool, default True Whether extra warnings not of the type `expected_warning` should cause the test to fail. match : str, optional Match warning message. Examples -------- >>> import warnings >>> with assert_produces_warning(): ... warnings.warn(UserWarning()) ... >>> with assert_produces_warning(False): ... warnings.warn(RuntimeWarning()) ... Traceback (most recent call last): ... AssertionError: Caused unexpected warning(s): ['RuntimeWarning']. >>> with assert_produces_warning(UserWarning): ... warnings.warn(RuntimeWarning()) Traceback (most recent call last): ... AssertionError: Did not see expected warning of class 'UserWarning'. ..warn:: This is *not* thread-safe. T)record)caught_warningsexpected_warningmatchcheck_stacklevel)rrN)warningscatch_warnings simplefilterrtypeWarning_assert_caught_expected_warning _assert_caught_no_extra_warnings)r filter_levelrraise_on_extra_warningsr__tracebackhide__ws _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/pandas/_testing/_warnings.pyassert_produces_warningrsF   -l+ G#'W 7G#H /$%%5%5  '0$%%5  #'W 7G#H /$%%5%5  '0$%%5's2CB4A78B4. C7:B11B44B=9Cc 2|r t|fi|StS)zX Return a context manager that possibly checks a warning based on the condition )rr)warning conditionkwargss rmaybe_produces_warningr$ss&w9&99}cd}d}g}|D]r}t|j|sd}|r t||,tj|t |j rd}X|j|j t|s!tdt|j|r*|s'tdt|jd|d|yy)zEAssert that there was the expected warning among the caught warnings.FTNz&Did not see expected warning of class zDid not see warning z matching 'z$'. The emitted warning messages are ) issubclasscategory&_assert_raised_with_correct_stacklevelresearchstrmessageappendAssertionErrorrepr__name__)rrrr saw_warningmatched_messageunmatched_messagesactual_warnings rrr}sKO) F n--/? @K6~F 99UC(>(>$?@&*O&--n.D.DE F 4$--./ 1   _"4(8(A(A#B"CDC!" $  %ur%cg}|D]}t||s|jtk(r9dt|jvr;t dt jDr\tr|jtk(rv|j|jj|j|j|jf|rtdt|y)zFAssert that no extra warnings apart from the expected ones are caught.zunclosed z3_assert_caught_no_extra_warnings..sBs|s*BszCaused unexpected warning(s): N)_is_unexpected_warningr(ResourceWarningr,r-anysysmodulesr EncodingWarningr.r1filenamelinenor/r0)rrextra_warningsr5s rrrs N) !.2B C&&/9-N4J4J0KKBckkBB00OC  ! !"++44"**"++"))  %6=d>>R=STUUr%cz|r|syttt|}tt |j | S)z1Check if the actual warning issued is unexpected.T)rrrboolr'r()r5rs rr=r=s; .DM+;< J~668HII JJr%ctj}tdD]}|j} tj|}~d|j d|d|j }|j |k(sJ|y#~wxYw)NzGWarning not set with correct stacklevel. File where warning is raised: z != z. Warning message: )inspect currentframerangef_backgetfilerCr-)r5frame_caller_filenamemsgs rr)r)s  "E 1X !//%0  ))7)@)@(A  .~/E/E.F H  " "o 5:s: 5 s A>>B) r7type[Warning] | bool | tuple[type[Warning], ...] | NonerzALiteral['error', 'ignore', 'always', 'default', 'module', 'once']rrGrrGr str | Nonereturnz4Generator[list[warnings.WarningMessage], None, None])r! type[Warning]r"rG) r!Sequence[warnings.WarningMessage]rrVrrTrrGrUNone)rrWrrSrUrX)r5warnings.WarningMessagerrSrUrG)r5rYrUrX) __future__r contextlibrrrJr*r@typingrrrr pandas.compatr collections.abcr r rrr$rrr=r)r9r%rr_s4"   PW !$(UMUU  U " U U:UUp$ 6$ $$   $  $  $ N$V6$VN$V $VNK+KMK K;+; ;r%