Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/test/test_warnings/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/test_warnings/__pycache__/__init__.cpython-35.pyc



��YfX��@s�ddlmZddlZddlZddlmZddlZddlZddlm	Z	ddl
mZmZddl
mZddlZe	jddd	g�Ze	jdd
d	g�Zedd��ZGd
d�d�ZGdd�de�ZGdd�deej�ZGdd�deej�ZGdd�de�ZGdd�deej�ZGdd�deej�ZGdd�de�ZGdd�deej�ZGdd �d eej�Z Gd!d"�d"e�Z!Gd#d$�d$e!ej�Z"Gd%d&�d&e!ej�Z#Gd'd(�d(eej�Z$Gd)d*�d*e�Z%Gd+d,�d,e%ej�Z&Gd-d.�d.e%ej�Z'Gd/d0�d0e�Z(Gd1d2�d2e(ej�Z)Gd3d4�d4e(ej�Z*Gd5d6�d6e�Z+Gd7d8�d8e+ej�Z,Gd9d:�d:e+ej�Z-Gd;d<�d<ej�Z.Gd=d>�d>ej�Z/d?d@�Z0e0Z1e2dAkrej3�dS)B�)�contextmanagerN)�StringIO)�support)�assert_python_ok�assert_python_failure)�
stacklevel�warningsZblocked�	_warningsZfreshccs�x:ttfD],}y|jj�Wq
tk
r8Yq
Xq
Wytj�Wntk
r_YnXtj}|j}z2|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/python35/lib64/python3.5/test/test_warnings/__init__.py�warnings_states$
	
		
			rcs:eZdZdZ�fdd�Z�fdd�Z�S)�BaseTestz'Basic bookkeeping required for testing.cs�tjj|_dt�kr(t�d=ttd�r=t`ttd�rRt`|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 .s
zBaseTest.setUpcs3ttjd<|jtj_tt|�j	�dS)Nr)
rrrrrrrrr�tearDown)r!)r"rrr#As
zBaseTest.tearDown)�__name__�
__module__�__qualname__�__doc__r r#rr)r"rr*src@s"eZdZdZdd�ZdS)�PublicAPITestszGEnsures that the correct values are exposed in the
    public API.
    cCs]|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_attributeLs		z(PublicAPITests.test_module_all_attributeN)r$r%r&r'r3rrrrr(Fsr(c@seZdZeZdS)�CPublicAPITestsN)r$r%r&�
c_warningsrrrrrr4Tsr4c@seZdZeZdS)�PyPublicAPITestsN)r$r%r&�py_warningsrrrrrr6Wsr6c@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.cCs_tjd|j��C}|jj�|jjddt�|jt|jjd�WdQRXdS)Nr�error�categoryzFilterTests.test_error)rr0rr/r.�UserWarning�assertRaisesr*)r!�wrrr�
test_error^s

zFilterTests.test_errorcs�tjd�j���}�jj�d���fdd�}tj��}|�WdQRX|j�}�jd|��jd|��jjddt	��j
t	|�WdQRXdS)	Nrz%FilterTests.test_ignore_after_defaultcs�jj�t�dS)N)rr*r;r)�messager!rr�fisz/FilterTests.test_error_after_default.<locals>.fz2UserWarning: FilterTests.test_ignore_after_defaultz&self.module.warn(message, UserWarning)r9r:)rr0rr/rZcaptured_stderr�getvalue�assertInr.r;r<)r!r=r@�stderrr)r?r!r�test_error_after_defaultes
		z$FilterTests.test_error_after_defaultcCsutjddd|j��S}|jj�|jjddt�|jjdt�|jt|�d�WdQRXdS)N�recordTr�ignorer:zFilterTests.test_ignorer)	rr0rr/r.r;r*�assertEqual�len)r!r=rrr�test_ignorews
