Your IP : 216.73.216.213


Current Path : /opt/alt/python36/lib64/python3.6/test/test_warnings/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/test/test_warnings/__pycache__/__init__.cpython-36.pyc

3

� f���@s�ddlmZddlZddlZddlmZddlZddlZddlZddl	Z	ddl
mZddlm
Z
mZddlmZddlZejddgd	�Zejddgd
�Zedd��ZGd
d�d�ZGdd�de�ZGdd�dee	j�ZGdd�dee	j�ZGdd�de�ZGdd�dee	j�ZGdd�dee	j�ZGdd�de�Z Gdd�de e	j�Z!Gdd �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(Gd-d.�d.e'e	j�Z)Gd/d0�d0e�Z*Gd1d2�d2e*e	j�Z+Gd3d4�d4e*e	j�Z,Gd5d6�d6e�Z-Gd7d8�d8e-e	j�Z.Gd9d:�d:e-e	j�Z/Gd;d<�d<e	j�Z0Gd=d>�d>e	j�Z1d?d@�Z2e2Z3e4dAk�r�e	j5�dS)B�)�contextmanagerN)�StringIO)�support)�assert_python_ok�assert_python_failure)�
stacklevel�warnings�	_warnings)Zblocked)Zfreshccs�x4ttfD](}y|jj�Wq
tk
r0Yq
Xq
Wytj�Wntk
rVYnXtj}|j}z(|dd�|_|jd�|t_dVWd|t_||_XdS)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/python36/lib64/python3.6/test/test_warnings/__init__.py�warnings_states$


rcs,eZdZdZ�fdd�Z�fdd�Z�ZS)�BaseTestz'Basic bookkeeping required for testing.cs`tjj|_dt�krt�d=ttd�r*t`ttd�r8t`|j	tj
d<|j	tj_tt|�j
�dS)Nr
r)�unittest�caser�old_unittest_module�globals�hasattrrr
rr�modules�superr�setUp)�self)�	__class__rrr 0s




zBaseTest.setUpcs&ttjd<|jtj_tt|�j	�dS)Nr)
rrrrrrrrr�tearDown)r!)r"rrr#Cs

zBaseTest.tearDown)�__name__�
__module__�__qualname__�__doc__r r#�
__classcell__rr)r"rr,src@seZdZdZdd�ZdS)�PublicAPITestszGEnsures that the correct values are exposed in the
    public API.
    cCsB|jt|jd��dddddddd	g}|jt|jj�t|��dS)
