HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/test_warnings/__pycache__/__init__.cpython-37.pyc
B

"��g���@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�x4ttfD](}y|j��Wq
tk
r0Yq
Xq
Wyt��Wntk
rVYnXtj}|j}z(|dd�|_|�d�|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�7/usr/local/lib/python3.7/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�krt�d=ttd�r*t`ttd�r8t`|j	tj
d<|j	tj_tt|��
�dS)Nr
r)�unittest�caser�old_unittest_module�globals�hasattrrr
rr�modules�superr�setUp)�self)�	__class__rrr$6s




zBaseTest.setUpcs&ttjd<|jtj_tt|��	�dS)Nr)
rrr"rrrrr#r�tearDown)r%)r&rrr'Is

zBaseTest.tearDown)rrr�__doc__r$r'�
__classcell__rr)r&rr2src@seZdZdZdd�ZdS)�PublicAPITestszGEnsures that the correct values are exposed in the
    public API.
    cCsB|�t|jd��dddddddd	g}|�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(r5rrrrr*Nsr*c@seZdZeZdS)�CPublicAPITestsN)rrr�
c_warningsrrrrrr6\sr6c@seZdZeZdS)�PyPublicAPITestsN)rrr�py_warningsrrrrrr8_sr8c@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.c	CsJtj|jd��2}|j��|jjdtd�|�t|jjd�WdQRXdS)N)r�error)�categoryzFilterTests.test_error)rr2rr1r0�UserWarning�assertRaisesr,)r%�wrrr�
test_errorfs

zFilterTests.test_errorc
s�tj�jd��x}�j��d���fdd�}t���}|�WdQRX|��}��d|���d|��jjdt	d���
t	|�WdQRXdS)	N)rz%FilterTests.test_ignore_after_defaultcs�j��t�dS)N)rr,r=r)�messager%rr�fqsz/FilterTests.test_error_after_default.<locals>.fz2UserWarning: FilterTests.test_ignore_after_defaultz&self.module.warn(message, UserWarning)r;)r<)rr2rr1r�captured_stderr�getvalue�assertInr0r=r>)r%r?rB�stderrr)rAr%r�test_error_after_defaultms

z$FilterTests.test_error_after_defaultc	Csjtjd|jd��P}|j��|jjdtd�|j�dt�|�t|�d�|�t	t
�dg�WdQRXdS)NT)�recordr�ignore)r<zFilterTests.test_ignorer�version)rr2rr1r0r=r,�assertEqual�len�listr
)r%r?rrr�test_ignores
zFilterTests.test_ignorec	sntjd�jd��T}�j��d���fdd�}|��jjdtd�|�|���t|�d�WdQRXdS)	NT)rHrz%FilterTests.test_ignore_after_defaultcs�j��t�dS)N)rr,r=r)rAr%rrrB�sz0FilterTests.test_ignore_after_default.<locals>.frI)r<�)rr2rr1r0r=rKrL)r%r?rBr)rAr%r�test_ignore_after_default�s
z%FilterTests.test_ignore_after_defaultc	s�tjd�jd���}�j���jjdtd�d���fdd�}|���t|�d���|d	jj	d
��|���t|�d���|d	jj	d
��WdQRXdS)NT)rHr�always)r<zFilterTests.test_alwayscs�j��t�dS)N)rr,r=r)rAr%rrrB�sz"FilterTests.test_always.<locals>.frO���r�)
rr2rr1r0r=rKrLrA�args)r%r?rBr)rAr%r�test_always�s
zFilterTests.test_alwaysc	s�tjd�jd���}�j��d���fdd�}|���t|�d���|djjd��|���t|�d��jjd	t	d
�|���t|�d���|djjd��|���t|�d���|djjd��WdQRXdS)
NT)rHrz$FilterTests.test_always_after_ignorecs�j��t�dS)N)rr,r=r)rAr%rrrB�sz0FilterTests.test_always_after_default.<locals>.frOrRrrQ)r<rS�)
rr2rr1rKrLrArTr0r=)r%r?rBr)rAr%r�test_always_after_default�s"
z%FilterTests.test_always_after_defaultc	Cs�tjd|jd���}|j��|jjdtd�td�}xftd�D]Z}|j�|t�|dkrv|�|dj	|�|dd�=q>|d	kr�|�t
|�d�q>td
��q>WWdQRXdS)NT)rHr�default)r<zFilterTests.test_defaultrSrrRrOzloop variant unhandled)rr2rr1r0r=�ranger,rKrArL�
ValueError)r%r?rA�xrrr�test_default�s
zFilterTests.test_defaultc	Cs�tjd|jd��p}|j��|jjdtd�td�}|j�|t�|�|dj|�|dd�=|j�|t�|�t	|�d�WdQRXdS)NT)rHrr)r<zFilterTests.test_modulerRr)
rr2rr1r0r=r,rKrArL)r%r?rArrr�test_module�s