zFilterTests.test_ignorecs�tjddd�j��p}�jj�d���fdd�}|��jjddt�|�|��jt|�d	�WdQRXdS)
NrETrz%FilterTests.test_ignore_after_defaultcs�jj�t�dS)N)rr*r;r)r?r!rrr@�sz0FilterTests.test_ignore_after_default.<locals>.frFr:�)rr0rr/r.r;rGrH)r!r=r@r)r?r!r�test_ignore_after_defaults
z%FilterTests.test_ignore_after_defaultcCs�tjddd|j���}|jj�|jjddt�d}|jj|t�|j||dj�|jj|t�|j|d	j|�WdQRXdS)
NrETr�alwaysr:zFilterTests.test_alwaysrJ���rM)	rr0rr/r.r;r*r1r?)r!r=r?rrr�test_always�s
zFilterTests.test_alwayscs5tjddd�j��}�jj�d���fdd�}|��jt|�d��j|d
jjd��|��jt|�d��jjd	d
t	�|��jt|�d��j|djjd��|��jt|�d��j|djjd��WdQRXdS)NrETrz$FilterTests.test_always_after_ignorecs�jj�t�dS)N)rr*r;r)r?r!rrr@�sz0FilterTests.test_always_after_default.<locals>.frJrrLr:��rMrMrM)
rr0rr/rGrHr?�argsr.r;)r!r=r@r)r?r!r�test_always_after_default�s"
z%FilterTests.test_always_after_defaultcCs�tjddd|j���}|jj�|jjddt�td�}x�td�D]}}|jj|t�|dkr�|j|dj	|�|dd�=qZ|d	kr�|jt
|�d�qZtd
��qZWWdQRXdS)NrETr�defaultr:zFilterTests.test_defaultrOrrJzloop variant unhandledrM)rr0rr/r.r;�ranger*rGr?rH�
ValueError)r!r=r?�xrrr�test_default�s
zFilterTests.test_defaultcCs�tjddd|j���}|jj�|jjddt�td�}|jj|t�|j|dj|�|dd�=|jj|t�|jt	|�d�WdQRXdS)	NrETrr:zFilterTests.test_modulerJrrM)
rr0rr/r.r;r*rGr?rH)r!r=r?rrr�test_module�s

zFilterTests.test_modulecCs�tjddd|j���}|jj�|jjddt�td�}|jj|tdd�|j|d
j|�|dd�=|jj|tdd
�|jt	|�d�|jj|tdd�|jt	|�d�WdQRXdS)NrETrr
r:zFilterTests.test_oncez__init__.py�*rJ�
rztest_warnings2.pyrM)
rr0rr/r.r;r+rGr?rH)r!r=r?rrr�	test_once�s

zFilterTests.test_oncecCsbtjd|j��F}|jj�|jjddt�|jt|jjdt�WdQRXdS)Nrr9r:zFilterTests.test_inheritance)	rr0rr/r.�Warningr<r;r*)r!r=rrr�test_inheritance�s

zFilterTests.test_inheritancecCs�tjddd|j���}|jj�|jjddt�|jjddtdd�|dd�=y|jjdt�Wntk
r�|jd	�YnX|jt	|�d
�WdQRXdS)NrETrrFr:r9�appendzFilterTests.test_orderingz!order handling for actions failedr)
rr0rr/r.r;r*ZfailrGrH)r!r=rrr�
test_ordering�s