N�__all__�warn�
warn_explicit�showwarning�
formatwarning�filterwarningsr�
resetwarnings�catch_warnings)�
assertTruerrZassertSetEqual�setr*)r!Z
target_apirrr�test_module_all_attributeNsz(PublicAPITests.test_module_all_attributeN)r$r%r&r'r4rrrrr)Hsr)c@seZdZeZdS)�CPublicAPITestsN)r$r%r&�
c_warningsrrrrrr5Vsr5c@seZdZeZdS)�PyPublicAPITestsN)r$r%r&�py_warningsrrrrrr7Ysr7c@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$S)%�FilterTestsz$Testing the filtering functionality.cCsJtj|jd��2}|jj�|jjdtd�|jt|jjd�WdQRXdS)N)r�error)�categoryzFilterTests.test_error)rr1rr0r/�UserWarning�assertRaisesr+)r!�wrrr�
test_error`s

zFilterTests.test_errorcs�tj�jd��x}�jj�d���fdd�}tj��}|�WdQRX|j�}�jd|��jd|��jjdt	d��j
t	|�WdQRXdS)	N)rz%FilterTests.test_ignore_after_defaultcs�jj�t�dS)N)rr+r<r)�messager!rr�fksz/FilterTests.test_error_after_default.<locals>.fz2UserWarning: FilterTests.test_ignore_after_defaultz&self.module.warn(message, UserWarning)r:)r;)rr1rr0r�captured_stderr�getvalue�assertInr/r<r=)r!r>rA�stderrr)r@r!r�test_error_after_defaultgs

z$FilterTests.test_error_after_defaultcCsXtjd|jd��>}|jj�|jjdtd�|jjdt�|jt|�d�WdQRXdS)NT)�recordr�ignore)r;zFilterTests.test_ignorer)	rr1rr0r/r<r+�assertEqual�len)r!r>rrr�test_ignoreys
zFilterTests.test_ignorecsntjd�jd��T}�jj�d���fdd�}|��jjdtd�|�|��jt|�d�WdQRXdS)	NT)rGrz%FilterTests.test_ignore_after_defaultcs�jj�t�dS)N)rr+r<r)r@r!rrrA�sz0FilterTests.test_ignore_after_default.<locals>.frH)r;�)rr1rr0r/r<rIrJ)r!r>rAr)r@r!r�test_ignore_after_default�s
z%FilterTests.test_ignore_after_defaultcs�tjd�jd���}�jj��jjdtd�d���fdd�}|��jt|�d��j|djj	d	��|��jt|�d
��j|djj	d	��WdQRXdS)
NT)rGr�always)r;zFilterTests.test_alwayscs�jj�t�dS)N)rr+r<r)r@r!rrrA�sz"FilterTests.test_always.<locals>.frLr����rP)
rr1rr0r/r<rIrJr@�args)r!r>rAr)r@r!r�test_always�s
zFilterTests.test_alwayscs�tjd�jd���}�jj�d���fdd�}|��jt|�d��j|djjd��|��jt|�d��jjdt	d	�|��jt|�d
��j|d
jjd��|��jt|�d��j|djjd��WdQRXdS)NT)rGrz$FilterTests.test_always_after_ignorecs�jj�t�dS)N)rr+r<r)r@r!rrrA�sz0FilterTests.test_always_after_default.<locals>.frLrrN)r;rO�rPrPrP)
rr1rr0rIrJr@rQr/r<)r!r>rAr)r@r!r�test_always_after_default�s"
z%FilterTests.test_always_after_defaultcCs�tjd|jd���}|jj�|jjdtd�td�}xftd�D]Z}|jj|t�|dkrv|j|d
j	|�|dd�=q>|dkr�|jt
|�d�q>td	��q>WWdQRXdS)NT)rGr�default)r;zFilterTests.test_defaultrOrrLzloop variant unhandledrP)rr1rr0r/r<�ranger+rIr@rJ�
ValueError)r!r>r@�xrrr�test_default�s
zFilterTests.test_defaultcCs�tjd|jd��p}|jj�|jjdtd�td�}|jj|t�|j|dj|�|dd�=|jj|t�|jt	|�d�WdQRXdS)	NT)rGrr)r;zFilterTests.test_modulerLrrP)
rr1rr0r/r<r+rIr@rJ)r!r>r@rrr�test_module�s

zFilterTests.test_modulecCs�tjd|jd���}|jj�|jjdtd�td�}|jj|tdd�|j|dj|�|dd�=|jj|tdd	�|jt	|�d
�|jj|tdd�|jt	|�d
�WdQRXdS)
NT)rGrr
)r;zFilterTests.test_oncez__init__.py�*rL�
rztest_warnings2.pyrP)
rr1rr0r/r<r,rIr@rJ)r!r>r@rrr�	test_once�s

zFilterTests.test_oncecCsLtj|jd��4}|jj�|jjdtd�|jt|jjdt�WdQRXdS)N)rr:)r;zFilterTests.test_inheritance)	rr1rr0r/�Warningr=r<r+)r!r>rrr�test_inheritance�s

zFilterTests.test_inheritancecCs�tjd|jd��~}|jj�|jjdtd�|jjdtdd�|dd�=y|jjdt�Wntk
rx|jd�YnX|jt	|�d	�WdQRXdS)
NT)rGrrH)r;r:)r;�appendzFilterTests.test_orderingz!order handling for actions failedr)
rr1rr0r/r<r+ZfailrIrJ)r!r>rrr�
test_ordering�s


zFilterTests.test_orderingc
Cs0tjd|jd���}|jjddtdd�|jt|jjd�|jj�d}|jj|�|j	t
|dj�|�|j|dj
tk�|jjd	dtdd�d
}|jj|�|jt
|dj�|�|jj�|jjddtdd�|jt|jjd�d
}|jj|�|j	t
|dj�|�|j|dj
tk�WdQRXdS)NT)rGrr:�rzconvert to errorzhandle normallyrLrHzfiltered outzhex*zhex/octznonmatching textrPrPrPrPrP)rr1rr/r^r=r<r+r0rI�strr@r2r;ZassertNotEqual)r!r>�textrrr�test_filterwarnings�s(

zFilterTests.test_filterwarningscCs�tjd|jd��x}|jjdt�|jjddt�|jt|jjd�|jt|jjd�|jjd�|j|g�|jjd�|j|g�WdQRXdS)	NT)rGrrHr:�matchzmatch prefixzsuffix matchzsomething completely different)	rr1rrr<r/r=r+rI)r!r>rrr�test_message_matchingsz!FilterTests.test_message_matchingcs|G�fdd�d���fdd�td�D��tjd|jd��:}�|j_|jjtd�dd	d
�|jt|dj	�d�WdQRXdS)
NcseZdZ�fdd�ZdS)z.FilterTests.test_mutate_filter_list.<locals>.Xcsg�dd�<dS)Nr)r!�a)�Lrrrfsz4FilterTests.test_mutate_filter_list.<locals>.X.matchN)r$r%r&rfr)rirr�Xsrjcsg|]}d��t��df�qS)rUr)r<)�.0�i)rjrr�
<listcomp>sz7FilterTests.test_mutate_filter_list.<locals>.<listcomp>rOT)rGr�bzf.pyr[rLrP)
rVrr1rrr,r<rIrcr@)r!r>r)rirjr�test_mutate_filter_listsz#FilterTests.test_mutate_filter_listcCs�tj|jd���|jj�|jjdtd�|jt|jj�d�|jjdtd�|jjdtd�|jt|jj�dd�|j|jjdddd	�WdQRXdS)
N)rr:)r;rLrHrOz(filterwarnings inserted duplicate filterrz>filterwarnings did not promote filter to the beginning of list)	rr1rr0r/r<rIrJr)r!rrr�%test_filterwarnings_duplicate_filters&s
z1FilterTests.test_filterwarnings_duplicate_filterscCs�tj|jd���|jj�|jjdtd�|jt|jj�d�|jjdtd�|jjdtd�|jt|jj�dd�|j|jjdddd	�WdQRXdS)
N)rr:)r;rLrHrOz&simplefilter inserted duplicate filterrz<simplefilter did not promote filter to the beginning of list)	rr1rr0rr<rIrJr)r!rrr�#test_simplefilter_duplicate_filters7s
z/FilterTests.test_simplefilter_duplicate_filterscCs�tj|jdd��t}|jj�|jjd�|jjddd�|jjddd�|jjdtd�|jt|jj	�dd	�|jt|�d
d�WdQRXdS)NT)rrGrHr:)r`�test_append_duplicate)r;rOz&simplefilter inserted duplicate filterrz+appended duplicate changed order of filters)
rr1rr0rr+r<rIrJr)r!r>rrrrrFs