zFilterTests.test_modulec	Cs�tjd|jd���}|j��|jjdtd�td�}|j�|tdd�|�|dj|�|dd�=|j�|tdd	�|�t	|�d
�|j�|tdd�|�t	|�d
�WdQRXdS)NT)rHrr
)r<zFilterTests.test_oncez__init__.py�*rR�
rztest_warnings2.py)
rr2rr1r0r=r-rKrArL)r%r?rArrr�	test_once�s

zFilterTests.test_oncec
Cs�tjd|jd���}|j�dt�|jjdtdddd�|�t|�d�|�t	��|jjdtdddd�WdQRX|�t|�d�|jjdtddid�|�t|�d	�WdQRXdS)
NT)rHrrQ�msg�filenamer^)�module_globalsrOrS)
rr2rrr=r-rKrLr>�	TypeError)r%r?rrr�test_module_globals�szFilterTests.test_module_globalsc	CsLtj|jd��4}|j��|jjdtd�|�t|jjdt�WdQRXdS)N)rr;)r<zFilterTests.test_inheritance)	rr2rr1r0�Warningr>r=r,)r%r?rrr�test_inheritance�s

zFilterTests.test_inheritancec	Cs�tjd|jd��~}|j��|jjdtd�|jjdtdd�|dd�=y|j�dt�Wntk
rx|�d�YnX|�t	|�d	�WdQRXdS)
NT)rHrrI)r<r;)r<�appendzFilterTests.test_orderingz!order handling for actions failedr)
rr2rr1r0r=r,ZfailrKrL)r%r?rrr�
test_orderings


zFilterTests.test_orderingc	Cs,tjd|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�WdQRXdS)NT)rHrr;�rzconvert to errorzhandle normallyrRrIzfiltered outzhex*zhex/octznonmatching text)rr2rr0rfr>r=r,r1rK�strrA�assertIsr<ZassertNotEqual)r%r?�textrrr�test_filterwarningss(

zFilterTests.test_filterwarningsc	Cs�tjd|jd��x}|j�dt�|j�ddt�|�t|jjd�|�t|jjd�|j�d�|�|g�|j�d�|�|g�WdQRXdS)	NT)rHrrIr;�matchzmatch prefixzsuffix matchzsomething completely different)	rr2rrr=r0r>r,rK)r%r?rrr�test_message_matching*sz!FilterTests.test_message_matchingc	s|G�fdd�d���fdd�td�D��tjd|jd��:}�|j_|j�td�dd	d
�|�t|dj	�d�WdQRXdS)NcseZdZ�fdd�ZdS)z.FilterTests.test_mutate_filter_list.<locals>.Xcsg�dd�<dS)Nr)r%�a)�Lrrro8sz4FilterTests.test_mutate_filter_list.<locals>.X.matchN)rrrror)rrrr�X7srscsg|]}d��t��df�qS)rXr)r=)�.0�i)rsrr�
<listcomp>;sz7FilterTests.test_mutate_filter_list.<locals>.<listcomp>rST)rHr�bzf.pyr^rR)
rYrr2rrr-r=rKrkrA)r%r?r)rrrsr�test_mutate_filter_list6sz#FilterTests.test_mutate_filter_listc	Cs�tj|jd���|j��|jjdtd�|�t|jj�d�|jjdtd�|jjdtd�|�t|jj�dd�|�|jjdddd	�WdQRXdS)
N)rr;)r<rOrIrSz(filterwarnings inserted duplicate filterrz>filterwarnings did not promote filter to the beginning of list)	rr2rr1r0r=rKrLr)r%rrr�%test_filterwarnings_duplicate_filtersBs
z1FilterTests.test_filterwarnings_duplicate_filtersc	Cs�tj|jd���|j��|jjdtd�|�t|jj�d�|jjdtd�|jjdtd�|�t|jj�dd�|�|jjdddd	�WdQRXdS)
N)rr;)r<rOrIrSz&simplefilter inserted duplicate filterrz<simplefilter did not promote filter to the beginning of list)	rr2rr1rr=rKrLr)r%rrr�#test_simplefilter_duplicate_filtersSs
z/FilterTests.test_simplefilter_duplicate_filtersc	Cs�tj|jdd��t}|j��|j�d�|jjddd�|jjddd�|jjdtd�|�t|jj	�dd	�|�t|�d
d�WdQRXdS)NT)rrHrIr;)rh�test_append_duplicate)r<rSz&simplefilter inserted duplicate filterrz+appended duplicate changed order of filters)
rr2rr1rr,r=rKrLr)r%r?rrrr{cs

z!FilterTests.test_append_duplicateN)rrrr(r@rGrNrPrUrWr\r]r`rergrirnrprxryrzr{rrrrr:bs&	
r:c@seZdZeZdS)�CFilterTestsN)rrrr7rrrrrr|rsr|c@seZdZeZdS)�
PyFilterTestsN)rrrr9rrrrrr}usr}c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e
�ee
d�d�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�	WarnTestsz2Test warnings.warn() and warnings.warn_explicit().c	Csztjd|jd��`}|j�d�xLtd�D]@}d|}|j�|�|�t|dj�|�|�	|dj
t�q(WWdQRXdS)NT)rHrr
�zmulti %drR)rr2rrrYr,rKrkrArlr<r=)r%r?rurmrrr�test_message}szWarnTests.test_messagec
CsjxdtddfD]V}tjd|jd��<}|j�d�|j�|�|�t|dj�tt	|���WdQRXqWdS)Nr^T)rHrr
rR)
rfrr2rrr,rKrkrAr=)r%Zobr?rrr�test_warn_nonstandard_types�sz%WarnTests.test_warn_nonstandard_typesc
Cs~t|j��jtjd|jd��N}t�d�|�tj�	|dj
�d�t�d�|�tj�	|dj
�d�WdQRXWdQRXdS)NT)rHrZspam1rRz
stacklevel.pyZspam2)rrrr2r�innerrK�os�path�basenamerb�outer)r%r?rrr�
test_filename�s