zFilterTests.test_orderingc
Cs�tjddd|j��t}|jjddtdd�|jt|jjd�|jj�d}|jj|�|j	t
|dj�|�|j|dj
tk�|jjd
dtdd�d}|jj|�|jt
|dj�|�|jj�|jjddtdd�|jt|jjd
�d}|jj|�|j	t
|dj�|�|j|dj
tk�WdQRXdS)NrETrr9�rzconvert to errorzhandle normallyrJrFzfiltered outzhex*zhex/octznonmatching textrMrMrMrMrM)rr0rr.r\r<r;r*r/rG�strr?r1r:ZassertNotEqual)r!r=�textrrr�test_filterwarnings�s(

zFilterTests.test_filterwarningscCs�tjddd|j���}|jjdt�|jjddt�|jt|jjd�|jt|jjd�|jjd�|j|g�|jjd	�|j|g�WdQRXdS)
NrETrrFr9�matchzmatch prefixzsuffix matchzsomething completely different)	rr0rrr;r.r<r*rG)r!r=rrr�test_message_matchingsz!FilterTests.test_message_matchingcs�G�fdd�d���fdd�td�D��tjddd|j��O}�|j_|jjtd	�dd
d�|jt|d
j	�d	�WdQRXdS)Ncs"eZdZ�fdd�ZdS)z.FilterTests.test_mutate_filter_list.<locals>.Xcsg�dd�<dS)Nr)r!�a)�Lrrrdsz4FilterTests.test_mutate_filter_list.<locals>.X.matchN)r$r%r&rdr)rgrr�Xsrhcs+g|]!}d��t��df�qS)rSr)r;)�.0�i)rhrr�
<listcomp>s	z7FilterTests.test_mutate_filter_list.<locals>.<listcomp>rOrETr�bzf.pyrYrJrM)
rTrr0rrr+r;rGrar?)r!r=r)rgrhr�test_mutate_filter_listsz#FilterTests.test_mutate_filter_listcCs�tjd|j���|jj�|jjddt�|jt|jj�d�|jjddt�|jjddt�|jt|jj�dd�|j|jjdddd	�WdQRXdS)
Nrr9r:rJrFrOz(filterwarnings inserted duplicate filterrz>filterwarnings did not promote filter to the beginning of list)	rr0rr/r.r;rGrHr)r!rrr�%test_filterwarnings_duplicate_filters s
z1FilterTests.test_filterwarnings_duplicate_filterscCs�tjd|j���|jj�|jjddt�|jt|jj�d�|jjddt�|jjddt�|jt|jj�dd�|j|jjdddd	�WdQRXdS)
Nrr9r:rJrFrOz&simplefilter inserted duplicate filterrz<simplefilter did not promote filter to the beginning of list)	rr0rr/rr;rGrHr)r!rrr�#test_simplefilter_duplicate_filters1s
z/FilterTests.test_simplefilter_duplicate_filterscCs�tjd|jdd���}|jj�|jjd�|jjddd�|jjddd�|jjddt�|jt|jj	�d	d
�|jt|�dd�WdQRXdS)
NrrETrFr9r^�test_append_duplicater:rOz&simplefilter inserted duplicate filterrz+appended duplicate changed order of filters)
rr0rr/rr*r;rGrHr)r!r=rrrrp@s
z!FilterTests.test_append_duplicateN)r$r%r&r'r>rDrIrKrNrRrWrXr[r]r_rcrermrnrorprrrrr8Zs$
r8c@seZdZeZdS)�CFilterTestsN)r$r%r&r5rrrrrrqOsrqc@seZdZeZdS)�
PyFilterTestsN)r$r%r&r7rrrrrrrRsrrc@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�tjddd|j��}|jjd�xetd�D]W}d|}|jj|�|jt|dj�|�|j	|d	j
tk�q;WWdQRXdS)
NrETrr
�zmulti %drJrMrM)rr0rrrTr*rGrar?r1r:r;)r!r=rjrbrrr�test_messageZs
zWarnTests.test_messagec
Cs�x�tddfD]t}tjddd|j��P}|jjd�|jj|�|jt|dj�tt	|���WdQRXqWdS)NrYrETrr
rJrM)
r\rr0rrr*rGrar?r;)r!�obr=rrr�test_warn_nonstandard_typesesz%WarnTests.test_warn_nonstandard_typescCs�t|j���tjddd|j��g}tjd�|jtjj	|dj
�d�tjd�|jtjj	|d	j
�d�WdQRXWdQRXdS)
NrETrZspam1rJz
stacklevel.pyZspam2rMrM)rrrr0r�innerrG�os�path�basename�filename�outer)r!r=rrr�
test_filenameps