z!FilterTests.test_append_duplicateN)r$r%r&r'r?rFrKrMrRrTrYrZr]r_rarergrorprqrrrrrrr9\s$
r9c@seZdZeZdS)�CFilterTestsN)r$r%r&r6rrrrrrsUsrsc@seZdZeZdS)�
PyFilterTestsN)r$r%r&r8rrrrrrtXsrtc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
jee
d�d�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�	WarnTestsz2Test warnings.warn() and warnings.warn_explicit().cCs|tjd|jd��b}|jjd�xNtd�D]B}d|}|jj|�|jt|dj�|�|j	|dj
tk�q(WWdQRXdS)	NT)rGrr
�zmulti %drLrPrP)rr1rrrVr+rIrcr@r2r;r<)r!r>rlrdrrr�test_message`szWarnTests.test_messagec
CsjxdtddfD]V}tjd|jd��<}|jjd�|jj|�|jt|dj�tt	|���WdQRXqWdS)Nr[T)rGrr
rLrP)
r^rr1rrr+rIrcr@r<)r!�obr>rrr�test_warn_nonstandard_typesksz%WarnTests.test_warn_nonstandard_typescCs~t|j��jtjd|jd��N}tjd�|jtjj	|dj
�d�tjd�|jtjj	|dj
�d�WdQRXWdQRXdS)	NT)rGrZspam1rLz
stacklevel.pyZspam2rPrP)rrrr1r�innerrI�os�path�basename�filename�outer)r!r>rrr�
test_filenamevs

zWarnTests.test_filenamecCs*t|j���tjd|jd����}tjddd�|jtjj	|dj
�d�tjddd�|jtjj	|dj
�d�tjdd	d�|jtjj	|dj
�d
�tjdd	d�|jtjj	|dj
�d�tjdd
d�|jtjj	|dj
�d
�tjddd�|jtjj	|dj
�d�WdQRXWdQRXdS)NT)rGrZspam3rL)rz
stacklevel.pyZspam4Zspam5rOz__init__.pyZspam6zspam6.5rSZspam7i'rrPrPrPrPrPrP)rrrr1rrzrIr{r|r}r~r)r!r>rrr�test_stacklevel�s*zWarnTests.test_stacklevelcCsvtjd�t|j��Xtjd|jd��<}|jjd�ddl}|jt	|�d�|j|dj
t�WdQRXWdQRXdS)Nz&test.test_warnings.data.import_warningT)rGrrNrrL)rZunloadrrrr1rZ&test.test_warnings.data.import_warningrIrJr~�__file__)r!r>�testrrr�test_stacklevel_import�s
z WarnTests.test_stacklevel_importcCsptj}z\t`t|j��Dtjd|jd��(}tjddd�|j|djtj	�WdQRXWdQRXWd|t_XdS)NT)rGrZspam8rL)rrP)
rr�rrrr1rzrIr~r$)r!r~r>rrr�test_missing_filename_not_main�s,z(WarnTests.test_missing_filename_not_main�argvztest needs sys.argvcCs�tj}tj}zft`dt_t|j��Htjd|jd��,}tjddd�|j|dj	t
jd�WdQRXWdQRXWd|t_|t_XdS)	N�__main__T)rGrZspam9rL)rrrP)rr�r$rrrr1rzrIr~rr�)r!r~�module_namer>rrr�$test_missing_filename_main_with_argv�s0z.WarnTests.test_missing_filename_main_with_argvcCs�tj}tj}tj}zdt`dt_t`t|j��Btjd|jd��&}tj	ddd�|j
|djd�WdQRXWdQRXWd|t_|t_|t_XdS)Nr�T)rGrZspam10rL)rrP)rr�r$rr�rrrr1rzrIr~)r!r~r�r�r>rrr�'test_missing_filename_main_without_argv�s*z1WarnTests.test_missing_filename_main_without_argvcCs�tj}tj}tj}zht`dt_dgt_t|j��Btjd|jd��&}tj	ddd�|j
|djd�WdQRXWdQRXWd|t_|t_|t_XdS)	Nr�rbT)rGrZspam11rL)rrP)rr�r$rr�rrrr1rzrIr~)r!�	file_namer�r�r>rrr�1test_missing_filename_main_with_argv_empty_string�s*z;WarnTests.test_missing_filename_main_with_argv_empty_stringcCs�tjd|jd��x}|jj�|jjdtd�xVd	D]N}ytj|�Wntk
rZw2YnX|jj	dt|d�|j
|d
j|�q2WWdQRXdS)NT)rGrrN)r;�
nonascii�surrogate�rdrL)r�r�rP)rr1rr0r/r<r{�fsencode�UnicodeEncodeErrorr,rIr~)r!r>r~rrr�%test_warn_explicit_non_ascii_filename�s