zWarnTests.test_filenamec
Cs(t|j���tjd|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�WdQRXWdQRXdS)NT)rHrZspam3rO)rrRz
stacklevel.pyZspam4Zspam5rSz__init__.pyZspam6zspam6.5rVZspam7i'r)rrrr2rr�rKr�r�r�rbr�)r%r?rrr�test_stacklevel�s*zWarnTests.test_stacklevelc
Csvt�d�t|j��Xtjd|jd��<}|j�d�ddl}|�t	|�d�|�|dj
t�WdQRXWdQRXdS)Nz&test.test_warnings.data.import_warningT)rHrrQrrO)rZunloadrrrr2rZ&test.test_warnings.data.import_warningrKrLrb�__file__)r%r?�testrrr�test_stacklevel_import�s
z WarnTests.test_stacklevel_importc
Csptj}z\t`t|j��Dtjd|jd��(}tjddd�|�|djtj	�WdQRXWdQRXWd|t_XdS)NT)rHrZspam8rO)rrR)
rr�rrrr2r�rKrbr)r%rbr?rrr�test_missing_filename_not_main�s,z(WarnTests.test_missing_filename_not_main�argvztest needs sys.argvc
Cs�tj}tj}zft`dt_t|j��Htjd|jd��,}tjddd�|�|dj	t
jd�WdQRXWdQRXWd|t_|t_XdS)	N�__main__T)rHrZspam9rO)rrRr)rr�rrrrr2r�rKrbrr�)r%rb�module_namer?rrr�$test_missing_filename_main_with_argv�s0z.WarnTests.test_missing_filename_main_with_argvc
Cs�tj}tj}tj}zdt`dt_t`t|j��Btjd|jd��&}tj	ddd�|�
|djd�WdQRXWdQRXWd|t_|t_|t_XdS)Nr�T)rHrZspam10rO)rrR)rr�rrr�rrrr2r�rKrb)r%rbr�r�r?rrr�'test_missing_filename_main_without_argv�s*z1WarnTests.test_missing_filename_main_without_argvc
Cs�tj}tj}tj}zht`dt_dgt_t|j��Btjd|jd��&}tj	ddd�|�
|djd�WdQRXWdQRXWd|t_|t_|t_XdS)	Nr�rjT)rHrZspam11rO)rrR)rr�rrr�rrrr2r�rKrb)r%�	file_namer�r�r?rrr�1test_missing_filename_main_with_argv_empty_string�s*z;WarnTests.test_missing_filename_main_with_argv_empty_stringc
Cs�tjd|jd��x}|j��|jjdtd�xVdD]N}yt�|�Wntk
rZw2YnX|j�	dt|d�|�
|dj|�q2WWdQRXdS)	NT)rHrrQ)r<)u
nonasciié€usurrogate�rmrOrR)rr2rr1r0r=r��fsencode�UnicodeEncodeErrorr-rKrb)r%r?rbrrr�%test_warn_explicit_non_ascii_filename
s

z/WarnTests.test_warn_explicit_non_ascii_filenamec	CsT|�t|jjdtdd�|�t|jjdddd�|jttf|jjdtdddd�dS)NrOr^)�registry)r>rdrr-r=rrf)r%rrr�test_warn_explicit_type_errorss
z(WarnTests.test_warn_explicit_type_errorsc	Cs8Gdd�dt�}|�t��|j�|��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)rrrr(r�rrrr�
BadStrWarning-sr�)rfr>rZrr,)r%r�rrr�test_bad_str)szWarnTests.test_bad_strc
Cs�Gdd�dt�}Gdd�d�}|�t��}|j�dd�WdQRX|�dt|j��|�t��}|j�d|�WdQRX|�dt|j��|�t��}|j�d|��WdQRX|�dt|j��tj	|jd���|j�
�|j�d	�|�|��}|j�d
|�WdQRX|�
d
t|j��|�t��}|j�d
d�WdQRX|�
d
t|j��|�|��}|j�d
|�WdQRX|�|jt�WdQRXdS)Nc@seZdZdS)z6WarnTests.test_warning_classes.<locals>.MyWarningClassN)rrrrrrr�MyWarningClass7sr�c@seZdZdS)z:WarnTests.test_warning_classes.<locals>.NonWarningSubclassN)rrrrrrr�NonWarningSubclass:sr�zbad warning categoryrjz)category must be a Warning subclass, not )rrXzgood warning category)rfr>rdrr,rErkZ	exceptionrr2r1r0ZassertWarnsrKZwarningr=ZassertIsInstance)r%r�r��cmrrr�test_warning_classes6s4
zWarnTests.test_warning_classesN)rrrr(r�r�r�r�r�r�r�
skipUnlessr!rr�r�r�r�r�r�r�rrrrr~ys

r~c@seZdZeZdd�ZdS)�
CWarnTestscCs&|�t|j�|�t|jjd��dS)N�__code__)�assertIsNotrr�assertFalser!r,)r%rrr�test_acceleratedbszCWarnTests.test_acceleratedN)rrrr7rr�rrrrr�]sr�c@seZdZeZdd�ZdS)�PyWarnTestscCs&|�t|j�|�t|jjd��dS)Nr�)r�rrr3r!r,)r%rrr�test_pure_pythonkszPyWarnTests.test_pure_pythonN)rrrr9rr�rrrrr�fsr�c@seZdZdd�Zdd�ZdS)�
WCmdLineTestsc
Cstj|jd���|�|jj|jjd�|�|jj|jjd�|�|jj|jjd�|�|jj��|j�d�WdQRX|�|jj��|j�d�WdQRX|�|jj��|j�d�WdQRX|�|jjd��|j�d	�WdQRX|j�d
�|�t|jjd�WdQRXdS)N)rz1:2:3:4:5:6zbogus::Warningzignore:2::4:-5zignore::123zignore::123abczignore::===uWärninguignore::Wärningzerror::Warning::0zconvert to error)	rr2rr>�_OptionError�
_setoptionZassertRaisesRegexr=r,)r%rrr�test_improper_inputrs"


z!WCmdLineTests.test_improper_inputc
Cs�tj|jd���|j�d�|�|jj��|j�d�WdQRX|�|jj��|j�d�WdQRX|j�d�|�t��|j�dt�WdQRXWdQRXdS)N)rzignore::Warningzignore::TestWarningz ignore::test.test_warnings.bogusz%error::test.test_warnings.TestWarningztest warning)rr2rr�r>r�rr,)r%rrr�test_import_from_module�sz%WCmdLineTests.test_import_from_moduleN)rrrr�r�rrrrr�psr�c@seZdZeZdS)�CWCmdLineTestsN)rrrr7rrrrrr��sr�c@s eZdZeZdd�Zdd�ZdS)�PyWCmdLineTestscCs"tddd�\}}}|�d|�dS)Nz-Wxxxz-c�passs0Invalid -W option ignored: invalid action: 'xxx')rrE)r%�rc�outr�rrr�test_improper_option�sz$PyWCmdLineTests.test_improper_optioncCs0tddd�\}}}|�|���|�d|�dS)Nz-Wiz-cz?import sys; sys.modules['warnings'].warn('foo', RuntimeWarning)sRuntimeWarning)rr��strip�assertNotIn)r%r�r�r�rrr�test_warnings_bootstrap�sz'PyWCmdLineTests.test_warnings_bootstrapN)rrrr9rr�r�rrrrr��sr�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}|j�ddtdd�|�t|jjd�|j`|�t|jjd�WdQRXdS)N)rr;rjrzconvert to error)	rr2rr0rfr>r=r,r)r%r?rrr�test_filter�sz_WarningsTests.test_filterc	Cstd�}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	�WdQRXWd||j_XdS)
Nzonceregistry testT)rHrr
)r<�filer^rRr)r=r�onceregistryr
rr2r1r0r-rKrArLr,rT)r%rAZoriginal_registryr?rrr�test_onceregistry�s.