zWarnTests.test_filenamecCs�t|j��ntjddd|j��K}tjddd�|jtjj	|dj
�d�tjddd�|jtjj	|dj
�d�tjd	dd
�|jtjj	|dj
�d�tjddd
�|jtjj	|dj
�d�tjd
dd�|jtjj	|dj
�d�tjddd�|jtjj	|dj
�d�WdQRXWdQRXdS)NrETrZspam3rrJz
stacklevel.pyZspam4Zspam5rOz__init__.pyZspam6zspam6.5rPZspam7i'rrMrMrMrMrMrM)rrrr0rrxrGryrzr{r|r})r!r=rrr�test_stacklevel{s*zWarnTests.test_stacklevelcCs�tjd�t|j��stjddd|j��P}|jjd�ddl}|jt	|�d�|j|dj
t�WdQRXWdQRXdS)Nz&test.test_warnings.data.import_warningrETrrLrrJ)rZunloadrrrr0rZ&test.test_warnings.data.import_warningrGrHr|�__file__)r!r=�testrrr�test_stacklevel_import�s
z WarnTests.test_stacklevel_importcCs�tj}zst`t|j��Wtjddd|j��4}tjddd�|j|djtj	�WdQRXWdQRXWd|t_XdS)NrETrZspam8rrJrM)
rr�rrrr0rxrGr|r$)r!r|r=rrr�test_missing_filename_not_main�s	,z(WarnTests.test_missing_filename_not_main�argvztest needs sys.argvcCs�tj}tj}z�t`dt_t|j��[tjddd|j��8}tjddd�|j|d	j	t
jd�WdQRXWdQRXWd|t_|t_XdS)
N�__main__rETrZspam9rrJrrM)rr�r$rrrr0rxrGr|rr�)r!r|�module_namer=rrr�$test_missing_filename_main_with_argv�s			0	z.WarnTests.test_missing_filename_main_with_argvcCs�tj}tj}tj}zt`dt_t`t|j��Ttjddd|j��1}tj	ddd�|j
|djd�WdQRXWdQRXWd|t_|t_|t_XdS)	Nr�rETrZspam10rrJrM)rr�r$rr�rrrr0rxrGr|)r!r|r�r�r=rrr�'test_missing_filename_main_without_argv�s				)		z1WarnTests.test_missing_filename_main_without_argvcCs�tj}tj}tj}z�t`dt_dgt_t|j��Ttjddd|j��1}tj	ddd�|j
|d	jd�WdQRXWdQRXWd|t_|t_|t_XdS)
Nr�r`rETrZspam11rrJrM)rr�r$rr�rrrr0rxrGr|)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�tjddd|j���}|jj�|jjddt�xgd
D]_}ytj|�Wntk
rvwHYnX|jj	dt|d	�|j
|dj|�qHWWdQRXdS)NrETrrLr:�
nonascii�surrogate�rbrJ)r�r�rM)rr0rr/r.r;ry�fsencode�UnicodeEncodeErrorr+rGr|)r!r=r|rrr�%test_warn_explicit_non_ascii_filename�s


z/WarnTests.test_warn_explicit_non_ascii_filenamec	Csv|jt|jjdtdd�|jt|jjdddd�|jttf|jjdtdddd�dS)NrJ�registryrY)r<�	TypeErrorrr+r;rr\)r!rrr�test_warn_explicit_type_errors�s	z(WarnTests.test_warn_explicit_type_errorsc	CsDGdd�dt�}|jt��|jj|��WdQRXdS)Nc@s"eZdZdZdd�ZdS)z-WarnTests.test_bad_str.<locals>.BadStrWarningz-Warning with a bad format string for __str__.cSsdddiS)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�
BadStrWarning
sr�)r\r<rUrr*)r!r�rrr�test_bad_strszWarnTests.test_bad_strc4CsGdd�dt�}Gdd�d�}|jt��}|jjdd�WdQRX|jdt|j��|jt��}|jjd|�WdQRX|jdt|j��|jt��}|jjd|��WdQRX|jdt|j��tj	d|j���|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@seZdZdS)z6WarnTests.test_warning_classes.<locals>.MyWarningClassN)r$r%r&rrrr�MyWarningClasssr�c@seZdZdS)z:WarnTests.test_warning_classes.<locals>.NonWarningSubclassN)r$r%r&rrrr�NonWarningSubclasssr�zbad warning categoryr`z)category must be a Warning subclass, not rrSzgood warning category)r\r<r�rr*rBraZ	exceptionrr0r/r.ZassertWarnsrGZwarningr;ZassertIsInstance)r!r�r��cmrrr�test_warning_classess4			
zWarnTests.test_warning_classesN)r$r%r&r'rurwr~rr�r�r�
skipUnlessrrr�r�r�r�r�r�r�rrrrrsVs'