z/WarnTests.test_warn_explicit_non_ascii_filenamec	CsT|jt|jjdtdd�|jt|jjdddd�|jttf|jjdtdddd�dS)NrLr[)�registry)r=�	TypeErrorrr,r<rr^)r!rrr�test_warn_explicit_type_errors�s
z(WarnTests.test_warn_explicit_type_errorsc	Cs8Gdd�dt�}|jt��|jj|��WdQRXdS)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)sr)r!rrr�__str__sz5WarnTests.test_bad_str.<locals>.BadStrWarning.__str__N)r$r%r&r'r�rrrr�
BadStrWarningsr�)r^r=rWrr+)r!r�rrr�test_bad_strszWarnTests.test_bad_strc4Cs�Gdd�dt�}Gdd�d�}|jt��}|jjdd�WdQRX|jdt|j��|jt��}|jjd|�WdQRX|jdt|j��|jt��}|jjd|��WdQRX|jdt|j��tj	|jd���|jj
�|jjd	�|j|��}|jjd
|�WdQRX|j
d
t|j��|jt��}|jjd
d�WdQRX|j
d
t|j��|j|��}|jjd
|�WdQRX|j|jt�WdQRXdS)Nc@seZdZdS)z6WarnTests.test_warning_classes.<locals>.MyWarningClassN)r$r%r&rrrr�MyWarningClasssr�c@seZdZdS)z:WarnTests.test_warning_classes.<locals>.NonWarningSubclassN)r$r%r&rrrr�NonWarningSubclasssr�zbad warning categoryrbz)category must be a Warning subclass, not )rrUzgood warning category)r^r=r�rr+rDrcZ	exceptionrr1r0r/ZassertWarnsrIZwarningr<ZassertIsInstance)r!r�r��cmrrr�test_warning_classess4
zWarnTests.test_warning_classesN)r$r%r&r'rwryr�r�r�r�r�
skipUnlessrrr�r�r�r�r�r�r�rrrrru\s

ruc@seZdZeZdd�ZdS)�
CWarnTestscCs(|jt|jk�|jt|jjd��dS)N�__code__)�assertFalserrrr+)r!rrr�test_acceleratedEszCWarnTests.test_acceleratedN)r$r%r&r6rr�rrrrr�@sr�c@seZdZeZdd�ZdS)�PyWarnTestscCs(|jt|jk�|jt|jjd��dS)Nr�)r�rrr2rr+)r!rrr�test_pure_pythonNszPyWarnTests.test_pure_pythonN)r$r%r&r8rr�rrrrr�Isr�c@seZdZdd�ZdS)�
WCmdLineTestscCs~tj|jd��f|j|jj|jjd�|j|jj|jjd�|j|jj|jjd�|jjd�|jt|jjd�WdQRXdS)N)rz1:2:3:4:5:6zbogus::Warningzignore:2::4:-5zerror::Warning::0zconvert to error)rr1rr=�_OptionError�
_setoptionr<r+)r!rrr�test_improper_inputUs