z _WarningsTests.test_onceregistryc	CsFtd�}|jj}�z$tjd|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�WdQRXWd||j_XdS)Nzdefaultaction testT)rHrz<test>r^)r�rRrOrSrJ�+rI�,r)r=r�
defaultactionrr2r1r-rKrArLrE)r%rAZoriginalr?r�r
rrr�test_default_action�s<


z"_WarningsTests.test_default_actionc
Csnd}tj|jd��F|jjdtd�|j`t�d��}|j�|�|�	�}WdQRXWdQRX|�
||�dS)Nzdel showwarning test)rrQ)r<rF)rr2rr0r=r.r�captured_outputr,rDrE)r%rm�stream�resultrrr�test_showwarning_missing�sz'_WarningsTests.test_showwarning_missingc
Cs�d}tj|jd��^|jjdtd�|jj}z4|j`t�d��}|j�|�|�	�}WdQRXWd||j_XWdQRX|�
||�dS)Nzdel _showwarnmsg test)rrQ)r<rF)rr2rr0r=�_showwarnmsgrr�r,rDrE)r%rm�showr�r�rrr�test_showwarnmsg_missing	sz'_WarningsTests.test_showwarnmsg_missingc
Csrtj|jd��Z|jjdtd�t|j_t�d��|j�	d�WdQRXd|j_|�
t|jj	d�WdQRXdS)N)rrQ)r<�stdoutzWarning!�)rr2rr0r=�printr.rr�r,r>rd)r%rrr�test_showwarning_not_callablesz,_WarningsTests.test_showwarning_not_callablec