rsc@s"eZdZeZdd�ZdS)�
CWarnTestscCs6|jt|jk�|jt|jjd��dS)N�__code__)�assertFalserrrr*)r!rrr�test_accelerated?szCWarnTests.test_acceleratedN)r$r%r&r5rr�rrrrr�:sr�c@s"eZdZeZdd�ZdS)�PyWarnTestscCs6|jt|jk�|jt|jjd��dS)Nr�)r�rrr1rr*)r!rrr�test_pure_pythonHszPyWarnTests.test_pure_pythonN)r$r%r&r7rr�rrrrr�Csr�c@seZdZdd�ZdS)�
WCmdLineTestscCs�tjd|j���|j|jj|jjd�|j|jj|jjd�|j|jj|jjd�|jjd�|jt|jjd�WdQRXdS)Nrz1:2:3:4:5:6zbogus::Warningzignore:2::4:-5zerror::Warning::0zconvert to error)rr0rr<�_OptionError�
_setoptionr;r*)r!rrr�test_improper_inputOsz!WCmdLineTests.test_improper_inputN)r$r%r&r�rrrrr�Msr�c@seZdZeZdS)�CWCmdLineTestsN)r$r%r&r5rrrrrr�]sr�c@s.eZdZeZdd�Zdd�ZdS)�PyWCmdLineTestscCs/tddd�\}}}|jd|�dS)Nz-Wxxxz-c�passs0Invalid -W option ignored: invalid action: 'xxx')rrB)r!�rc�outr�rrr�test_improper_optiondsz$PyWCmdLineTests.test_improper_optioncCsBtddd�\}}}|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_bootstrapks	z'PyWCmdLineTests.test_warnings_bootstrapN)r$r%r&r7rr�r�rrrrr�asr�c@s|eZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dS)�_WarningsTestsz'Tests specific to the _warnings module.c
Csztjd|j��^}|jjddtdd�|jt|jjd�|j`|jt|jjd�WdQRXdS)Nrr9r`rzconvert to error)	rr0rr.r\r<r;r*r)r!r=rrr�test_filter{s	z_WarningsTests.test_filtercCsttd�}zT|jj}iatjddd|j�� }|jj�|jjddt�|jj|tdd�|j	|dj
|�|dd�=|jj|tdd�|j	t|�d
�i|j_ia|jjd�|j	|dj
j
|j
�|dd�=|j`ia|jj|tdd�|j	t|�d
�WdQRXWd||j_XdS)
Nzonceregistry testrETrr
r:�filerYrJrrMrM)r;r�onceregistryr
rr0r/r.r+rGr?rHr*rQ)r!r?Zoriginal_registryr=rrr�test_onceregistry�s.


	!z _WarningsTests.test_onceregistrycCs�td�}|jj}z�tjddd|j��j}|jj�i}|jj|tddd|�|j|dj|�|jt	|�d�|jt	|�d	�|j
d
|�|dd�=|j`i}i}|jj|tddd|�|j|dj|�|jt	|�d�|jt	|�d	�|dd�=d|j_i}i}|jj|tdd
d|�|jt	|�d�WdQRXWd||j_XdS)Nzdefaultaction testrETrz<test>rYr�rJrO�version�+rF�,rrMrM)r;r�
defaultactionrr0r/r+rGr?rHrB)r!r?Zoriginalr=r�r
rrr�test_default_action�s<

	
!z"_WarningsTests.test_default_actioncCs�d}tjd|j��Y|jjddt�|j`tjd��#}|jj|�|j	�}WdQRXWdQRX|j
||�dS)Nzdel showwarning testrrLr:rC)rr0rr.r;r,r�captured_outputr*rArB)r!rb�stream�resultrrr�test_showwarning_missing�s	z'_WarningsTests.test_showwarning_missingcCs�tjd|j��s|jjddt�t|j_tjd��|jj	d�WdQRXd|j_|j
t|jj	d�WdQRXdS)NrrLr:�stdoutzWarning!�)rr0rr.r;�printr,rr�r*r<r�)r!rrr�test_showwarning_not_callable�sz,_WarningsTests.test_showwarning_not_callablec
Cstd}tjd|j��V|jjddt�|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_warningrrLr:rC�
rOzToo many newlines in %rrJrz.py�:rP� z  )rr0rr.r;r,rr�rrxrArG�count�splitryrz�splitextr��rsplit�intr$�	linecache�getliner��AssertionError)
r!rbr�r�Z
first_lineZsecond_lineZ
expected_fileZfirst_line_partsrz�lineZ
warning_classr?Z
expected_linerrr�test_show_warning_output�s(	
 z'_WarningsTests.test_show_warning_outputcCs�t�}|d}zrtjddd|j�}|�J}|jjddt�d|d<tjdt�|jt|��WdQRXWd||d<XdS)Nr�rETrrLr:r�)	rrr0rr.r;r*r1rH)r!Zglobals_dictZoldfileZcatchr=rrr�test_filename_none�s	
	
z!_WarningsTests.test_filename_nonecCsLtdd�\}}}|j|d�|jd|�|jd|�dS)Nz-czjimport sys; sys.stderr = None; import warnings; warnings.simplefilter('always'); warnings.warn('Warning!')�sWarning!sError)rrGr�)r!r�r�rCrrr�test_stderr_nones
z_WarningsTests.test_stderr_noneN)r$r%r&r'r5rr�r�r�r�r�r�r�r�rrrrr�us
%	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.pyrPz%s:%s: %s: %s
  %s