z!WCmdLineTests.test_improper_inputN)r$r%r&r�rrrrr�Ssr�c@seZdZeZdS)�CWCmdLineTestsN)r$r%r&r6rrrrrr�csr�c@s eZdZeZdd�Zdd�ZdS)�PyWCmdLineTestscCs"tddd�\}}}|jd|�dS)Nz-Wxxxz-c�passs0Invalid -W option ignored: invalid action: 'xxx')rrD)r!�rc�outr�rrr�test_improper_optionjsz$PyWCmdLineTests.test_improper_optioncCs0tddd�\}}}|j|j��|jd|�dS)Nz-Wiz-cz?import sys; sys.modules['warnings'].warn('foo', RuntimeWarning)sRuntimeWarning)rr��strip�assertNotIn)r!r�r�r�rrr�test_warnings_bootstrapqsz'PyWCmdLineTests.test_warnings_bootstrapN)r$r%r&r8rr�r�rrrrr�gsr�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.c
Cs\tj|jd��D}|jjddtdd�|jt|jjd�|j`|jt|jjd�WdQRXdS)N)rr:rbrzconvert to error)	rr1rr/r^r=r<r+r)r!r>rrr�test_filter�sz_WarningsTests.test_filtercCstd�}z�|jj}iatjd|jd���}|jj�|jjdtd�|jj|tdd�|j	|d
j
|�|dd�=|jj|tdd�|j	t|�d	�i|j_ia|jjd�|j	|dj
j
|j
�|dd�=|j`ia|jj|tdd�|j	t|�d	�WdQRXWd||j_XdS)Nzonceregistry testT)rGrr
)r;�filer[rLrrPrP)r<r�onceregistryr
rr1r0r/r,rIr@rJr+rQ)r!r@Zoriginal_registryr>rrr�test_onceregistry�s.


