o
    ^h                     @   s   d dl Z d dlZd dlZd dlZd dlZddddddZdd ZG d	d
 d
eZe j	dd Z
e j	dedfddZe j	dd ZdddZe j	dd Zdd ZdS )    N    linenooffsetc                C   s  ddl m} tjdd}tdt t|dd W d    n1 s#w   Y  | t|d| |\}| 	t
|jt|j |rJ| t|j| | |jd | |j |d urb| |j| tjdd}td	t || ||||d
 W d    n1 sw   Y  | |g  d S )Nr   )check_syntax_errorTrecordalwaysz
<testcase>execr   errorr   )test.supportr   warningscatch_warningssimplefilterSyntaxWarningcompileassertEquallenZ
assertTrue
issubclasscategoryZassertRegexstrmessagefilenameZassertIsNotNoner   )testcaseZ	statementZerrtextr   r   r   warnswarn r   .  /home/conda/feedstock_root/build_artifacts/python-split_1761171407825/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehol/lib/python3.10/test/support/warnings_helper.pycheck_syntax_warning   s.   r   c                    s    fdd}|S )zDecorator to suppress warnings.

    Use of context managers to hide warnings make diffs
    more noisy and tools like 'git blame' less useful.
    c                    s   t   fdd}|S )Nc                    sP   t   t jd d | g|R i |W  d    S 1 s!w   Y  d S )Nignorer   )r   r   r   )selfargskwargs)r   testr   r   wrapper-   s   
$z3ignore_warnings.<locals>.decorator.<locals>.wrapper)	functoolswraps)r%   r&   r!   )r%   r   	decorator,   s   z"ignore_warnings.<locals>.decoratorr   )r   r)   r   r!   r   ignore_warnings&   s   r*   c                   @   s4   e Zd ZdZdd Zdd Zedd Zdd	 Zd
S )WarningsRecorderzyConvenience wrapper for the warnings list returned on
       entry to the warnings.catch_warnings() context manager.
    c                 C   s   || _ d| _d S )Nr   	_warnings_last)r"   Zwarnings_listr   r   r   __init__:   s   
zWarningsRecorder.__init__c                 C   s@   t | j| jkrt| jd |S |tjjv rd S td| |f )Nz%r has no attribute %r)r   r-   r.   getattrr   WarningMessage_WARNING_DETAILSAttributeError)r"   attrr   r   r   __getattr__>   s
   zWarningsRecorder.__getattr__c                 C   s   | j | jd  S Nr,   r"   r   r   r   r   E   s   zWarningsRecorder.warningsc                 C   s   t | j| _d S r7   )r   r-   r.   r8   r   r   r   resetI   s   zWarningsRecorder.resetN)	__name__
__module____qualname____doc__r/   r6   propertyr   r9   r   r   r   r   r+   6   s    
r+   c                  O   s.   | d}| sdtff} |du rd}t| |S )a  Context manager to silence warnings.

    Accept 2-tuples as positional arguments:
        ("message regexp", WarningCategory)

    Optional argument:
     - if 'quiet' is True, it does not fail if a filter catches nothing
        (default True without argument,
         default False if some filters are defined)

    Without argument, it defaults to:
        check_warnings(("", Warning), quiet=True)
    quietr   NT)getWarning_filterwarnings)filtersr$   r?   r   r   r   check_warningsM   s   


rD   Fc                 c   sj    ddl m} tjdd}tjd||d dV  |r|  W d   n1 s(w   Y  | |g  dS )a  Context manager to check that no warnings are emitted.

    This context manager enables a given warning within its scope
    and checks that no warnings are emitted even with that warning
    enabled.

    If force_gc is True, a garbage collection is attempted before checking
    for warnings. This may help to catch warnings emitted when objects
    are deleted, such as ResourceWarning.

    Other keyword arguments are passed to warnings.filterwarnings().
    r   )
gc_collectTr   r
   )r   r   N)r   rE   r   r   filterwarningsr   )r   r   r   force_gcrE   r   r   r   r   check_no_warningse   s   rH   c                 c   s<    t | tdd dV  W d   dS 1 sw   Y  dS )a"  Context manager to check that no ResourceWarning is emitted.

    Usage:

        with check_no_resource_warning(self):
            f = open(...)
            ...
            del f

    You must remove the object which may emit ResourceWarning before
    the end of the context manager.
    T)r   rG   N)rH   ResourceWarning)r   r   r   r   check_no_resource_warning~   s   "rJ   c                 c   s   t d}|jd}|r|  tjdd}t jd d t	|V  W d   n1 s0w   Y  t
|}g }| D ]5\}}d}	|dd D ]}|j}
t|t|
tjret|
j|red}	|| qI|	sr|sr|||jf q=|r}td	|d
  |rtd|d
  dS )zCatch the warnings, then check if all the expected
    warnings have been raised and re-raise unexpected warnings.
    If 'quiet' is True, only re-raise the unexpected warnings.
       Z__warningregistry__Tr   r   r
   NFzunhandled warning %sr   z)filter (%r, %s) did not catch any warning)sys	_getframe	f_globalsr@   clearr   r   modulesr   r+   listr   rematchr   Ir   	__class__removeappendr:   AssertionError)rC   r?   frameregistrywZreraisemissingmsgcatseenwarningr   r   r   rB      s>   


rB   c               
   c   s<    t jd d  } zd V  W | t jd d < d S | t jd d < w r7   )r   rC   )Zold_filtersr   r   r   save_restore_warnings_filters   s
   "ra   c                   C   s   t jdtdd d S )NzThis is used in test_support test to ensure support.ignore_deprecations_from() works as expected. You should not be seeing this.r   )
stacklevel)r   r   DeprecationWarningr   r   r   r   _warn_about_deprecation   s
   
rd   )r   )F)
contextlibr'   rR   rL   r   r   r*   objectr+   contextmanagerrD   rA   rH   rJ   rB   ra   rd   r   r   r   r   <module>   s(    


'
