Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/test_warnings/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/test_warnings/__pycache__/__init__.cpython-39.pyc

a

XC?h5��@s�ddlmZddlZddlZddlmZddlZddlZddlZddl	Z	ddl
mZddlm
Z
mZddlmZddlZejddgd	�Zejddgd
�Zeed�Zedd
��ZGdd�de�ZGdd�d�ZGdd�de�ZGdd�dee	j�ZGdd�dee	j�Z Gdd�de�Z!Gdd�de!e	j�Z"Gdd�de!e	j�Z#Gdd�de�Z$Gd d!�d!e$e	j�Z%Gd"d#�d#e$e	j�Z&Gd$d%�d%e�Z'Gd&d'�d'e'e	j�Z(Gd(d)�d)e'e	j�Z)Gd*d+�d+ee	j�Z*Gd,d-�d-e�Z+Gd.d/�d/e+e	j�Z,Gd0d1�d1e+e	j�Z-Gd2d3�d3e�Z.Gd4d5�d5e.e	j�Z/Gd6d7�d7e.e	j�Z0Gd8d9�d9e�Z1Gd:d;�d;e1e	j�Z2Gd<d=�d=e1e	j�Z3Gd>d?�d?e	j�Z4Gd@dA�dAe	j�Z5dBdC�Z6e6Z7e8dDk�r�e	�9�dS)E�)�contextmanagerN)�StringIO)�support)�assert_python_ok�assert_python_failure��
stacklevel�warnings�	_warnings)Zblocked)ZfreshZgettotalrefcountc	cs�ttfD]&}z|j��Wqty,Yq0qzt��WntyNYn0tj}|j}z4|dd�|_|�d�|t_dVW|t_||_n|t_||_0dS)z8Use a specific warnings implementation in warning_tests.N�once)	�sys�
warning_tests�__warningregistry__�clear�AttributeError�	NameErrorr	�filters�simplefilter)�moduleZto_clear�original_warningsZoriginal_filters�r�@/opt/alt/python39/lib64/python3.9/test/test_warnings/__init__.py�warnings_states(
�rc@seZdZdS)�TestWarningN��__name__�
__module__�__qualname__rrrrr.srcs,eZdZdZ�fdd�Z�fdd�Z�ZS)�BaseTestz'Basic bookkeeping required for testing.cs`tjj|_dt�vrt�d=ttd�r*t`ttd�r8t`|j	tj
d<|j	tj_tt|��
�dS)Nrr	)�unittest�caser	�old_unittest_module�globals�hasattrr
rrr�modules�superr�setUp��self��	__class__rrr&6s




zBaseTest.setUpcs&ttjd<|jtj_tt|��	�dS)Nr	)
rrr$r!rr r	r%r�tearDownr'r)rrr+Is

zBaseTest.tearDown)rrr�__doc__r&r+�
__classcell__rrr)rr2src@seZdZdZdd�ZdS)�PublicAPITestszGEnsures that the correct values are exposed in the
    public API.
    cCs6|�t|jd��gd�}|�t|jj�t|��dS)N�__all__)�warn�
warn_explicit�showwarning�
formatwarning�filterwarningsr�
resetwarnings�catch_warnings)�
assertTruer#rZassertSetEqual�setr/)r(Z
target_apirrr�test_module_all_attributeTs
�z(PublicAPITests.test_module_all_attributeN)rrrr,r9rrrrr.Nsr.c@seZdZeZdS)�CPublicAPITestsN�rrr�
c_warningsrrrrrr:\sr:c@seZdZeZdS)�PyPublicAPITestsN�rrr�py_warningsrrrrrr=_sr=c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&S)'�FilterTestsz$Testing the filtering functionality.cCs^tj|jd��<}|j��|jjdtd�|�t|jjd�Wd�n1sP0YdS)N�r�error��category�FilterTests.test_error)rr6rr5r4�UserWarning�assertRaisesr0�r(�wrrr�
test_errorfs
�rEc	s�tj�jd���}�j��d���fdd�}t���}|�Wd�n1sP0Y|��}��d|���d|��jjdt	d���
t	|�Wd�n1s�0YdS)	NrA�%FilterTests.test_ignore_after_defaultcs�j��t�dS�N�rr0rFr��messager(rr�fqsz/FilterTests.test_error_after_default.<locals>.fz2UserWarning: FilterTests.test_ignore_after_defaultz&self.module.warn(message, UserWarning)rBrC)rr6rr5r�captured_stderr�getvalue�assertInr4rFrG)r(rIrP�stderrrrNr�test_error_after_defaultms

$��z$FilterTests.test_error_after_defaultcCs~tjd|jd��Z}|j��|jjdtd�|j�dt�|�t|�d�|�t	t
�dg�Wd�n1sp0YdS)NT��recordr�ignorerC�FilterTests.test_ignorer�version)rr6rr5r4rFr0�assertEqual�len�listrrHrrr�test_ignores�
rYcs�tjd�jd��^}�j��d���fdd�}|��jjdtd�|�|���t|�d�Wd�n1st0YdS)	NTrVrKcs�j��t�dSrLrMrrNrrrP�sz0FilterTests.test_ignore_after_default.<locals>.frXrC�)rr6rr5r4rFr[r\�r(rIrPrrNr�test_ignore_after_default�s�
rKcs�tjd�jd���}�j���jjdtd�d���fdd�}|���t|�d���|d	jj	d
��|���t|�d���|d	jj	d
��Wd�n1s�0YdS)NTrV�alwaysrC�FilterTests.test_alwayscs�j��t�dSrLrMrrNrrrP�sz"FilterTests.test_always.<locals>.fr_���r�)
rr6rr5r4rFr[r\rO�argsr`rrNr�test_always�s�
rccstjd�jd���}�j��d���fdd�}|���t|�d���|djjd��|���t|�d��jjd	t	d
�|���t|�d���|djjd��|���t|�d���|djjd��Wd�n1s�0YdS)
NTrVz$FilterTests.test_always_after_ignorecs�j��t�dSrLrMrrNrrrP�sz0FilterTests.test_always_after_default.<locals>.fr_rdrrbrCre�)
rr6rr5r[r\rOrfr4rFr`rrNr�test_always_after_default�s&�
z%FilterTests.test_always_after_defaultcCs�tjd|jd���}|j��|jjdtd�td�}td�D]Z}|j�|t�|dkrt|�|dj	|�|dd�=q<|d	kr�|�t
|�d�q<td
��q<Wd�n1s�0YdS)NTrV�defaultrC�FilterTests.test_defaultrerrdr_zloop variant unhandled)rr6rr5r4rF�ranger0r[rOr\�
ValueError)r(rIrO�xrrr�test_default�s�
rkcCs�tjd|jd��z}|j��|jjdtd�td�}|j�|t�|�|dj|�|dd�=|j�|t�|�t	|�d�Wd�n1s�0YdS)NTrVrrC�FilterTests.test_modulerdr)
rr6rr5r4rFr0r[rOr\�r(rIrOrrr�test_module�s�

rpcCs�tjd|jd���}|j��|jjdtd�td�}|j�|tdd�|�|dj|�|dd�=|j�|tdd	�|�t	|�d
�|j�|tdd�|�t	|�d
�Wd�n1s�0YdS)NTrVrrC�FilterTests.test_once�__init__.py�*rd�
rztest_warnings2.py)
rr6rr5r4rFr1r[rOr\rqrrr�	test_once�s(�
�
��rsc	Cs�tjd|jd���}|j�dt�|jjdtdddd�|�t|�d�|�t	��&|jjdtdddd�Wd�n1s|0Y|�t|�d�|jjdtddid�|�t|�d	�Wd�n1s�0YdS)
NTrVrb�msg�filenameru��module_globalsr_re)
rr6rrrFr1r[r\rG�	TypeErrorrHrrr�test_module_globals�s$���$�zFilterTests.test_module_globalscCs`tj|jd��>}|j��|jjdtd�|�t|jjdt�Wd�n1sR0YdS)NrArBrC�FilterTests.test_inheritance)	rr6rr5r4�WarningrGrFr0rHrrr�test_inheritance�s
�r~c	Cs�tjd|jd���}|j��|jjdtd�|jjdtdd�|dd�=z|j�dt�Wntyv|�d�Yn0|�t	|�d	�Wd�n1s�0YdS)
NTrVrXrCrB)rD�append�FilterTests.test_orderingz!order handling for actions failedr)
rr6rr5r4rFr0Zfailr[r\rHrrr�
test_orderings�

�
r�cCsBtjd|jd���}|j�ddtdd�|�t|jjd�|j��d}|j�|�|�	t
|dj�|�|�|dj
t�|j�d	dtdd�d
}|j�|�|�t
|dj�|�|j��|j�ddtdd�|�t|jjd�d
}|j�|�|�	t
|dj�|�|�|dj
t�Wd�n1�s40YdS)NTrVrB�r�convert to errorzhandle normallyrdrXzfiltered outzhex*zhex/octznonmatching text)rr6rr4rrGrFr0r5r[�strrO�assertIsrDZassertNotEqual)r(rI�textrrr�test_filterwarningss,�

zFilterTests.test_filterwarningscCs�tjd|jd���}|j�dt�|j�ddt�|�t|jjd�|�t|jjd�|j�d�|�|g�|j�d�|�|g�Wd�n1s�0YdS)	NTrVrXrB�matchzmatch prefixzsuffix matchzsomething completely different)	rr6rrrFr4rGr0r[rHrrr�test_message_matching*s�z!FilterTests.test_message_matchingcs�G�fdd�d���fdd�td�D��tjd|jd��D}�|j_|j�td�dd	d
�|�t|dj	�d�Wd�n1s�0YdS)NcseZdZ�fdd�ZdS)z.FilterTests.test_mutate_filter_list.<locals>.Xcsg�dd�<dSrLr)r(�a��Lrrr�8sz4FilterTests.test_mutate_filter_list.<locals>.X.matchN)rrrr�rr�rr�X7sr�csg|]}d��t��df�qS)rjr)rF)�.0�i)r�rr�
<listcomp>;�z7FilterTests.test_mutate_filter_list.<locals>.<listcomp>reTrV�bzf.pyrurd)
rlrr6rrr1rFr[r�rOrHr)r�r�r�test_mutate_filter_list6s�z#FilterTests.test_mutate_filter_listcCs�tj|jd���|j��|jjdtd�|�t|jj�d�|jjdtd�|jjdtd�|�t|jj�dd�|�|jjdddd	�Wd�n1s�0YdS)
NrArBrCr_rXrez(filterwarnings inserted duplicate filterrz>filterwarnings did not promote filter to the beginning of list)	rr6rr5r4rFr[r\rr'rrr�%test_filterwarnings_duplicate_filtersBs
��z1FilterTests.test_filterwarnings_duplicate_filterscCs�tj|jd���|j��|jjdtd�|�t|jj�d�|jjdtd�|jjdtd�|�t|jj�dd�|�|jjdddd	�Wd�n1s�0YdS)
NrArBrCr_rXre�&simplefilter inserted duplicate filterrz<simplefilter did not promote filter to the beginning of list)	rr6rr5rrFr[r\rr'rrr�#test_simplefilter_duplicate_filtersSs
��z/FilterTests.test_simplefilter_duplicate_filterscCs�tj|jdd��~}|j��|j�d�|jjddd�|jjddd�|jjdtd�|�t|jj	�dd	�|�t|�d
d�Wd�n1s�0YdS)NT�rrWrXrB�r��test_append_duplicaterCrer�rz+appended duplicate changed order of filters)
rr6rr5rr0rFr[r\rrHrrrr�cs�
��z!FilterTests.test_append_duplicateN)rrrr,rJrUr^rargrirorrrwr}r�r�r�r�r�r�r�r�rrrrr@bs&	
r@c@seZdZeZdS)�CFilterTestsNr;rrrrr�rsr�c@seZdZeZdS)�
PyFilterTestsNr>rrrrr�usr�c@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�	WarnTestsz2Test warnings.warn() and warnings.warn_explicit().cCs�tjd|jd��f}|j�d�td�D]@}d|}|j�|�|�t|dj�|�|�	|dj
t�q&Wd�n1s|0YdS)NTrVr�zmulti %drd)rr6rrrlr0r[r�rOr�rDrF)r(rIr�r�rrr�test_message}s�zWarnTests.test_messagec	CsztddfD]j}tjd|jd��F}|j�d�|j�|�|�t|dj�tt	|���Wd�q
1sj0Yq
dS)NruTrVrrd)
rrr6rrr0r[r�rOrF)r(ZobrIrrr�test_warn_nonstandard_types�s�z%WarnTests.test_warn_nonstandard_typesc	Cs�t|j���tjd|jd��X}t�d�|�tj�	|dj
�d�t�d�|�tj�	|dj
�d�Wd�n1sz0YWd�n1s�0YdS)NTrVZspam1rd�
stacklevel.pyZspam2�rrrr6r
�innerr[�os�path�basenameryZouterrHrrr�
test_filename�s�
�
�zWarnTests.test_filenamec	CsVt|j���4tjd|jd���}tjddd�|�tj�	|dj
�d�tjddd�|�tj�	|dj
�d�tjd	d
d�|�tj�	|dj
�d�tjdd
d�|�tj�	|dj
�d�tjd
dd�|�tj�	|dj
�d�tjddd�|�tj�	|dj
�d�Wd�n1�s(0YWd�n1�sH0YdS)NTrVZspam3r_rrdr�Zspam4Zspam5rertZspam6zspam6.5rhZspam7i'rr�rHrrr�test_stacklevel�s:�������zWarnTests.test_stacklevelc	Cs�t�d�t|j��vtjd|jd��F}|j�d�ddl}|�t	|�d�|�|dj
t�Wd�n1sr0YWd�n1s�0YdS)Nz&test.test_warnings.data.import_warningTrVrbrr_)rZunloadrrrr6rZ&test.test_warnings.data.import_warningr[r\ry�__file__)r(rI�testrrr�test_stacklevel_import�s
�z WarnTests.test_stacklevel_importcCsjd}td|d�}tjdd��(}|jjdtd�t|�Wd�n1sJ0Y|�|dj|�dS)	Nz<warnings-test>z3import warnings
warnings.warn('hello', UserWarning)�execT)rWrbrCr)	�compilerr6rrrFr�r[ry)r(ryZcodeobjrIrrr�test_exec_filename�s�&zWarnTests.test_exec_filenamec
Cs�tjd|jd��~}|j��|jjdtd�dD]N}zt�|�WntyXYq0Yn0|j�	dt|d�|�
|dj|�q0Wd�n1s�0YdS)	NTrVrbrC)u
nonasciié€usurrogate�r�r_rd)rr6rr5r4rFr��fsencode�UnicodeEncodeErrorr1r[ry)r(rIryrrr�%test_warn_explicit_non_ascii_filename�s�

z/WarnTests.test_warn_explicit_non_ascii_filenamec	CsT|�t|jjdtdd�|�t|jjdddd�|jttf|jjdtdddd�dS)Nr_ru��registry)rGr|rr1rFrrr'rrr�test_warn_explicit_type_errors�s��

�z(WarnTests.test_warn_explicit_type_errorscCsLGdd�dt�}|�t��|j�|��Wd�n1s>0YdS)Nc@seZdZdZdd�ZdS)z-WarnTests.test_bad_str.<locals>.BadStrWarningz-Warning with a bad format string for __str__.cSsdddiS)NzA bad formatted string %(err)�errzthere is no %(err)srr'rrr�__str__�s�z5WarnTests.test_bad_str.<locals>.BadStrWarning.__str__N)rrrr,r�rrrr�
BadStrWarning�sr�)rrGrmrr0)r(r�rrr�test_bad_str�szWarnTests.test_bad_strc	Cs*Gdd�dt�}Gdd�d�}|�t��}|j�dd�Wd�n1sL0Y|�dt|j��|�t��}|j�d|�Wd�n1s�0Y|�dt|j��|�t�� }|j�d|��Wd�n1s�0Y|�dt|j��tj	|jd���|j�
�|j�d	�|�|��}|j�d
|�Wd�n1�sV0Y|�
d
t|j��|�t��}|j�d
d�Wd�n1�s�0Y|�
d
t|j��|�|��}|j�d
|�Wd�n1�s�0Y|�|jt�Wd�n1�s0YdS)Nc@seZdZdS)z6WarnTests.test_warning_classes.<locals>.MyWarningClassNrrrrr�MyWarningClass�sr�c@seZdZdS)z:WarnTests.test_warning_classes.<locals>.NonWarningSubclassNrrrrr�NonWarningSubclass�sr�zbad warning categoryr�z)category must be a Warning subclass, not rArjzgood warning category)rrGr|rr0rSr�Z	exceptionrr6r5r4ZassertWarnsr[ZwarningrFZassertIsInstance)r(r�r��cmrrr�test_warning_classes�s:,�,�.�
...zWarnTests.test_warning_classesN)rrrr,r�r�r�r�r�r�r�r�r�r�rrrrr�ys


r�c@seZdZeZdd�ZdS)�
CWarnTestscCs&|�t|j�|�t|jjd��dS�N�__code__)�assertIsNotrr�assertFalser#r0r'rrr�test_accelerated#szCWarnTests.test_acceleratedN)rrrr<rr�rrrrr�sr�c@seZdZeZdd�ZdS)�PyWarnTestscCs&|�t|j�|�t|jjd��dSr�)r�rrr7r#r0r'rrr�test_pure_python,szPyWarnTests.test_pure_pythonN)rrrr?rr�rrrrr�'sr�c@seZdZdd�Zdd�ZdS)�
WCmdLineTestsc	Cs�tj|jd���\|�|jj|jjd�|�|jj|jjd�|�|jj|jjd�|�|jj��|j�d�Wd�n1s�0Y|�|jj��|j�d�Wd�n1s�0Y|�|jj��|j�d�Wd�n1s�0Y|�|jjd��|j�d	�Wd�n1�s60Y|j�d
�|�t|jjd�Wd�n1�st0YdS)NrAz1:2:3:4:5:6zbogus::Warningzignore:2::4:-5zignore::123zignore::123abczignore::===uWärninguignore::Wärningzerror::Warning::0r�)	rr6rrG�_OptionError�
_setoptionZassertRaisesRegexrFr0r'rrr�test_improper_input3s(
�
�
�***,z!WCmdLineTests.test_improper_inputc	Cs�tj|jd���|j�d�|�|jj��|j�d�Wd�n1sL0Y|�|jj��|j�d�Wd�n1s�0Y|j�d�|�t��|j�dt�Wd�n1s�0YWd�n1s�0YdS)NrAzignore::Warningzignore::TestWarningz ignore::test.test_warnings.bogusz%error::test.test_warnings.TestWarningztest warning)rr6rr�rGr�rr0r'rrr�test_import_from_moduleHs**z%WCmdLineTests.test_import_from_moduleN)rrrr�r�rrrrr�1sr�c@seZdZeZdS)�CWCmdLineTestsNr;rrrrr�Tsr�c@s eZdZeZdd�Zdd�ZdS)�PyWCmdLineTestscCs"tddd�\}}}|�d|�dS)Nz-Wxxx�-c�passs0Invalid -W option ignored: invalid action: 'xxx')rrS�r(�rc�outr�rrr�test_improper_option[sz$PyWCmdLineTests.test_improper_optioncCs0tddd�\}}}|�|���|�d|�dS)Nz-Wir�z?import sys; sys.modules['warnings'].warn('foo', RuntimeWarning)sRuntimeWarning)rr��strip�assertNotInr�rrr�test_warnings_bootstrapbs
�
z'PyWCmdLineTests.test_warnings_bootstrapN)rrrr?rr�r�rrrrr�Xsr�c@s�eZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zejdd��Zejdd��Zejdd��ZdS)�_WarningsTestsz'Tests specific to the _warnings module.cCsptj|jd��N}|j�ddtdd�|�t|jjd�|j`|�t|jjd�Wd�n1sb0YdS)NrArBr�rr�)	rr6rr4rrGrFr0rrHrrr�test_filterrs��z_WarningsTests.test_filtercCs2td�}�z|jj}iatjd|jd���}|j��|jjdtd�|j�|tdd�|�	|dj
|�|dd�=|j�|tdd�|�	t|�d	�i|j_ia|j�d�|�	|dj
j
|j
�|dd�=|j`ia|j�|tdd�|�	t|�d	�Wd�n1�s0YW||j_n
||j_0dS)
Nzonceregistry testTrVrrC�filerurdr)rFr�onceregistryrrr6r5r4r1r[rOr\r0rf)r(rOZoriginal_registryrIrrr�test_onceregistry|s2�


2z _WarningsTests.test_onceregistrycCsdtd�}|jj}�zBtjd|jd���}|j��i}|jj|tdd|d�|�|dj|�|�t	|�d�|�t	|�d	�|�
d
|�|dd�=|j`i}i}|jj|tdd|d�|�|dj|�|�t	|�d�|�t	|�d	�|dd�=d|j_i}i}|jj|tdd
|d�|�t	|�d�Wd�n1�s@0YW||j_n
||j_0dS)Nzdefaultaction testTrVz<test>rur�rdr_rerZ�+rX�,r)rFr�
defaultactionrr6r5r1r[rOr\rS)r(rOZoriginalrIr�rrrr�test_default_action�sF�
�
�
�2z"_WarningsTests.test_default_actionc	Cs�d}tj|jd��d|jjdtd�|j`t�d��$}|j�|�|�	�}Wd�n1s^0YWd�n1s|0Y|�
||�dS)Nzdel showwarning testrArbrCrT)rr6rr4rFr2r�captured_outputr0rRrS)r(r��stream�resultrrr�test_showwarning_missing�sDz'_WarningsTests.test_showwarning_missingc	Cs�d}tj|jd���|jjdtd�|jj}zP|j`t�d��$}|j�|�|�	�}Wd�n1sh0YW||j_n
||j_0Wd�n1s�0Y|�
||�dS)Nzdel _showwarnmsg testrArbrCrT)rr6rr4rF�_showwarnmsgrr�r0rRrS)r(r��showr�r�rrr�test_showwarnmsg_missing�s(2z'_WarningsTests.test_showwarnmsg_missingc	Cs�tj|jd��x|jjdtd�t|j_t�d��|j�	d�Wd�n1sT0Yd|j_|�
t|jj	d�Wd�n1s�0YdS)NrArbrC�stdoutzWarning!�)rr6rr4rF�printr2rr�r0rGr|r'rrr�test_showwarning_not_callable�s*z,_WarningsTests.test_showwarning_not_callablec
	CsBd}tj|jd��b|jjdtd�|j`t�d��"}t�	|�|�
�}Wd�n1s\0YWd�n1sz0Y|�|�d�dd|�|�
dd	�\}}tj�tj�d
d}|�dd
�}|\}}	}
}t|	�}	|�||�|�|
dtj�|�|d|�dt�||	���d}|�s2J�|�||�dS)Nztest show_warningrArbrCrT�
rezToo many newlines in %rr_r�.py�:rh� z  )rr6rr4rFr2rr�r
r�rRr[�count�splitr�r��splitextr��rsplit�intr�	linecache�getliner�)
r(r�r�r�Z
first_lineZsecond_lineZ
expected_fileZfirst_line_partsr��lineZ
warning_classrOZ
expected_linerrr�test_show_warning_output�s*
D�
z'_WarningsTests.test_show_warning_outputc	Cs�t�}|d}zrtjd|jd�}|�B}|jjdtd�d|d<t�dt�|�t|��Wd�n1sl0YW||d<n
||d<0dS)Nr�TrVrbrCr�)	r"rr6rr4rFr0r7r\)r(Zglobals_dictZoldfileZcatchrIrrr�test_filename_none�s�.z!_WarningsTests.test_filename_nonecCs8tdd�\}}}|�|d�|�d|�|�d|�dS)Nr�zjimport sys; sys.stderr = None; import warnings; warnings.simplefilter('always'); warnings.warn('Warning!')r�sWarning!sError)rr[r��r(r�r�rTrrr�test_stderr_none	s�
z_WarningsTests.test_stderr_nonec
Csdd�}|j}tj|d���|jdtd�t���.}|jdtdd|d	�d
d�d�Wd�n1sf0Y|�d
|�	��|j
}zf|`
t���0}|jdtdd|d	g�d
d�d�Wd�n1s�0Y|�d|�	��W||_
n||_
0Wd�n1�s0YdS)NcsG�fdd�d�}|�S)NcseZdZ�fdd�ZdS)zI_WarningsTests.test_issue31285.<locals>.get_bad_loader.<locals>.BadLoadercsG�fdd�dt�}|d�S)NcseZdZ�fdd�ZdS)zg_WarningsTests.test_issue31285.<locals>.get_bad_loader.<locals>.BadLoader.get_source.<locals>.BadSourcecs�SrLrr'��splitlines_ret_valrr�
splitlinesszr_WarningsTests.test_issue31285.<locals>.get_bad_loader.<locals>.BadLoader.get_source.<locals>.BadSource.splitlinesN)rrrr�rr�rr�	BadSourcesr�Zspam)r�)r(�fullnamer�r�rr�
get_sourceszT_WarningsTests.test_issue31285.<locals>.get_bad_loader.<locals>.BadLoader.get_sourceN)rrrr�rr�rr�	BadLoadersrr)r�rrr�r�get_bad_loadersz6_WarningsTests.test_issue31285.<locals>.get_bad_loaderrArjrC�foo�barr_ruZfoobar)�
__loader__rrzzUserWarning: fooZeggszUserWarning: eggs)rrr6r4rFrrQr1rSrRr�)r(r�wmodrTr�rrr�test_issue31285s0	
��$
��$z_WarningsTests.test_issue31285c
Cs�|j}tj|d���|�d�t�|dd��N|�t��$|jdt	dddd�Wd�n1sb0YWd�n1s�0YWd�n1s�0YdS)NrArr�rrr_r�)
rrr6r4r�	swap_attrrGr|r1r�r(rrrr�test_issue314116s
z_WarningsTests.test_issue31411c
Cs�|j}tj|d���ddtddfg|_|�t�� |�dtdd�Wd�n1sV0Yg|_t�	|dd��J|�t�� |�dtdd�Wd�n1s�0YWd�n1s�0YWd�n1s�0YdS)NrArrrr_r�)
rrr6rrrGr|r1rrrrrr�test_issue31416As.�z_WarningsTests.test_issue31416c
Cs�tj|jd���|jjdtd�t�t�dd��Rt�t�dd��"|�t|jj	d�Wd�n1sj0YWd�n1s�0YWd�n1s�0YdS)NrArBrCrsfoor�r)
rr6rr4rFrZ	swap_itemr"rGr0r'rrr�test_issue31566Ps�z_WarningsTests.test_issue31566N)rrrr,r<rr�r�r�r�r�r�r�r�r�rrZcpython_onlyr	r
rrrrrr�ls$
%		$