Csd}tj|jd��D|jjdtd�|j`t�d��}t�	|�|�
�}WdQRXWdQRX|�|�d�dd|�|�
dd	�\}}tj�tj�d
d}|�dd
�}|\}}	}
}t|	�}	|�||�|�|
dtj�|�|d|�dt�||	���d}|�s
t�|�||�dS)Nztest show_warning)rrQ)r<rF�
rSzToo many newlines in %rrOrz.py�:rV� z  )rr2rr0r=r.rr�rr�rDrK�count�splitr�r��splitextr��rsplit�intr�	linecache�getliner��AssertionError)
r%rmr�r�Z
first_lineZsecond_lineZ
expected_fileZfirst_line_partsr��lineZ
warning_classrAZ
expected_linerrr�test_show_warning_output"s(


z'_WarningsTests.test_show_warning_outputc	Cstt�}|d}zVtjd|jd�}|�8}|jjdtd�d|d<t�dt�|�t|��WdQRXWd||d<XdS)Nr�T)rHrrQ)r<r�)	r rr2rr0r=r,r3rL)r%Zglobals_dictZoldfileZcatchr?rrr�test_filename_none9s
z!_WarningsTests.test_filename_nonecCs8tdd�\}}}|�|d�|�d|�|�d|�dS)Nz-czjimport sys; sys.stderr = None; import warnings; warnings.simplefilter('always'); warnings.warn('Warning!')�sWarning!sError)rrKr�)r%r�r�rFrrr�test_stderr_noneHs
z_WarningsTests.test_stderr_nonec
Cs�dd�}|j}tj|d���|jdtd�t���$}|jdtdd|d	�d
d�d�WdQRX|�d
|�	��|j
}zL|`
t���&}|jdtdd|d	g�d
d�d�WdQRX|�d|�	��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�
splitlinesYszr_WarningsTests.test_issue31285.<locals>.get_bad_loader.<locals>.BadLoader.get_source.<locals>.BadSource.splitlinesN)rrrr�r)r�rr�	BadSourceXsr�Zspam)rk)r%�fullnamer�)r�rr�
get_sourceWszT_WarningsTests.test_issue31285.<locals>.get_bad_loader.<locals>.BadLoader.get_sourceN)rrrr�r)r�rr�	BadLoaderVsr�r)r�r�r)r�r�get_bad_loaderUsz6_WarningsTests.test_issue31285.<locals>.get_bad_loader)rrX)r<�foo�barrOr^Zfoobar)�
__loader__r)rczUserWarning: fooZeggszUserWarning: eggs)rrr2r0r=rrCr-rErDr�)r%r��wmodrFr�rrr�test_issue31285Qs(	

z_WarningsTests.test_issue31285cCsp|j}tj|d��T|�d�t�|dd��0|�t��|jdt	dddd�WdQRXWdQRXWdQRXdS)N)rr
r�r�r�rO)r�)
rrr2r0r�	swap_attrr>rdr-rf)r%r�rrr�test_issue31411us
z_WarningsTests.test_issue31411cCs�|j}tj|d���ddtddfg|_|�t��|�dtdd�WdQRXg|_t�	|dd��,|�t��|�dtdd�WdQRXWdQRXWdQRXdS)N)rrr�r�rOr�)
rrr2rfrr>rdr-rr�)r%r�rrr�test_issue31416�sz_WarningsTests.test_issue31416cCsxtj|jd��`|jjdtd�t�t�dd��4t�t�dd��|�t|jj	d�WdQRXWdQRXWdQRXdS)N)rr;)r<rsfoor�r�)
rr2rr0r=rZ	swap_itemr r>r,)r%rrr�test_issue31566�s
z_WarningsTests.test_issue31566N)rrrr(r7rr�r�r�r�r�r�r�r�r�r�rZcpython_onlyr�r�r�rrrrr��s
%		$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)Nrarz.pyrVz%s:%s: %s: %s
  %s
z
 for the win!)
rfr�r�r�rr�r�r�r�rrKrr/)r%rAr<r��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)Nrz.pyrVrazfor the win!)r�r�r�rr�r�r�r�rfrrr/r.rKrD)r%r�r�Zexpected_file_linerAr<�file_objectr�rrr�test_showwarning�s$z%WarningsDisplayTests.test_showwarningc		Cs�dd�}tj�tj�dd}d}t�||���}d}t}t	�}d|�d|�d	|�d
|��d|��}t
�|jd|��,|j�
||||||�|�|��|�WdQRXdS)
Nc
Ss"d|�d|�d|�d|�d|��
S)Nzm=z:c=z:f=z:l=z:t=r)rAr<rb�linenormrrr�myformatwarning�szIWarningsDisplayTests.test_formatwarning_override.<locals>.myformatwarningrz.pyrVrazm=z:c=z:f=z:l=z:t=r/)r�r�r�rr�r�r�r�rfrrr�rr.rKrD)	r%r�r�r�r�rAr<r��expectedrrr�test_formatwarning_override�sz0WarningsDisplayTests.test_formatwarning_overrideN)rrrr(r�r�r�rrrrr��sr�c@seZdZeZdS)�CWarningsDisplayTestsN)rrrr7rrrrrr��sr�c@seZdZeZdd�ZdS)�PyWarningsDisplayTestsc	Cs�|�tjtj�ttjd��}|�t�d��WdQRXdd�}|dtj�}t�d�}|jtjd��	�}|�
||�|ddd	tj�}t�d
�}|jtjd��	�}|�
||�dS)Nr?z�
                def func():
                    f = open(__file__)
                    # Emit ResourceWarning
                    f = None

                func()
            cWs6t|�}|j�dd�}d�|���}t�dd|�}|S)N�ascii�replacer�z<.*>z<...>)rr��decode�joinr��re�sub)rTZresrFrrr�run�s
z4PyWarningsDisplayTests.test_tracemalloc.<locals>.runz-Wdz�
            {fname}:5: ResourceWarning: unclosed file <...>
              f = None
            ResourceWarning: Enable tracemalloc to get the object allocation traceback
        )Zfnamez-Xz
tracemalloc=2a
            {fname}:5: ResourceWarning: unclosed file <...>
              f = None
            Object allocated at (most recent call last):
              File "{fname}", lineno 7
                func()
              File "{fname}", lineno 3
                f = open(__file__)
        )Z
addCleanupr�unlinkZTESTFN�open�write�textwrap�dedentr�r�rK)r%�fpr�rFr�rrr�test_tracemalloc�s
z'PyWarningsDisplayTests.test_tracemallocN)rrrr9rrrrrrr��sr�c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�CatchWarningTestszTest catch_warnings().c	Cs�|j}|j}|j}|j|dd��t�|_|_WdQRX|�|j|�|�|j|�|j|dd��t�|_|_WdQRX|�|j|�|�|j|�dS)NT)rrHF)rrr.r2�objectrl)r%r��orig_filters�orig_showwarningrrr�test_catch_warnings_restoresz-CatchWarningTests.test_catch_warnings_restorec	Cs|j}|j|dd���}|�|g�|�t|�t�|�d�|�d�|�t|dj	�d�|�d�|�t|dj	�d�|�t|dj	�d�|�t|dj	�d�|dd�=|�|g�WdQRX|j
}|j|d	d��}|�|�|�|j
|�WdQRXdS)
NT)rrHrQr�rRr�rrOF)rr2rKrl�typerMrr,rkrAr.�assertIsNone)r%r�r?r
rrr�test_catch_warnings_recording"s"




z/CatchWarningTests.test_catch_warnings_recordingc	Cs~|j}|j|dd�}|�t|j�|�|�t|j�WdQRX|j|dd�}|�t|j�|�|�t|j�WdQRXdS)NT)rrHF)rr2r>�RuntimeError�__exit__�	__enter__)r%r�r[rrr�!test_catch_warnings_reentry_guard7sz3CatchWarningTests.test_catch_warnings_reentry_guardc	Cs�|j}|j}|j}|j|d��,}|�|�|�|j|�|�|j|�WdQRX|�|j|�|tjdkr�|���,}|�|�|�|j|�|�|j|�WdQRX|�|j|�dS)N)rr)	rrr.r2r
rlr�rr")r%r�r	r
r?rrr�test_catch_warnings_defaultsDs


z.CatchWarningTests.test_catch_warnings_defaultsc
s�d}|j}g�d
�fdd�	}t�|d|��P|j|dd��(}|�|j|�|�d�|�|�WdQRX|�|j|�WdQRX|�	t
|�d|�|�	|d	jjd	|�|�	�g�dS)NzThis is a warningcs��|�dS)N)rh)rAr<rbr�r�r�)�my_logrr�	my_logger]szLCatchWarningTests.test_record_override_showwarning_before.<locals>.my_loggerr.T)rrHrQrOr)NN)
rrr�r2r�r.rr,rlrKrLrArT)r%rmr�r�logr)rr�'test_record_override_showwarning_beforeVs
z9CatchWarningTests.test_record_override_showwarning_beforec	s�d}|j}g�d	�fdd�	}|j|dd�� }|�d�||_|�|�WdQRX|�t��d��|��djd|�|�|g�dS)
NzThis is a warningcs��|�dS)N)rh)rAr<rbr�r�r�)rrrrvszLCatchWarningTests.test_record_override_showwarning_inside.<locals>.my_loggerT)rrHrQrOr)NN)rr2rr.r,rKrLrT)r%rmr�rrr)rr�'test_record_override_showwarning_insideos
z9CatchWarningTests.test_record_override_showwarning_insidec
Csr|j}|tjdk	r|�d�tjdd���}|�|jg�|�d�|�	d�|�t
|j�d�|�	d�|�t
|j�d�|�t
|jdj�d�|�t
|jd	j�d�|��|�|jg�WdQRXt���WdQRXt�dt
f��|�	d�WdQRX|�t�� t�d
tf��WdQRXWdQRX|�t��*t�dtf��|�	d�WdQRXWdQRXdS)Nrz,module to test is not loaded warnings moduleF)�quietrQr�r�rrOrj)rrr"ZskipTestrZcheck_warningsrKrrr,rkrA�resetr=r>r��RuntimeWarning)r%r�r?rrr�test_check_warnings�s0





z%CatchWarningTests.test_check_warningsN)rrrr(rrrrrrrrrrrrs
rc@seZdZeZdS)�CCatchWarningTestsN)rrrr7rrrrrr�src@seZdZeZdS)�PyCatchWarningTestsN)rrrr9rrrrrr�src@sPeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�	e
��dkd�d
d��ZdS)�EnvironmentVariableTestscCs&tddddd�\}}}|�|d�dS)Nz-cz2import sys; sys.stdout.write(str(sys.warnoptions))zignore::DeprecationWarningrj)�PYTHONWARNINGS�
PYTHONDEVMODEs['ignore::DeprecationWarning'])rrK)r%r�r�rFrrr�test_single_warning�s
z,EnvironmentVariableTests.test_single_warningcCs&tddddd�\}}}|�|d�dS)Nz-cz2import sys; sys.stdout.write(str(sys.warnoptions))z1ignore::DeprecationWarning,ignore::UnicodeWarningrj)r r!s8['ignore::DeprecationWarning', 'ignore::UnicodeWarning'])rrK)r%r�r�rFrrr�test_comma_separated_warnings�sz6EnvironmentVariableTests.test_comma_separated_warningscCs(tdddddd�\}}}|�|d�dS)Nz-Wignore::UnicodeWarningz-cz2import sys; sys.stdout.write(str(sys.warnoptions))zignore::DeprecationWarningrj)r r!s8['ignore::DeprecationWarning', 'ignore::UnicodeWarning'])rrK)r%r�r�rFrrr�test_envvar_and_command_line�sz5EnvironmentVariableTests.test_envvar_and_command_linecCs>tdddddd�\}}}|�|d�|�|��dd	d
g�dS)Nz-Werror::DeprecationWarningz-czjimport sys, warnings; sys.stdout.write(str(sys.warnoptions)); warnings.warn('Message', DeprecationWarning)zdefault::DeprecationWarningrj)r r!s<['default::DeprecationWarning', 'error::DeprecationWarning']s"Traceback (most recent call last):s&  File "<string>", line 1, in <module>sDeprecationWarning: Message)rrKr�)r%r�r�rFrrr�(test_conflicting_envvar_and_command_line�s
zAEnvironmentVariableTests.test_conflicting_envvar_and_command_linec
	Cs�|jtk}trg}nT|r$t�d�}nd}ddt|dfddtddfddtddfddtddfddtddfg}dd�|D�}|r�d}nd}|d	7}t	d
|dd�\}}}d
d�|�
�D�}	d|_|�|	|�dS)Nr�rXrrIcSsg|]}t|����qSr)rk�encode)rtrBrrrrv�szNEnvironmentVariableTests.test_default_filter_configuration.<locals>.<listcomp>zPimport sys; sys.modules.pop('warnings', None); sys.modules['_warnings'] = None; rjz5import warnings; [print(f) for f in warnings.filters]z-cT)Z
__isolatedcSsg|]}|���qSr)r�)rtr�rrrrv�s)
rr9�Py_DEBUGr��compile�DeprecationWarning�PendingDeprecationWarning�
ImportWarning�ResourceWarningrr�ZmaxDiffrK)
r%Zpure_python_apiZexpected_default_filtersZmain_module_filterZexpected_output�coder�r�rFZstdout_linesrrr�!test_default_filter_configuration�s(
z:EnvironmentVariableTests.test_default_filter_configurationr�z%requires non-ascii filesystemencodingcCs.tdddddd�\}}}|�|d�d��dS)Nz-cz2import sys; sys.stdout.write(str(sys.warnoptions))zutf-8uignore:DeprecaciónWarningrj)ZPYTHONIOENCODINGr r!u['ignore:DeprecaciónWarning'])rrKr&)r%r�r�rFrrr�
test_nonascii�sz&EnvironmentVariableTests.test_nonasciiN)
rrrr"r#r$r%r.rr�r�getfilesystemencodingr/rrrrr�s
rc@seZdZeZdS)�CEnvironmentVariableTestsN)rrrr7rrrrrr1�sr1c@seZdZeZdS)�PyEnvironmentVariableTestsN)rrrr9rrrrrr2�sr2c@seZdZdd�ZdS)�
BootstrapTestc
CsNt���<}t�d��&tdd|d�tdddd|d�WdQRXWdQRXdS)N�	encodingsz-cr�)Z
PYTHONPATHz-WrQ)rZtemp_cwdr)r%�cwdrrr�test_issue_8766szBootstrapTest.test_issue_8766N)rrrr6rrrrr3sr3c@s"eZdZejdd��Zdd�ZdS)�FinalizationTestcCs(d}td|�\}}}|�|��d�dS)Nzk
import warnings
warn = warnings.warn

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

a=A()
        z-cz__main__:7: UserWarning: test)rrKr�)r%r-r�r�r�rrr�test_finalizations
z"FinalizationTest.test_finalizationcCshd}dt}tdd|�\}}}|�|�|�t|��dt}tdd|�\}}}|�|�|�t|��dS)Ns&sys:1: ResourceWarning: unclosed file zf = open(%a)z-Wdz-czimport warnings; f = open(%a))r�rr3�
startswithr�)r%r�r-r�r�r�rrr�test_late_resource_warning!sz+FinalizationTest.test_late_resource_warningN)rrrrZrequires_type_collectingr8r:rrrrr7
sr7cCstj��tj��dS)N)r9r�rr7rrrr�setUpModule3s
r;r�):�
contextlibrr�r��iorr�rrrr�rZtest.support.script_helperrrZtest.test_warnings.datarrrrZimport_fresh_moduler9r7r!r'rrfrrr*ZTestCaser6r8r:r|r}r~r�r�r�r�r�r�r�r�r�rrrrr1r2r3r7r;ZtearDownModuler�mainrrrr�<module>sd
e	
#p@2P
&