a  ze5@sddlmZddlZddlZddlmZddlZddlZddlZddl Z ddl m Z ddl m Z mZddlmZddlZe jddgd Ze jddgd Zeed Zed d ZGdddeZGdddZGdddeZGdddee jZGdddee jZ GdddeZ!Gddde!e jZ"Gddde!e jZ#GdddeZ$Gd d!d!e$e jZ%Gd"d#d#e$e jZ&Gd$d%d%eZ'Gd&d'd'e'e jZ(Gd(d)d)e'e jZ)Gd*d+d+ee jZ*Gd,d-d-eZ+Gd.d/d/e+e jZ,Gd0d1d1e+e jZ-Gd2d3d3eZ.Gd4d5d5e.e jZ/Gd6d7d7e.e jZ0Gd8d9d9eZ1Gd:d;d;e1e jZ2Gdd?d?e jZ4Gd@dAdAe jZ5dBdCZ6e6Z7e8dDkre 9dS)E)contextmanagerN)StringIO)support)assert_python_okassert_python_failure stacklevelwarnings _warnings)Zblocked)ZfreshZgettotalrefcountc csttfD]&}z|jWqty,Yq0qz tWntyNYn0tj}|j}z4|dd|_|d|t_dVW|t_||_n|t_||_0dS)z8Use a specific warnings implementation in warning_tests.Nonce) sys warning_tests__warningregistry__clearAttributeError NameErrorr filters simplefilter)moduleZto_clearoriginal_warningsZoriginal_filtersrO/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_warnings/__init__.pywarnings_states(     rc@s eZdZdS) TestWarningN__name__ __module__ __qualname__rrrrr.srcs,eZdZdZfddZfddZZS)BaseTestz'Basic bookkeeping required for testing.cs`tjj|_dtvrtd=ttdr*t`ttdr8t`|j tj d<|j tj_t t | dS)Nrr )unittestcaser old_unittest_moduleglobalshasattrr rr rmodulessuperrsetUpself __class__rrr&6s      zBaseTest.setUpcs&ttjd<|jtj_tt| dS)Nr ) rr r$r!rr r r%rtearDownr'r)rrr+Is  zBaseTest.tearDown)rrr__doc__r&r+ __classcell__rrr)rr2s rc@seZdZdZddZdS)PublicAPITestszGEnsures that the correct values are exposed in the public API. cCs6|t|jdgd}|t|jjt|dS)N__all__)warn warn_explicit showwarning formatwarningfilterwarningsr resetwarningscatch_warnings) assertTruer#rZassertSetEqualsetr/)r(Z target_apirrrtest_module_all_attributeTs z(PublicAPITests.test_module_all_attributeN)rrrr,r9rrrrr.Nsr.c@seZdZeZdS)CPublicAPITestsNrrr c_warningsrrrrrr:\sr:c@seZdZeZdS)PyPublicAPITestsNrrr py_warningsrrrrrr=_sr=c@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd d!Zd"d#Zd$d%Zd&S)' FilterTestsz$Testing the filtering functionality.cCs^tj|jd<}|j|jjdtd|t|jjdWdn1sP0YdS)NrerrorcategoryFilterTests.test_error)rr6rr5r4 UserWarning assertRaisesr0r(wrrr test_errorfs   rEc stjjd}jdfdd}t}|Wdn1sP0Y|}d|d|jjdt d t |Wdn1s0YdS) NrA%FilterTests.test_ignore_after_defaultcsjtdSNrr0rFrmessager(rrfqsz/FilterTests.test_error_after_default..fz2UserWarning: FilterTests.test_ignore_after_defaultz&self.module.warn(message, UserWarning)rBrC) rr6rr5rcaptured_stderrgetvalueassertInr4rFrG)r(rIrPstderrrrNrtest_error_after_defaultms  $z$FilterTests.test_error_after_defaultcCs~tjd|jdZ}|j|jjdtd|jdt|t|d|t t dgWdn1sp0YdS)NTrecordrignorerCFilterTests.test_ignorerversion) rr6rr5r4rFr0 assertEquallenlistrrHrrr test_ignores rYcstjdjd^}jdfdd}|jjdtd||t|dWdn1st0YdS) NTrVrKcsjtdSrLrMrrNrrrPsz0FilterTests.test_ignore_after_default..frXrC)rr6rr5r4rFr[r\r(rIrPrrNrtest_ignore_after_defaults rKcstjdjd}jjjdtddfdd}|t|d|d jj d |t|d |d jj d Wdn1s0YdS) NTrValwaysrCFilterTests.test_alwayscsjtdSrLrMrrNrrrPsz"FilterTests.test_always..fr_r) rr6rr5r4rFr[r\rOargsr`rrNr test_alwayss rccstjdjd}jdfdd}|t|d|djjd|t|djjd t d |t|d |djjd|t|d |djjdWdn1s0YdS) NTrVz$FilterTests.test_always_after_ignorecsjtdSrLrMrrNrrrPsz0FilterTests.test_always_after_default..fr_rdrrbrCre) rr6rr5r[r\rOrfr4rFr`rrNrtest_always_after_defaults& z%FilterTests.test_always_after_defaultcCstjd|jd}|j|jjdtdtd}tdD]Z}|j|t|dkrt||dj ||dd=q<|d kr|t |dq}|j|jjdtd|t|jjdtWdn1sR0YdS)NrArBrCFilterTests.test_inheritance) rr6rr5r4WarningrGrFr0rHrrrtest_inheritances   r~c Cstjd|jd}|j|jjdtd|jjdtdd|dd=z|jdtWntyv|dYn0|t |d Wdn1s0YdS) NTrVrXrCrB)rDappendFilterTests.test_orderingz!order handling for actions failedr) rr6rr5r4rFr0Zfailr[r\rHrrr test_orderings    rcCsBtjd|jd}|jddtdd|t|jjd|jd}|j|| t |dj || |dj t|jd dtddd }|j||t |dj ||j|jdd tdd|t|jjd d }|j|| t |dj || |dj tWdn1s40YdS)NTrVrBrconvert to errorzhandle normallyrdrXz filtered outzhex*zhex/octznonmatching text)rr6rr4rrGrFr0r5r[strrOassertIsrDZassertNotEqual)r(rItextrrrtest_filterwarningss,     zFilterTests.test_filterwarningscCstjd|jd}|jdt|jddt|t|jjd|t|jjd|jd||g|jd||gWdn1s0YdS) NTrVrXrBmatchz match prefixz suffix matchzsomething completely different) rr6rrrFr4rGr0r[rHrrrtest_message_matching*s   z!FilterTests.test_message_matchingcsGfdddfddtdDtjd|jdD}|j_|jtddd d |t|d j dWdn1s0YdS) NcseZdZfddZdS)z.FilterTests.test_mutate_filter_list..Xcsgdd<dSrLr)r(aLrrr8sz4FilterTests.test_mutate_filter_list..X.matchN)rrrrrrrrX7srcsg|]}dtdfqS)rjr)rF).0i)rrr ;z7FilterTests.test_mutate_filter_list..reTrVbzf.pyrurd) rlrr6rrr1rFr[rrOrHr)rrrtest_mutate_filter_list6sz#FilterTests.test_mutate_filter_listcCstj|jd|j|jjdtd|t|jjd|jjdtd|jjdtd|t|jjdd||jjdddd Wdn1s0YdS) 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_filterscCstj|jd|j|jjdtd|t|jjd|jjdtd|jjdtd|t|jjdd||jjdddd Wdn1s0YdS) NrArBrCr_rXre&simplefilter inserted duplicate filterrzrrrrrusrc@s`eZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ dS) WarnTestsz2Test warnings.warn() and warnings.warn_explicit().cCstjd|jdf}|jdtdD]@}d|}|j||t|dj|| |dj t q&Wdn1s|0YdS)NTrVr zmulti %drd) rr6rrrlr0r[rrOrrDrF)r(rIrrrrr test_message}s   zWarnTests.test_messagec CsztddfD]j}tjd|jdF}|jd|j||t|djtt |Wdq 1sj0Yq dS)NruTrVr rd) rrr6rrr0r[rrOrF)r(obrIrrrtest_warn_nonstandard_typess  z%WarnTests.test_warn_nonstandard_typesc Cst|jtjd|jdX}td|tj |dj dt d|tj |dj dWdn1sz0YWdn1s0YdS)NTrVZspam1rd stacklevel.pyZspam2 rrrr6r innerr[ospathbasenameryZouterrHrrr test_filenames   zWarnTests.test_filenamec CsVt|j4tjd|jd}tjddd|tj |dj dtj ddd|tj |dj dtjd d d|tj |dj d tj d d d|tj |dj dtj d dd|tj |dj d tjddd|tj |dj dWdn1s(0YWdn1sH0YdS)NTrVZspam3r_rrdrZspam4Zspam5rertZspam6zspam6.5rhZspam7i'r rrHrrrtest_stacklevels:zWarnTests.test_stacklevelc Cstdt|jvtjd|jdF}|jdddl}|t |d||dj t Wdn1sr0YWdn1s0YdS)Nz&test.test_warnings.data.import_warningTrVrbrr_) rZunloadrrrr6rZ&test.test_warnings.data.import_warningr[r\ry__file__)r(rItestrrrtest_stacklevel_imports   z WarnTests.test_stacklevel_importcCsjd}td|d}tjdd(}|jjdtdt|Wdn1sJ0Y||dj|dS) Nzz3import warnings warnings.warn('hello', UserWarning)execT)rWrbrCr) compilerr6rrrFrr[ry)r(ryZcodeobjrIrrrtest_exec_filenames&zWarnTests.test_exec_filenamec Cstjd|jd~}|j|jjdtddD]N}zt|WntyXYq0Yn0|j dt|d| |dj |q0Wdn1s0YdS) NTrVrbrC)u nonasciié€u surrogaterr_rd) rr6rr5r4rFrfsencodeUnicodeEncodeErrorr1r[ry)r(rIryrrr%test_warn_explicit_non_ascii_filenames   z/WarnTests.test_warn_explicit_non_ascii_filenamec CsT|t|jjdtdd|t|jjdddd|jttf|jjdtdddddS)Nr_ruregistry)rGr|rr1rFrrr'rrrtest_warn_explicit_type_errorss    z(WarnTests.test_warn_explicit_type_errorscCsLGdddt}|t|j|Wdn1s>0YdS)Nc@seZdZdZddZdS)z-WarnTests.test_bad_str..BadStrWarningz-Warning with a bad format string for __str__.cSs dddiS)NzA bad formatted string %(err)errzthere is no %(err)srr'rrr__str__sz5WarnTests.test_bad_str..BadStrWarning.__str__N)rrrr,rrrrr BadStrWarningsr)rrGrmrr0)r(rrrr test_bad_strs zWarnTests.test_bad_strc Cs*Gdddt}Gddd}|t}|jddWdn1sL0Y|dt|j|t}|jd|Wdn1s0Y|dt|j|t }|jd|Wdn1s0Y|dt|jtj |jd|j |j d | |}|jd |Wdn1sV0Y| d t|j| t}|jd dWdn1s0Y| d t|j| |}|jd |Wdn1s0Y||jtWdn1s0YdS) Nc@s eZdZdS)z6WarnTests.test_warning_classes..MyWarningClassNrrrrrMyWarningClasssrc@s eZdZdS)z:WarnTests.test_warning_classes..NonWarningSubclassNrrrrrNonWarningSubclasssrzbad warning categoryrz)category must be a Warning subclass, not rArjzgood warning category)rrGr|rr0rSr exceptionrr6r5r4Z assertWarnsr[warningrFZassertIsInstance)r(rrcmrrrtest_warning_classess: , , .   . . .zWarnTests.test_warning_classesN)rrrr,rrrrrrrrrrrrrrrys       rc@seZdZeZddZdS) CWarnTestscCs&|t|j|t|jjddSN__code__) assertIsNotrr assertFalser#r0r'rrrtest_accelerated#szCWarnTests.test_acceleratedN)rrrr<rrrrrrrsrc@seZdZeZddZdS) PyWarnTestscCs&|t|j|t|jjddSr)rrrr7r#r0r'rrrtest_pure_python,szPyWarnTests.test_pure_pythonN)rrrr?rrrrrrr'src@seZdZddZddZdS) WCmdLineTestsc Cstj|jd\||jj|jjd||jj|jjd||jj|jjd||jj|jdWdn1s0Y||jj|jdWdn1s0Y||jj|jdWdn1s0Y||jjd|jd Wdn1s60Y|jd |t|jjd Wdn1st0YdS) NrAz 1:2:3:4:5:6zbogus::Warningzignore:2::4:-5z ignore::123zignore::123abcz ignore::===uWärninguignore::Wärningzerror::Warning::0r) rr6rrG _OptionError _setoptionZassertRaisesRegexrFr0r'rrrtest_improper_input3s(   ***, z!WCmdLineTests.test_improper_inputc Cstj|jd|jd||jj|jdWdn1sL0Y||jj|jdWdn1s0Y|jd|t|jdtWdn1s0YWdn1s0YdS)NrAzignore::Warningzignore::TestWarningz ignore::test.test_warnings.bogusz%error::test.test_warnings.TestWarningz test warning)rr6rrrGrrr0r'rrrtest_import_from_moduleHs **  z%WCmdLineTests.test_import_from_moduleN)rrrrrrrrrr1src@seZdZeZdS)CWCmdLineTestsNr;rrrrrTsrc@s eZdZeZddZddZdS)PyWCmdLineTestscCs"tddd\}}}|d|dS)Nz-Wxxx-cpasss0Invalid -W option ignored: invalid action: 'xxx')rrSr(rcoutrrrrtest_improper_option[sz$PyWCmdLineTests.test_improper_optioncCs0tddd\}}}|||d|dS)Nz-Wirz?import sys; sys.modules['warnings'].warn('foo', RuntimeWarning)sRuntimeWarning)rrstrip assertNotInrrrrtest_warnings_bootstrapbs  z'PyWCmdLineTests.test_warnings_bootstrapN)rrrr?rrrrrrrrXsrc@seZdZdZeZddZddZddZdd Z d d Z d d Z ddZ ddZ ddZddZejddZejddZejddZdS)_WarningsTestsz'Tests specific to the _warnings module.cCsptj|jdN}|jddtdd|t|jjd|j`|t|jjdWdn1sb0YdS)NrArBrrr) 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 Wdn1s0YW||j_n ||j_0dS) Nzonceregistry testTrVr rCfilerurdr)rFr onceregistryrrr6r5r4r1r[rOr\r0rf)r(rOZoriginal_registryrIrrrtest_onceregistry|s2    2z _WarningsTests.test_onceregistrycCsdtd}|jj}zBtjd|jd}|ji}|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 |dWdn1s@0YW||j_n ||j_0dS)Nzdefaultaction testTrVzrurrdr_rerZ+rX,r) rFr defaultactionrr6r5r1r[rOr\rS)r(rOZoriginalrIrrrrrtest_default_actionsF    2z"_WarningsTests.test_default_actionc Csd}tj|jdd|jjdtd|j`td$}|j|| }Wdn1s^0YWdn1s|0Y| ||dS)Nzdel showwarning testrArbrCrT) rr6rr4rFr2rcaptured_outputr0rRrS)r(rstreamresultrrrtest_showwarning_missings  Dz'_WarningsTests.test_showwarning_missingc Csd}tj|jd|jjdtd|jj}zP|j`td$}|j|| }Wdn1sh0YW||j_n ||j_0Wdn1s0Y| ||dS)Nzdel _showwarnmsg testrArbrCrT) rr6rr4rF _showwarnmsgrrr0rRrS)r(rshowrrrrrtest_showwarnmsg_missings  (2z'_WarningsTests.test_showwarnmsg_missingc Cstj|jdx|jjdtdt|j_td|j dWdn1sT0Yd|j_| t |jj dWdn1s0YdS)NrArbrCstdoutzWarning!) rr6rr4rFprintr2rrr0rGr|r'rrrtest_showwarning_not_callables *z,_WarningsTests.test_showwarning_not_callablec Cs8d}tj|jdb|jjdtd|j`td"}t || }Wdn1s\0YWdn1sz0Y| | ddd|| dd \}}tjtjd d }|d d }|\}} } } t| } | ||| | dtj| | d|dt|| d} | || dS)Nztest show_warningrArbrCrT rezToo many newlines in %rr_r.py:rh z )rr6rr4rFr2rrr rrRr[countsplitrrsplitextrrsplitintr linecachegetliner) r(rrrZ first_lineZ second_lineZ expected_fileZfirst_line_partsrlineZ warning_classrOZ expected_linerrrtest_show_warning_outputs(  D   z'_WarningsTests.test_show_warning_outputc Cst}|d}zrtjd|jd}|B}|jjdtdd|d<tdt|t|Wdn1sl0YW||d<n ||d<0dS)NrTrVrbrCr) r"rr6rr4rFr0r7r\)r(Z globals_dictZoldfileZcatchrIrrrtest_filename_nones .z!_WarningsTests.test_filename_nonecCs8tdd\}}}||d|d||d|dS)Nrzjimport sys; sys.stderr = None; import warnings; warnings.simplefilter('always'); warnings.warn('Warning!')rsWarning!sError)rr[rr(rrrTrrrtest_stderr_none s    z_WarningsTests.test_stderr_nonec Csdd}|j}tj|d|jdtdt.}|jdtdd|d d d d Wdn1sf0Y|d | |j }zf|` t0}|jdtdd|d gd d d Wdn1s0Y|d| W||_ n||_ 0Wdn1s 0YdS)NcsGfddd}|S)NcseZdZfddZdS)zI_WarningsTests.test_issue31285..get_bad_loader..BadLoadercsGfdddt}|dS)NcseZdZfddZdS)zg_WarningsTests.test_issue31285..get_bad_loader..BadLoader.get_source..BadSourcecsSrLrr'splitlines_ret_valrr splitlinesszr_WarningsTests.test_issue31285..get_bad_loader..BadLoader.get_source..BadSource.splitlinesN)rrrrrrrr BadSourcesrZspam)r)r(fullnamerrrr get_sourceszT_WarningsTests.test_issue31285..get_bad_loader..BadLoader.get_sourceN)rrrrrrrr BadLoadersrr)rrrrrget_bad_loadersz6_WarningsTests.test_issue31285..get_bad_loaderrArjrCfoobarr_ruZfoobar) __loader__rrzzUserWarning: fooZeggszUserWarning: eggs) rrr6r4rFrrQr1rSrRr)r(rwmodrTrrrrtest_issue31285s0  $ $z_WarningsTests.test_issue31285c Cs|j}tj|d|dt|ddN|t$|jdt ddddWdn1sb0YWdn1s0YWdn1s0YdS)NrAr rrrr_r) rrr6r4r swap_attrrGr|r1rr(rrrrtest_issue314116s   z_WarningsTests.test_issue31411c Cs|j}tj|dddtddfg|_|t |dtddWdn1sV0Yg|_t |ddJ|t |dtddWdn1s0YWdn1s0YWdn1s0YdS)NrArrrr_r) rrr6rrrGr|r1rr r rrrtest_issue31416As .z_WarningsTests.test_issue31416c Cstj|jd|jjdtdttddRttdd"|t|jj dWdn1sj0YWdn1s0YWdn1s0YdS)NrArBrCrsfoorr) rr6rr4rFrZ swap_itemr"rGr0r'rrrtest_issue31566Ps z_WarningsTests.test_issue31566N)rrrr,r<rrrrrrrrrrr rZ cpython_onlyr r rrrrrrls$ %   $  rc@s(eZdZdZddZddZddZdS) WarningsDisplayTestsziTest the displaying of warnings and the ability to overload functions related to displaying warnings.c Csd}t}tjtjdd}d}t||}d}||||j ||f}| ||j |||||d7}||||j ||f}| ||j |||||dS)Nrxrrrhz%s:%s: %s: %s %s z for the win!) rrrrr rrrrrr[rr3)r(rOrD file_nameline_num file_lineformatexpectrrrtest_formatwarning`s&  z'WarningsDisplayTests.test_formatwarningcCstjtjdd}d}t||}d}t}t }|j ||||}|j |||||| |||d7}|j |||||}t }|j ||||||| ||dS)Nrrrhrxz for the win!)rrrr rrrrrrrr3r2r[rR)r(rrZexpected_file_linerOrD file_objectrrrrtest_showwarningrs,  z%WarningsDisplayTests.test_showwarningc Csdd}tjtjdd}d}t||}d}t}t }d|d|d |d |d |}t |j d |6|j |||||||||Wdn1s0YdS) Nc Ss"d|d|d|d|d| S)Nm=:c=:f=:l=:t=r)rOrDrylinenorrrrmyformatwarningszIWarningsDisplayTests.test_formatwarning_override..myformatwarningrrrhrxrrrrrr3)rrrr rrrrrrrr rr2r[rR) r(rrrrrOrDrexpectedrrrtest_formatwarning_overridesz0WarningsDisplayTests.test_formatwarning_overrideN)rrrr,rrr rrrrr[src@seZdZeZdS)CWarningsDisplayTestsNr;rrrrr!sr!c@seZdZeZddZdS)PyWarningsDisplayTestsc Cs|tjtjttjd }|tdWdn1sB0Ydd}tj tj}|dtj}td|d }| |||ddd tj}td|d |d |d  }| ||dS) NrIz def func(): f = open(__file__) # Emit ResourceWarning f = None func() cWs<t|ddi}|jdd}d|}tdd|}|S)NPYTHONIOENCODINGutf-8replacerz<.*>z<...>)rrdecodejoinrresub)rfresrTrrrruns z4PyWarningsDisplayTests.test_tracemalloc..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 addCleanuprunlinkZTESTFNopenwritetextwrapdedentrrabspathrr[)r(fpr+ryrTrrrrtest_tracemallocs&.     z'PyWarningsDisplayTests.test_tracemallocN)rrrr?rr4rrrrr"sr"c@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)CatchWarningTestszTest catch_warnings().cCs|j}|j}|j}|j|ddt|_|_Wdn1sD0Y||j|||j||j|ddt|_|_Wdn1s0Y||j|||j|dSNTrF)rrr2r6objectr)r(r orig_filtersorig_showwarningrrrtest_catch_warnings_restores,,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=||gWdn1s0Y|j }|j|d d(}| |||j |Wdn1s 0YdS) NTrrbrrdrrr_F) rr6r[rtyper]rr0rrOr2 assertIsNone)r(rrIr9rrrtest_catch_warnings_recordings"     * z/CatchWarningTests.test_catch_warnings_recordingcCs|j}|j|dd}|t|j||t|jWdn1sJ0Y|j|dd}|t|j||t|jWdn1s0YdSr6)rr6rG RuntimeError__exit__ __enter__)r(rrnrrr!test_catch_warnings_reentry_guards,z3CatchWarningTests.test_catch_warnings_reentry_guardcCs|j}|j}|j}|j|d6}||||j|||j|Wdn1sZ0Y||j||tjdur|6}||||j|||j|Wdn1s0Y||j|dS)NrAr ) rrr2r6r<rrr r$)r(rr8r9rIrrrtest_catch_warnings_defaultss ,  ,z.CatchWarningTests.test_catch_warnings_defaultsc sd}|j}gd fdd }t|d|n|j|dd2}||j||d||Wdn1sr0Y||j|Wdn1s0Y| t |d|| |d j j d || gdS) NThis is a warningcs|dSrLrrOrDryrrrZmy_logrr my_loggerszLCatchWarningTests.test_record_override_showwarning_before..my_loggerr2Trrbr_r)NN) rrr r6rr2rr0rr[r\rOrfr(rrrFlogrrEr'test_record_override_showwarning_befores (,z9CatchWarningTests.test_record_override_showwarning_beforecsd}|j}gd fdd }|j|dd*}|d||_||Wdn1sZ0Y|td|djd|||gdS) NrCcs|dSrLrrDrErrrF6szLCatchWarningTests.test_record_override_showwarning_inside..my_loggerTrrbr_r)NN)rr6rr2r0r[r\rfrGrrEr'test_record_override_showwarning_inside/s (z9CatchWarningTests.test_record_override_showwarning_insidec Cs|j}|tjdur|dtjdd}||jg|d| d|t |j d| d|t |j d|t |jdj d|t |jd j d| ||jgWdn1s0YtWdn1s0Ytdt f| dWdn1s80Y|t@td tfWdn1st0YWdn1s0Y|tJtdtf| dWdn1s0YWdn1s0YdS) Nr z,module to test is not loaded warnings moduleF)quietrbrrrr_r)rr r$ZskipTestrZcheck_warningsr[r rr0rrOresetrFrGAssertionErrorRuntimeWarning)r(rrIrrrtest_check_warningsCs0    , * @ z%CatchWarningTests.test_check_warningsN) rrrr,r:r=rArBrIrJrOrrrrr5s r5c@seZdZeZdS)CCatchWarningTestsNr;rrrrrPbsrPc@seZdZeZdS)PyCatchWarningTestsNr>rrrrrQesrQc@sPeZdZddZddZddZddZd d Ze e d kd d dZ dS)EnvironmentVariableTestscCs&tddddd\}}}||ddS)Nr2import sys; sys.stdout.write(str(sys.warnoptions))ignore::DeprecationWarningrPYTHONWARNINGS PYTHONDEVMODEs['ignore::DeprecationWarning']rr[rrrrtest_single_warningks  z,EnvironmentVariableTests.test_single_warningcCs&tddddd\}}}||ddS)NrrSz1ignore::DeprecationWarning,ignore::UnicodeWarningrrU8['ignore::DeprecationWarning', 'ignore::UnicodeWarning']rXrrrrtest_comma_separated_warningsrs z6EnvironmentVariableTests.test_comma_separated_warningscCs(tdddddd\}}}||ddS)Nz-Wignore::UnicodeWarningrrSrTrrUrZrXrrrrtest_envvar_and_command_linezs z5EnvironmentVariableTests.test_envvar_and_command_linecCs<tdddddd\}}}||d||gddS) Nz-Werror::DeprecationWarningrzjimport sys, warnings; sys.stdout.write(str(sys.warnoptions)); warnings.warn('Message', DeprecationWarning)zdefault::DeprecationWarningrrUs<['default::DeprecationWarning', 'error::DeprecationWarning'])s"Traceback (most recent call last):s& File "", line 1, in sDeprecationWarning: Message)rr[rrrrr(test_conflicting_envvar_and_command_lines  zAEnvironmentVariableTests.test_conflicting_envvar_and_command_linec Cs|jtu}trg}nT|r$td}nd}ddt|dfddtddfddtddfddtddfddtddfg}dd|D}|rd}nd}|d 7}t d |d d \}}}d d| D} d|_ | | |dS)N__main__rjrrXcSsg|]}t|qSr)rencode)rrPrrrrrzNEnvironmentVariableTests.test_default_filter_configuration..zPimport sys; sys.modules.pop('warnings', None); sys.modules['_warnings'] = None; rz5import warnings; [print(f) for f in warnings.filters]rT)Z __isolatedcSsg|] }|qSr)r)rrrrrrr) rr?Py_DEBUGr(rDeprecationWarningPendingDeprecationWarning ImportWarningResourceWarningrrZmaxDiffr[) r(Zpure_python_apiZexpected_default_filtersZmain_module_filterZexpected_outputcoderrrTZ stdout_linesrrr!test_default_filter_configurations*       z:EnvironmentVariableTests.test_default_filter_configurationasciiz%requires non-ascii filesystemencodingcCs<dtj}tddd|dd\}}}||t|gdS)Nzignore:DeprecationWarningrrSr$r)r#rVrW)rZ FS_NONASCIIrr[rr_)r(rVrrrTrrr test_nonasciis  z&EnvironmentVariableTests.test_nonasciiN) rrrrYr[r\r]rfrZ skipUnlessr getfilesystemencodingrhrrrrrRis rRc@seZdZeZdS)CEnvironmentVariableTestsNr;rrrrrjsrjc@seZdZeZdS)PyEnvironmentVariableTestsNr>rrrrrksrkc@seZdZddZdS) BootstrapTestc CsvtZ}td0tdd|dtdddd|dWdn1sJ0YWdn1sh0YdS)N encodingsrr)Z PYTHONPATHz-Wrb)rZtemp_cwdr)r(cwdrrrtest_issue_8766szBootstrapTest.test_issue_8766N)rrrrorrrrrlsrlc@seZdZddZddZdS)FinalizationTestcCs,d}td|\}}}||ddS)Nzk import warnings warn = warnings.warn class A: def __del__(self): warn("test") a=A() rz:7: UserWarning: test)rr[r&rstrip)r(rerrrrrrtest_finalizations  z"FinalizationTest.test_finalizationcCshd}dt}tdd|\}}}|||t|dt}tdd|\}}}|||t|dS)Ns&sys:1: ResourceWarning: unclosed file z f = open(%a)r,rzimport warnings; f = open(%a))rrr7 startswithrg)r(rrerrrrrrtest_late_resource_warningsz+FinalizationTest.test_late_resource_warningN)rrrrrrtrrrrrpsrpcCstjtjdSrL)r?rrr<rrrr setUpModules rur^): contextlibrrriorr(r r0rrrZtest.support.script_helperrrZtest.test_warnings.datarr r rZimport_fresh_moduler?r<r#r`rrrrr.ZTestCaser:r=r@rrrrrrrrrrr!r"r5rPrQrRrjrkrlrpruZtearDownModulermainrrrrsf      &  #p@1P $