r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�WarningsDisplayTestsziTest the displaying of warnings and the ability to overload functions
    related to displaying warnings.c
Cs�d}t}tj�tj�dd}d}t�||���}d}||||j	||f}|�
||j�||||��|d7}||||j	||f}|�
||j�|||||��dS)Nrxrr�rhz%s:%s: %s: %s
  %s
z
 for the win!)
rr�r�r�r
r�r�r�r�rr[rr3)r(rOrD�	file_name�line_num�	file_line�format�expectrrr�test_formatwarning`s&����z'WarningsDisplayTests.test_formatwarningcCs�tj�tj�dd}d}t�||���}d}t}t	�}|j
�||||�}|j
�|||||�|�
|��|�|d7}|j
�|||||�}t	�}|j
�||||||�|�
||���dS)Nrr�rhrxzfor the win!)r�r�r�r
r�r�r�r�rrrr3r2r[rR)r(r
rZexpected_file_linerOrD�file_objectrrrr�test_showwarningrs,����z%WarningsDisplayTests.test_showwarningc		Cs�dd�}tj�tj�dd}d}t�||���}d}t}t	�}d|�d|�d	|�d
|��d|��}t
�|jd|��6|j�
||||||�|�|��|�Wd�n1s�0YdS)
Nc
Ss"d|�d|�d|�d|�d|��
S)N�m=�:c=�:f=�:l=�:t=r)rOrDry�linenor�rrr�myformatwarning�szIWarningsDisplayTests.test_formatwarning_override.<locals>.myformatwarningrr�rhrxrrrrrr3)r�r�r�r
r�r�r�r�rrrrrr2r[rR)	r(rr
rrrOrDr�expectedrrr�test_formatwarning_override�s��z0WarningsDisplayTests.test_formatwarning_overrideN)rrrr,rrrrrrrr[src@seZdZeZdS)�CWarningsDisplayTestsNr;rrrrr�src@seZdZeZdd�ZdS)�PyWarningsDisplayTestsc	Cs�|�tjtj�ttjd�� }|�t�d��Wd�n1sB0Ydd�}tj	�
tj�}|dtj�}t�d|�d����}|�||�|ddd	tj�}t�d|�d
|�d|�d����}|�||�dS)
NrIz�
                def func():
                    f = open(__file__)
                    # Emit ResourceWarning
                    f = None

                func()
            cWs<t|ddi�}|j�dd�}d�|���}t�dd|�}|S)N�PYTHONIOENCODING�utf-8�replacer�z<.*>z<...>)rr��decode�joinr��re�sub)rf�resrTrrr�run�s
z4PyWarningsDisplayTests.test_tracemalloc.<locals>.run�-Wdz
            z�:5: ResourceWarning: unclosed file <...>
              f = None
            ResourceWarning: Enable tracemalloc to get the object allocation traceback
        z-Xz
tracemalloc=2z�:5: ResourceWarning: unclosed file <...>
              f = None
            Object allocated at (most recent call last):
              File "z7", lineno 7
                func()
              File "z7", lineno 3
                f = open(__file__)
        )
Z
addCleanupr�unlinkZTESTFN�open�write�textwrap�dedentr�r��abspathr�r[)r(�fpr(ryrTrrrr�test_tracemalloc�s&.	
����	z'PyWarningsDisplayTests.test_tracemallocN)rrrr?rr1rrrrr�src@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�CatchWarningTestszTest catch_warnings().cCs�|j}|j}|j}|j|dd��t�|_|_Wd�n1sD0Y|�|j|�|�|j|�|j|dd��t�|_|_Wd�n1s�0Y|�|j|�|�|j|�dS�NTr�F)rrr2r6�objectr�)r(r�orig_filters�orig_showwarningrrr�test_catch_warnings_restore�s,,z-CatchWarningTests.test_catch_warnings_restorecCs.|j}|j|dd���}|�|g�|�t|�t�|�d�|�d�|�t|dj	�d�|�d�|�t|dj	�d�|�t|dj	�d�|�t|dj	�d�|dd�=|�|g�Wd�n1s�0Y|j
}|j|d	d��(}|�|�|�|j
|�Wd�n1�s 0YdS)
NTr�rbrrdrrr_F)rr6r[r��typer]rr0r�rOr2�assertIsNone)r(rrIr6rrr�test_catch_warnings_recording�s"



*
z/CatchWarningTests.test_catch_warnings_recordingcCs�|j}|j|dd�}|�t|j�|�|�t|j�Wd�n1sJ0Y|j|dd�}|�t|j�|�|�t|j�Wd�n1s�0YdSr3)rr6rG�RuntimeError�__exit__�	__enter__)r(rrnrrr�!test_catch_warnings_reentry_guard�s,z3CatchWarningTests.test_catch_warnings_reentry_guardcCs�|j}|j}|j}|j|d��6}|�|�|�|j|�|�|j|�Wd�n1sZ0Y|�|j|�|tjdur�|���6}|�|�|�|j|�|�|j|�Wd�n1s�0Y|�|j|�dS)NrAr	)	rrr2r6r9r�r�rr$)r(rr5r6rIrrr�test_catch_warnings_defaultss
,

,z.CatchWarningTests.test_catch_warnings_defaultsc	s�d}|j}g�d
�fdd�	}t�|d|��n|j|dd��2}|�|j|�|�d�|�|�Wd�n1sr0Y|�|j|�Wd�n1s�0Y|�	t
|�d|�|�	|d	jjd	|�|�	�g�dS)N�This is a warningcs��|�dSrLr��rOrDryrr�r��Zmy_logrr�	my_loggerszLCatchWarningTests.test_record_override_showwarning_before.<locals>.my_loggerr2Tr�rbr_r)NN)
rrrr6r�r2rr0r�r[r\rOrf�r(r�rrC�logrrBr�'test_record_override_showwarning_befores
(,z9CatchWarningTests.test_record_override_showwarning_beforecs�d}|j}g�d	�fdd�	}|j|dd��*}|�d�||_|�|�Wd�n1sZ0Y|�t��d��|��djd|�|�|g�dS)
Nr@cs��|�dSrLr�rArBrrrC6szLCatchWarningTests.test_record_override_showwarning_inside.<locals>.my_loggerTr�rbr_r)NN)rr6rr2r0r[r\rfrDrrBr�'test_record_override_showwarning_inside/s
(z9CatchWarningTests.test_record_override_showwarning_insidec	Cs|j}|tjdur|�d�tjdd���}|�|jg�|�d�|�	d�|�t
|j�d�|�	d�|�t
|j�d�|�t
|jdj�d�|�t
|jd	j�d�|��|�|jg�Wd�n1s�0Yt���Wd�n1s�0Yt�dt
f��|�	d�Wd�n1�s80Y|�t��@t�d
tf��Wd�n1�st0YWd�n1�s�0Y|�t��Jt�dtf��|�	d�Wd�n1�s�0YWd�n1�s�0YdS)Nr	z,module to test is not loaded warnings moduleF)�quietrbrrrr_r�)rrr$ZskipTestrZcheck_warningsr[r	rr0r�rO�resetrFrG�AssertionError�RuntimeWarning)r(rrIrrr�test_check_warningsCs0



,
*@z%CatchWarningTests.test_check_warningsN)rrrr,r7r:r>r?rFrGrLrrrrr2�s
r2c@seZdZeZdS)�CCatchWarningTestsNr;rrrrrMbsrMc@seZdZeZdS)�PyCatchWarningTestsNr>rrrrrNesrNc@sPeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�	e
��dkd�d
d��ZdS)�EnvironmentVariableTestscCs&tddddd�\}}}|�|d�dS)Nr��2import sys; sys.stdout.write(str(sys.warnoptions))�ignore::DeprecationWarningr���PYTHONWARNINGS�
PYTHONDEVMODEs['ignore::DeprecationWarning']�rr[r�rrr�test_single_warningks�z,EnvironmentVariableTests.test_single_warningcCs&tddddd�\}}}|�|d�dS)Nr�rPz1ignore::DeprecationWarning,ignore::UnicodeWarningr�rR�8['ignore::DeprecationWarning', 'ignore::UnicodeWarning']rUr�rrr�test_comma_separated_warningsrs��z6EnvironmentVariableTests.test_comma_separated_warningscCs(tdddddd�\}}}|�|d�dS)Nz-Wignore::UnicodeWarningr�rPrQr�rRrWrUr�rrr�test_envvar_and_command_linezs��z5EnvironmentVariableTests.test_envvar_and_command_linecCs<tdddddd�\}}}|�|d�|�|��gd��dS)	Nz-Werror::DeprecationWarningr�zjimport sys, warnings; sys.stdout.write(str(sys.warnoptions)); warnings.warn('Message', DeprecationWarning)zdefault::DeprecationWarningr�rRs<['default::DeprecationWarning', 'error::DeprecationWarning'])s"Traceback (most recent call last):s&  File "<string>", line 1, in <module>sDeprecationWarning: Message)rr[r�r�rrr�(test_conflicting_envvar_and_command_line�s��
�zAEnvironmentVariableTests.test_conflicting_envvar_and_command_linec
	Cs�|jtu}trg}nT|r$t�d�}nd}ddt|dfddtddfddtddfddtddfddtddfg}dd�|D�}|r�d}nd}|d	7}t	d
|dd�\}}}d
d�|�
�D�}	d|_|�|	|�dS)N�__main__rjrrXcSsg|]}t|����qSr)r��encode)r�rPrrrr��r�zNEnvironmentVariableTests.test_default_filter_configuration.<locals>.<listcomp>zPimport sys; sys.modules.pop('warnings', None); sys.modules['_warnings'] = None; r�z5import warnings; [print(f) for f in warnings.filters]r�T)Z
__isolatedcSsg|]}|���qSr)r�)r�r�rrrr��r�)
rr?�Py_DEBUGr%r��DeprecationWarning�PendingDeprecationWarning�
ImportWarning�ResourceWarningrr�ZmaxDiffr[)
r(Zpure_python_apiZexpected_default_filtersZmain_module_filterZexpected_output�coder�r�rTZstdout_linesrrr�!test_default_filter_configuration�s*
�z:EnvironmentVariableTests.test_default_filter_configuration�asciiz%requires non-ascii filesystemencodingcCs<dtj}tddd|dd�\}}}|�|t|g����dS)Nzignore:DeprecationWarningr�rPr!r�)r rSrT)rZFS_NONASCIIrr[r�r\)r(rSr�r�rTrrr�
test_nonascii�s
�z&EnvironmentVariableTests.test_nonasciiN)
rrrrVrXrYrZrcrZ
skipUnlessr�getfilesystemencodingrerrrrrOis
�rOc@seZdZeZdS)�CEnvironmentVariableTestsNr;rrrrrg�srgc@seZdZeZdS)�PyEnvironmentVariableTestsNr>rrrrrh�srhc@seZdZdd�ZdS)�
BootstrapTestc	Csvt���Z}t�d��0tdd|d�tdddd|d�Wd�n1sJ0YWd�n1sh0YdS)NZ	encodingsr�r�)Z
PYTHONPATHz-Wrb)rZtemp_cwdr)r(�cwdrrr�test_issue_8766�szBootstrapTest.test_issue_8766N)rrrrkrrrrri�sric@seZdZdd�Zdd�ZdS)�FinalizationTestcCs,d}td|�\}}}|�|����d�dS)Nzk
import warnings
warn = warnings.warn

class A:
    def __del__(self):
        warn("test")

a=A()
        r�z<string>:7: UserWarning: test)rr[r#�rstrip)r(rbr�r�r�rrr�test_finalization�s

�z"FinalizationTest.test_finalizationcCshd}dt}tdd|�\}}}|�|�|�t|��dt}tdd|�\}}}|�|�|�t|��dS)Ns&sys:1: ResourceWarning: unclosed file zf = open(%a)r)r�zimport warnings; f = open(%a))r�rr7�
startswithrd)r(rrbr�r�r�rrr�test_late_resource_warning�sz+FinalizationTest.test_late_resource_warningN)rrrrnrprrrrrl�srlcCstj��tj��dSrL)r?r�rr<rrrr�setUpModule�s
rqr[):�
contextlibrr�r��iorr%rr-rr�rZtest.support.script_helperrrZtest.test_warnings.datarr
r	rZimport_fresh_moduler?r<r#r]rrrrr.ZTestCaser:r=r@r�r�r�r�r�r�r�r�r�rrrr2rMrNrOrgrhrirlrqZtearDownModuler�mainrrrr�<module>sf

&	
#p@1P
$