z
 for the win!)
r\ryrzr�rr�r�r�r�r$rGrr-)r!r?r:r��line_numZ	file_line�format�expectrrr�test_formatwarnings


z'WarningsDisplayTests.test_formatwarningcCstjjtj�dd}d}tj||�j�}d}t}t	�}|j
j||||�}|j
j|||||�|j
|j�|�|d7}|j
j|||||�}t	�}|j
j||||||�|j
||j��dS)Nrz.pyrPr�zfor the win!)ryrzr�rr�r�r�r�r\rrr-r,rGrA)r!r�r�Zexpected_file_liner?r:Zfile_objectr�rrr�test_showwarning#s$		
	
z%WarningsDisplayTests.test_showwarningN)r$r%r&r'r�r�rrrrr�sr�c@seZdZeZdS)�CWarningsDisplayTestsN)r$r%r&r5rrrrrr�8sr�c@seZdZeZdS)�PyWarningsDisplayTestsN)r$r%r&r7rrrrrr�;sr�c@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�CatchWarningTestszTest catch_warnings().cCs�|j}|j}|j}|jd|dd��t�|_|_WdQRX|j|j|k�|j|j|k�|jd|dd��t�|_|_WdQRX|j|j|k�|j|j|k�dS)NrrETF)rrr,r0�objectr1)r!�wmod�orig_filters�orig_showwarningrrr�test_catch_warnings_restoreCs			z-CatchWarningTests.test_catch_warnings_restorecCsd|j}|jd|dd���}|j|g�|jt|�tk�|jd�|jd�|jt|d
j	�d�|jd�|jt|dj	�d�|jt|dj	�d�|jt|dj	�d�|dd�=|j|g�WdQRX|j
}|jd|dd	��0}|j|dk�|j|j
|k�WdQRXdS)NrrETrL�foorJ�barrFrMrM)rr0rGr1�type�listrr*rar?r,)r!r�r=r�rrr�test_catch_warnings_recordingRs"	



	z/CatchWarningTests.test_catch_warnings_recordingcCs�|j}|jd|dd�}|jt|j�|�|jt|j�WdQRX|jd|dd�}|jt|j�|�|jt|j�WdQRXdS)NrrETF)rr0r<�RuntimeError�__exit__�	__enter__)r!r�rVrrr�!test_catch_warnings_reentry_guardgs	z3CatchWarningTests.test_catch_warnings_reentry_guardcCs|j}|j}|j}|jd|��F}|j|dk�|j|j|k�|j|j|k	�WdQRX|j|j|k�|tjdkr