z _WarningsTests.test_onceregistrycCsFtd�}|jj}�z$tjd|jd���}|jj�i}|jj|tdd|d�|j|dj|�|jt	|�d�|jt	|�d�|j
d	|�|dd�=|j`i}i}|jj|tdd
|d�|j|dj|�|jt	|�d�|jt	|�d�|dd�=d|j_i}i}|jj|tdd|d�|jt	|�d
�WdQRXWd||j_XdS)Nzdefaultaction testT)rGrz<test>r[)r�rLrO�version�+rH�,rrPrP)r<r�
defaultactionrr1r0r,rIr@rJrD)r!r@Zoriginalr>r�r
rrr�test_default_action�s<


z"_WarningsTests.test_default_actioncCsnd}tj|jd��F|jjdtd�|j`tjd��}|jj|�|j	�}WdQRXWdQRX|j
||�dS)Nzdel showwarning test)rrN)r;rE)rr1rr/r<r-r�captured_outputr+rCrD)r!rd�stream�resultrrr�test_showwarning_missing�sz'_WarningsTests.test_showwarning_missingcCs�d}tj|jd��^|jjdtd�|jj}z4|j`tjd��}|jj|�|j	�}WdQRXWd||j_XWdQRX|j
||�dS)Nzdel _showwarnmsg test)rrN)r;rE)rr1rr/r<�_showwarnmsgrr�r+rCrD)r!rd�showr�r�rrr�test_showwarnmsg_missing�sz'_WarningsTests.test_showwarnmsg_missingcCsrtj|jd��Z|jjdtd�t|j_tjd��|jj	d�WdQRXd|j_|j
t|jj	d�WdQRXdS)N)rrN)r;�stdoutzWarning!�)rr1rr/r<�printr-rr�r+r=r�)r!rrr�test_showwarning_not_callable�sz,_WarningsTests.test_showwarning_not_callablec
Csd}tj|jd��D|jjdtd�|j`tjd��}tj	|�|j
�}WdQRXWdQRX|j|jd�dd|�|j
dd	�\}}tjjtj�d
d}|jdd
�}|\}}	}
}t|	�}	|j||�|j|
dtj�|j|d|�dtj||	�j�d}|�s
t�|j||�dS)Nztest show_warning)rrN)r;rE�
rOzToo many newlines in %rrLrz.py�:rS� z  )rr1rr/r<r-rr�rrzrCrI�count�splitr{r|�splitextr��rsplit�intr$�	linecache�getliner��AssertionError)
r!rdr�r�Z
first_lineZsecond_lineZ
expected_fileZfirst_line_partsr|�lineZ
warning_classr@Z
expected_linerrr�test_show_warning_output�s(


z'_WarningsTests.test_show_warning_outputcCstt�}|d}zVtjd|jd�}|�8}|jjdtd�d|d<tjdt�|jt|��WdQRXWd||d<XdS)Nr�T)rGrrN)r;r�)	rrr1rr/r<r+r2rJ)r!Zglobals_dictZoldfileZcatchr>rrr�test_filename_none	s
z!_WarningsTests.test_filename_nonecCs8tdd�\}}}|j|d�|jd|�|jd|�dS)Nz-czjimport sys; sys.stderr = None; import warnings; warnings.simplefilter('always'); warnings.warn('Warning!')�sWarning!sError)rrIr�)r!r�r�rErrr�test_stderr_nones
z_WarningsTests.test_stderr_nonec#Cs�dd�}|j}tj|d���|jdtd�tj��$}|jdtdd|d	�d
d�d�WdQRX|jd
|j	��|j
}zL|`
tj��&}|jdtdd|d	g�d
d�d�WdQRX|jd|j	��Wd||_
XWdQRXdS)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�S)Nr)r!)�splitlines_ret_valrr�
splitlines)szr_WarningsTests.test_issue31285.<locals>.get_bad_loader.<locals>.BadLoader.get_source.<locals>.BadSource.splitlinesN)r$r%r&r�r)r�rr�	BadSource(sr�Zspam)rc)r!�fullnamer�)r�rr�
get_source'szT_WarningsTests.test_issue31285.<locals>.get_bad_loader.<locals>.BadLoader.get_sourceN)r$r%r&r�r)r�rr�	BadLoader&sr�r)r�r�r)r�r�get_bad_loader%sz6_WarningsTests.test_issue31285.<locals>.get_bad_loader)rrU)r;�foo�barrLr[Zfoobar)�
__loader__r$)�module_globalszUserWarning: fooZeggszUserWarning: eggs)rrr1r/r<rrBr,rDrCr�)r!r��wmodrEr�rrr�test_issue31285!s(	

z_WarningsTests.test_issue31285cCsp|j}tj|d��T|jd�tj|dd��0|jt��|jdt	dddd�WdQRXWdQRXWdQRXdS)N)rr
r�r�r�rL)r�)
rrr1r/r�	swap_attrr=r�r,r^)r!r�rrr�test_issue31411Es
z_WarningsTests.test_issue31411c!Cs�|j}tj|d���ddtddfg|_|jt��|jdtdd�WdQRXg|_tj	|dd��,|jt��|jdtdd�WdQRXWdQRXWdQRXdS)N)rrr�r�rLr�)
rrr1r^rr=r�r,rr�)r!r�rrr�test_issue31416Psz_WarningsTests.test_issue31416cCsxtj|jd��`|jjdtd�tjt�dd��4tjt�dd��|jt|jj	d�WdQRXWdQRXWdQRXdS)N)rr:)r;r$sfoor�r�)
rr1rr/r<rZ	swap_itemrr=r+)r!rrr�test_issue31566_s
z_WarningsTests.test_issue31566N)r$r%r&r'r6rr�r�r�r�r�r�r�r�r�r�rZcpython_onlyr�r�r�rrrrr�{s
%		$r�c@s eZdZdZdd�Zdd�ZdS)�WarningsDisplayTestsziTest the displaying of warnings and the ability to overload functions
    related to displaying warnings.cCs�d}t}tjjtj�dd}d}tj||�j�}d}||||j	||f}|j
||jj||||��|d7}||||j	||f}|j
||jj|||||��dS)N�msgrz.pyrSz%s:%s: %s: %s
  %s
z
 for the win!)
r^r{r|r�rr�r�r�r�r$rIrr.)r!r@r;r��line_numZ	file_line�format�expectrrr�test_formatwarningosz'WarningsDisplayTests.test_formatwarningcCs�tjjtj�dd}d}tj||�j�}d}t}t	�}|j
j||||�}|j
j|||||�|j
|j�|�|d7}|j
j|||||�}t	�}|j
j||||||�|j
||j��dS)Nrz.pyrSr�zfor the win!)r{r|r�rr�r�r�r�r^rrr.r-rIrC)r!r�r�Zexpected_file_liner@r;Zfile_objectr�rrr�test_showwarning�s$z%WarningsDisplayTests.test_showwarningN)r$r%r&r'r�r�rrrrr�jsr�c@seZdZeZdS)�CWarningsDisplayTestsN)r$r%r&r6rrrrrr��sr�c@seZdZeZdd�ZdS)�PyWarningsDisplayTestscCs�|jtjtj�ttjd��}|jtjd��WdQRXtdddtj�}|j	j
dd�}dj|j��}t
jd	d
|�}tjd�}|jtjd�j�}|j||�dS)
Nr>z�
                def func():
                    f = open(__file__)
                    # Emit ResourceWarning
                    f = None

                func()
            z-Wdz-Xz
tracemalloc=2�ascii�replacer�z<.*>z<...>a
            {fname}:5: ResourceWarning: unclosed file <...>
              f = None
            Object allocated at (most recent call first):
              File "{fname}", lineno 3
                f = open(__file__)
              File "{fname}", lineno 7
                func()
        )Zfname)Z
addCleanupr�unlinkZTESTFN�open�write�textwrap�dedentrr��decode�joinr��re�subr�r�rI)r!�fp�resrE�expectedrrr�test_tracemalloc�sz'PyWarningsDisplayTests.test_tracemallocN)r$r%r&r8rr�rrrrr��sr�c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�CatchWarningTestszTest catch_warnings().cCs�|j}|j}|j}|j|dd��t�|_|_WdQRX|j|j|k�|j|j|k�|j|dd��t�|_|_WdQRX|j|j|k�|j|j|k�dS)NT)rrGF)rrr-r1�objectr2)r!r��orig_filters�orig_showwarningrrr�test_catch_warnings_restore�sz-CatchWarningTests.test_catch_warnings_restorecCs|j}|j|dd���}|j|g�|jt|�tk�|jd�|jd�|jt|d	j	�d�|jd�|jt|d
j	�d�|jt|dj	�d�|jt|dj	�d�|dd�=|j|g�WdQRX|j
}|j|dd��$}|j|dk�|j|j
|k�WdQRXdS)NT)rrGrNr�rLr�rFrPrP)rr1rIr2�type�listrr+rcr@r-)r!r�r>rrrr�test_catch_warnings_recording�s"



z/CatchWarningTests.test_catch_warnings_recordingcCs~|j}|j|dd�}|jt|j�|�|jt|j�WdQRX|j|dd�}|jt|j�|�|jt|j�WdQRXdS)NT)rrGF)rr1r=�RuntimeError�__exit__�	__enter__)r!r�rXrrr�!test_catch_warnings_reentry_guard�sz3CatchWarningTests.test_catch_warnings_reentry_guardcCs�|j}|j}|j}|j|d��4}|j|dk�|j|j|k�|j|j|k	�WdQRX|j|j|k�|tjdkr�|j��4}|j|dk�|j|j|k�|j|j|k	�WdQRX|j|j|k�dS)N)rr)rrr-r1r2rr)r!r�rrr>rrr�test_catch_warnings_defaults�s
z.CatchWarningTests.test_catch_warnings_defaultscs�d}|j}g�d
�fdd�	}tj|d|��P|j|dd��(}|j|j|�|jd�|j|�WdQRX|j|j|�WdQRX|j	t
|�d|�|j	|d	jjd	|�|j	�g�dS)NzThis is a warningcs�j|�dS)N)r`)r@r;r~�linenor�r�)�my_logrr�	my_loggerszLCatchWarningTests.test_record_override_showwarning_before.<locals>.my_loggerr-T)rrGrNrLr)NN)
rrr�r1ZassertIsNotr-rr+ZassertIsrIrJr@rQ)r!rdr�r�logr)r
r�'test_record_override_showwarning_befores
z9CatchWarningTests.test_record_override_showwarning_beforecs�d}|j}g�d	�fdd�	}|j|dd�� }|jd�||_|j|�WdQRX|jt��d��|j�djd|�|j|g�dS)
NzThis is a warningcs�j|�dS)N)r`)r@r;r~rr�r�)r
rrr$szLCatchWarningTests.test_record_override_showwarning_inside.<locals>.my_loggerT)rrGrNrLr)NN)rr1rr-r+rIrJrQ)r!rdr�rrr)r
r�'test_record_override_showwarning_insides
z9CatchWarningTests.test_record_override_showwarning_insidec3Csr|j}|tjdk	r|jd�tjdd���}|j|jg�|jd�|j	d�|jt
|j�d�|j	d�|jt
|j�d�|jt
|jdj�d�|jt
|jd	j�d�|j�|j|jg�WdQRXtj��WdQRXtjdt
f��|j	d�WdQRX|jt�� tjd
tf��WdQRXWdQRX|jt��*tjdtf��|j	d�WdQRXWdQRXdS)Nrz,module to test is not loaded warnings moduleF)�quietrNr�r�rrLrb)rrrZskipTestrZcheck_warningsrIrrr+rcr@�resetr<r=r��RuntimeWarning)r!r�r>rrr�test_check_warnings1s0





z%CatchWarningTests.test_check_warningsN)r$r%r&r'rrr
rrrrrrrrr��s
r�c@seZdZeZdS)�CCatchWarningTestsN)r$r%r&r6rrrrrrPsrc@seZdZeZdS)�PyCatchWarningTestsN)r$r%r&r8rrrrrrSsrc@sHeZdZdd�Zdd�Zdd�Zdd�Zeje	j
�d	kd
�dd��Zd
S)�EnvironmentVariableTestscCs$tdddd�\}}}|j|d�dS)Nz-cz2import sys; sys.stdout.write(str(sys.warnoptions))zignore::DeprecationWarning)�PYTHONWARNINGSs['ignore::DeprecationWarning'])rrI)r!r�r�rErrr�test_single_warningYsz,EnvironmentVariableTests.test_single_warningcCs$tdddd�\}}}|j|d�dS)Nz-cz2import sys; sys.stdout.write(str(sys.warnoptions))z1ignore::DeprecationWarning,ignore::UnicodeWarning)rs8['ignore::DeprecationWarning', 'ignore::UnicodeWarning'])rrI)r!r�r�rErrr�test_comma_separated_warnings_s
z6EnvironmentVariableTests.test_comma_separated_warningscCs&tddddd�\}}}|j|d�dS)Nz-Wignore::UnicodeWarningz-cz2import sys; sys.stdout.write(str(sys.warnoptions))zignore::DeprecationWarning)rs8['ignore::DeprecationWarning', 'ignore::UnicodeWarning'])rrI)r!r�r�rErrr�test_envvar_and_command_linefs
z5EnvironmentVariableTests.test_envvar_and_command_linecCs<tddddd�\}}}|j|d�|j|j�ddd	g�dS)
Nz-Werror::DeprecationWarningz-czjimport sys, warnings; sys.stdout.write(str(sys.warnoptions)); warnings.warn('Message', DeprecationWarning)zdefault::DeprecationWarning)rs<['default::DeprecationWarning', 'error::DeprecationWarning']s"Traceback (most recent call last):s&  File "<string>", line 1, in <module>sDeprecationWarning: Message)rrIr�)r!r�r�rErrr�(test_conflicting_envvar_and_command_linems
zAEnvironmentVariableTests.test_conflicting_envvar_and_command_liner�z%requires non-ascii filesystemencodingcCs,tddddd�\}}}|j|djd��dS)Nz-cz2import sys; sys.stdout.write(str(sys.warnoptions))zutf-8uignore:DeprecaciónWarning)ZPYTHONIOENCODINGru['ignore:DeprecaciónWarning'])rrI�encode)r!r�r�rErrr�
test_nonasciiysz&EnvironmentVariableTests.test_nonasciiN)r$r%r&rrrrrr�r�getfilesystemencodingrrrrrrWsrc@seZdZeZdS)�CEnvironmentVariableTestsN)r$r%r&r6rrrrrr!�sr!c@seZdZeZdS)�PyEnvironmentVariableTestsN)r$r%r&r8rrrrrr"�sr"c@seZdZdd�ZdS)�
BootstrapTestcCsNtj��<}tjd��&tdd|d�tdddd|d�WdQRXWdQRXdS)NZ	encodingsz-cr�)�
PYTHONPATHz-WrN)rZtemp_cwdr)r!�cwdrrr�test_issue_8766�szBootstrapTest.test_issue_8766N)r$r%r&r&rrrrr#�sr#c@s"eZdZejdd��Zdd�ZdS)�FinalizationTestcCs$d}td|�\}}}|j|d�dS)Nzk
import warnings
warn = warnings.warn

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

a=A()
        z-cs__main__:7: UserWarning: test)rrI)r!�coder�r�r�rrr�test_finalization�s
z"FinalizationTest.test_finalizationcCshd}dt}tdd|�\}}}|j|j|�t|��dt}tdd|�\}}}|j|j|�t|��dS)Ns&sys:1: ResourceWarning: unclosed file zf = open(%a)z-Wdz-czimport warnings; f = open(%a))r�rr2�
startswithr�)r!r�r(r�r�r�rrr�test_late_resource_warning�sz+FinalizationTest.test_late_resource_warningN)r$r%r&rZrequires_type_collectingr)r+rrrrr'�sr'cCstjj�tjj�dS)N)r8r�rr6rrrr�setUpModule�s
r,r�)6�
contextlibrr�r{�iorr�rr�rr�rZtest.support.script_helperrrZtest.test_warnings.datarrrrZimport_fresh_moduler8r6rrr)ZTestCaser5r7r9rsrtrur�r�r�r�r�r�r�r�r�r�rrrr!r"r#r'r,ZtearDownModuler$�mainrrrr�<module>s^ze	
p-#,
&