zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
U
¬ý°d½ã    @sÖddlmZddlmZmZddlZddlZddlmZm    Z    m
Z
m Z m Z ddl Z eeddddfddd    d    d
d d œd d„ƒZdd    dœdd„Zddd
d    ddœdd„Zddddœdd„Zddd    dœdd„Zdddœd d!„ZdS)"é)Ú annotations)ÚcontextmanagerÚ nullcontextN)Ú    GeneratorÚLiteralÚSequenceÚTypeÚcastÚalwaysTz7type[Warning] | bool | tuple[type[Warning], ...] | NonezCLiteral[('error', 'ignore', 'always', 'default', 'module', 'once')]Úboolz
str | Nonez4Generator[list[warnings.WarningMessage], None, None])Úexpected_warningÚ filter_levelÚcheck_stacklevelÚraise_on_extra_warningsÚmatchÚreturnc csjd}tjddP}t |¡z
|VW5|rJttt|ƒ}t||||d|rZt||dXW5QRXdS)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_warningsr rr)rr N)ÚwarningsÚcatch_warningsÚ simplefilterr    rÚWarningÚ_assert_caught_expected_warningÚ _assert_caught_no_extra_warnings)r r rrrZ__tracebackhide__Úw©rúPd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pandas/_testing/_warnings.pyÚassert_produces_warnings$C
 
üþrz type[Warning])ÚwarningÚ    conditioncKs|rt|f|ŽStƒSdS)zX
    Return a context manager that possibly checks a warning based on the condition
    N)rr)rrÚkwargsrrrÚmaybe_produces_warningls r!z!Sequence[warnings.WarningMessage]ÚNone)rr rrrcCs¢d}d}g}|D]L}t|j|ƒrd}|r0t|ƒ|dk    rt |t|jƒ¡rPd}q| |j¡q|svtdt    |j
ƒ›ƒ‚|rž|sžtdt    |j
ƒ›d|›d|›ƒ‚dS)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 ) Ú
issubclassÚcategoryÚ&_assert_raised_with_correct_stacklevelÚreÚsearchÚstrÚmessageÚappendÚAssertionErrorÚreprÚ__name__)rr rrZ saw_warningZmatched_messageZunmatched_messagesÚactual_warningrrrrvs( ÿÿr)rr rcCs~g}|D]Z}t||ƒr|jtkrFdt|jƒkr0qtdd„tjDƒƒrFq| |jj    |j|j
|j f¡q|rzt dt |ƒ›ƒ‚dS)zFAssert that no extra warnings apart from the expected ones are caught.zunclosed <ssl.SSLSocketcss|]}d|kVqdS)Z
matplotlibNr)Ú.0ÚmodrrrÚ    <genexpr>°sz3_assert_caught_no_extra_warnings.<locals>.<genexpr>zCaused unexpected warning(s): N)Ú_is_unexpected_warningr$ÚResourceWarningr(r)ÚanyÚsysÚmodulesr*r-ÚfilenameÚlinenor+r,)rr Zextra_warningsr.rrrrs"
 
üÿ    rzwarnings.WarningMessage)r.r rcCs,|r |s dSttt|ƒ}tt|j|ƒ ƒS)z1Check if the actual warning issued is unexpected.T)r    rrr r#r$)r.r rrrr2¿sr2)r.rcCsVddlm}m}||ƒddƒ}d|j›d|j›d|j›}|j|jksRt|ƒ‚dS)Nr)Ú getframeinfoÚstackézGWarning not set with correct stacklevel. File where warning is raised: z != z. Warning message: )Úinspectr9r:r7r)r+)r.r9r:ZcallerÚmsgrrrr%Ês
ÿr%)Ú
__future__rÚ
contextlibrrr&r5Útypingrrrrr    rrrr!rrr2r%rrrrÚ<module>s" ùX
'"