|j��F}|j|dk�|j|j|k�|j|j|k	�WdQRX|j|j|k�dS)Nrr)rrr,r0r1rr)r!r�r�r�r=rrr�test_catch_warnings_defaultsts			z.CatchWarningTests.test_catch_warnings_defaultsc3Cs�|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 module�quietFrLr�r�rrJr`)rrrZskipTestrZcheck_warningsrGrrr*rar?�resetr;r<r��RuntimeWarning)r!r�r=rrr�test_check_warnings�s0	



  

z%CatchWarningTests.test_check_warningsN)	r$r%r&r'r�r�r�r�r�rrrrr�?s
r�c@seZdZeZdS)�CCatchWarningTestsN)r$r%r&r5rrrrrr��sr�c@seZdZeZdS)�PyCatchWarningTestsN)r$r%r&r7rrrrrr��sr�c@sjeZdZdd�Zdd�Zdd�Zdd�Zeje	j
�d	kd
�dd��Zd
S)�EnvironmentVariableTestscCs2tdddd�\}}}|j|d�dS)Nz-cz2import sys; sys.stdout.write(str(sys.warnoptions))�PYTHONWARNINGSzignore::DeprecationWarnings['ignore::DeprecationWarning'])rrG)r!r�r�rCrrr�test_single_warning�sz,EnvironmentVariableTests.test_single_warningcCs2tdddd�\}}}|j|d�dS)Nz-cz2import sys; sys.stdout.write(str(sys.warnoptions))r�z1ignore::DeprecationWarning,ignore::UnicodeWarnings8['ignore::DeprecationWarning', 'ignore::UnicodeWarning'])rrG)r!r�r�rCrrr�test_comma_separated_warnings�s
	z6EnvironmentVariableTests.test_comma_separated_warningscCs5tddddd�\}}}|j|d�dS)Nz-Wignore::UnicodeWarningz-cz2import sys; sys.stdout.write(str(sys.warnoptions))r�zignore::DeprecationWarnings8['ignore::DeprecationWarning', 'ignore::UnicodeWarning'])rrG)r!r�r�rCrrr�test_envvar_and_command_line�s
		z5EnvironmentVariableTests.test_envvar_and_command_linecCsTtddddd�\}}}|j|d�|j|j�ddd	g�dS)
Nz-Werror::DeprecationWarningz-czjimport sys, warnings; sys.stdout.write(str(sys.warnoptions)); warnings.warn('Message', DeprecationWarning)r�zdefault::DeprecationWarnings<['default::DeprecationWarning', 'error::DeprecationWarning']s"Traceback (most recent call last):s&  File "<string>", line 1, in <module>sDeprecationWarning: Message)rrG�
splitlines)r!r�r�rCrrr�(test_conflicting_envvar_and_command_line�s		zAEnvironmentVariableTests.test_conflicting_envvar_and_command_line�asciiz%requires non-ascii filesystemencodingcCsAtdddddd�\}}}|j|djd��dS)Nz-cz2import sys; sys.stdout.write(str(sys.warnoptions))ZPYTHONIOENCODINGzutf-8r�uignore:DeprecaciónWarningu['ignore:DeprecaciónWarning'])rrG�encode)r!r�r�rCrrr�
test_nonascii�s	z&EnvironmentVariableTests.test_nonasciiN)r$r%r&r�r�r�r�rr�r�getfilesystemencodingr�rrrrr��sr�c@seZdZeZdS)�CEnvironmentVariableTestsN)r$r%r&r5rrrrrr��sr�c@seZdZeZdS)�PyEnvironmentVariableTestsN)r$r%r&r7rrrrrr��sr�c@seZdZdd�ZdS)�
BootstrapTestcCs]tj��J}tjd��1tddd|�tddddd|�WdQRXWdQRXdS)N�	encodingsz-cr��
PYTHONPATHz-WrL)rZtemp_cwdr)r!�cwdrrr�test_issue_8766�szBootstrapTest.test_issue_8766N)r$r%r&rrrrrr��sr�c@s1eZdZejdd��Zdd�ZdS)�FinalizationTestcCs2d}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)rrG)r!�coder�r�r�rrr�test_finalization�s
z"FinalizationTest.test_finalizationcCs�d}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�rr1�
startswithr�)r!Zexpectedrr�r�r�rrr�test_late_resource_warnings

z+FinalizationTest.test_late_resource_warningN)r$r%r&rZrequires_type_collectingrrrrrrr�srcCstjj�tjj�dS)N)r7r�rr5rrrr�setUpModules
rr�)4�
contextlibrr�ry�iorrrr�rZtest.support.script_helperrrZtest.test_warnings.datarrrrZimport_fresh_moduler7r5rrr(ZTestCaser4r6r8rqrrrsr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrZtearDownModuler$�mainrrrr�<module>sR��	
�,f,
&