a 5êdgW•ã@sLdZddlZddlZddlZddlZddlZddlZddlZddlZz ddl Z Wne yfdZ Yn0z ddl Z Wne yŠdZ Yn0ddl m Z mZddlmZmZddlmZddlmZmZmZddlmZddlmZdd lmZGd d „d ƒZGd d „d ƒZGdd„deejƒZGdd„dƒZ Gdd„deejƒZ!Gdd„dƒZ"Gdd„dejƒZ#Gdd„de#ƒZ$Gdd„de#ƒZ%Gdd„de#ƒZ&Gdd„de#ƒZ'Gd d!„d!e#ƒZ(Gd"d#„d#e#ƒZ)Gd$d%„d%e#ƒZ*Gd&d'„d'e#ƒZ+Gd(d)„d)e#ƒZ,Gd*d+„d+ƒZ-Gd,d-„d-ejƒZ.Gd.d/„d/ejƒZ/Gd0d1„d1ejƒZ0e1d2krHe 2¡dS)3z, Tests for fileinput module. Nick Mathewson éN)ÚBytesIOÚStringIO)Ú FileInputÚ hook_encoded)ÚPath)ÚverboseÚTESTFNÚcheck_warnings)Úunlink)Úsupport)Úmockc@seZdZddœdd„ZdS)Ú BaseTestsÚw©ÚmodecCsRt ¡\}}| tj|¡t||ƒ}| |¡Wdƒn1sD0Y|S©N)ÚtempfileÚmkstempÚ addCleanupr r ÚopenÚwrite)ÚselfZcontentrÚfdÚnameÚf©rú//usr/local/lib/python3.9/test/test_fileinput.pyÚwriteTmp(s   (zBaseTests.writeTmpN)Ú__name__Ú __module__Ú __qualname__rrrrrr %sr c@sDeZdZdd„Zedd„ƒZdd„Zddd „Zdd d „Zd d„Z dS)Ú LineReadercCs g|_dSr©Ú _linesread©rrrrÚ__init__1szLineReader.__init__cCs$z|jdd…Wg|_Sg|_0dSrr"r$rrrÚ linesread4s þzLineReader.linesreadcCst| d¡ƒ|_|S©NT)ÚiterÚ splitlinesÚit)rÚfilenamerrrrÚopenhook;szLineReader.openhookNcCst|jdƒ}|j |¡|S)NÚ)Únextr*r#Úappend)rÚsizeÚlinerrrÚreadline?s  zLineReader.readlineéÿÿÿÿcCs@g}d}| ¡}|s|S| |¡|t|ƒ7}||kr|SqdS©Nr)r2r/Úlen)rÚhintÚlinesr0r1rrrÚ readlinesDs  zLineReader.readlinescCsdSrrr$rrrÚclosePszLineReader.close)N)r3) rrr r%Úpropertyr&r,r2r8r9rrrrr!/s   r!c@seZdZdd„ZdS)ÚBufferSizesTestsc Cs’| d dd„tdƒDƒ¡¡}| d dd„tdƒDƒ¡¡}| d dd„tdƒDƒ¡¡}| d d d„td ƒDƒ¡¡}t d ¡}trŽtd ƒt||||fd }t|ƒ}|  ¡|  t |ƒd¡|  |dd¡|  |dd¡|  |  ¡d¡|  |  ¡|¡trtdƒt||||fd }d}|r@|dkr@| ¡}q$|  |  ¡|¡|  |  ¡d¡|  | ¡d¡| | ¡¡| | ¡¡trštdƒ| ¡|  | ¡d¡|  |  ¡d¡|  ¡trØtdƒt||||dfd }tj} zTtdƒt_t|ƒ}|  t |ƒd¡|  |dd ¡|  |  ¡d!¡| ¡W| t_n| t_0tr^td"ƒt||||fd }|  |  ¡d#¡|  |  ¡d¡| ¡|  |  ¡d#¡|  |  ¡d¡trÆtd$ƒtj} zJt||||fd d%}|D]} | dd&… ¡} t| ƒqæ|  ¡W| t_n| t_0t||||fd }|D]N} |  | d&d'¡| | dd&…¡} | | d¡|  t|  d ¡ƒ| ¡¡q6|  ¡dS)(Nr-css|]}d|dVqdS)zLine %s of file 1 éNr©Ú.0ÚirrrÚ Vóz5BufferSizesTests.test_buffer_sizes..écss|]}d|dVqdS)zLine %s of file 2 r<Nrr=rrrr@WrAé css|]}d|dVqdS)zLine %s of file 3 r<Nrr=rrrr@XrAécss|]}d|dVqdS)zLine %s of file 4 r<Nrr=rrrr@YrAr<zLINE (\d+) OF FILE (\d+)z1. Simple iteration©ÚfileséézLine 5 of file 1 ézLine 1 of file 4 z2. Status variablesÚxzLine 6 of file 2 ééz 3. NextfilezLine 1 of file 3 éz4. Stdinú-z Line 1 of stdin Line 2 of stdin é!é zLine 2 of stdin zz5. Boundary conditionsrz 6. Inplace©rFÚinplacer3Ú )rÚjoinÚrangeÚreÚcompilerÚprintrÚlistr9Ú assertEqualr5Úlinenor+r2Ú filelinenoÚ assertFalseÚ isfirstlineÚisstdinÚnextfileÚsysÚstdinrÚstdoutÚupperÚmatchÚassertNotEqualÚintÚgroup) rÚt1Út2Út3Út4ÚpatÚfir7ÚsZ savestdinZ savestdoutr1ÚmrrrÚtest_buffer_sizesTsŠ       z"BufferSizesTests.test_buffer_sizesN)rrr rqrrrrr;Ssr;c@seZdZdd„Zdd„ZdS)ÚUnconditionallyRaisecCs||_d|_dS©NF)Úexception_typeÚinvoked)rrtrrrr%§szUnconditionallyRaise.__init__cOsd|_| ¡‚dSr')rurt©rÚargsÚkwargsrrrÚ__call__ªszUnconditionallyRaise.__call__N©rrr r%ryrrrrrr¦srrc@søeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zejeddd„ƒZdd„Zejedd d!„ƒZejedd"d#„ƒZd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4S)5ÚFileInputTestscCsÌ| d¡}| d¡}| d¡}| d¡}t||||fd}| ¡}| |d¡| | ¡d¡| | ¡d¡| | ¡|¡| ¡}| |¡| | ¡d¡| | ¡d¡| | ¡|¡| ¡dS)Nr-zThe only line there is. rEr<r) rrr2rZr[r\r+r]r9)rrirjrkrlrnr1rrrÚtest_zero_byte_files°s       z#FileInputTests.test_zero_byte_filescCs^| d¡}| d¡}t||fd}t|ƒ}| |gd¢¡| | ¡d¡| | ¡d¡dS)NúA B CúD E FrE©úA úB ÚCzD zE ÚFérL)rrrYrZr\r[©rrirjrnr7rrrÚ%test_files_that_dont_end_with_newlineÄs  z4FileInputTests.test_files_that_dont_end_with_newlinecCs~| d¡}| d¡}t||fd}| | ¡d¡t|ƒ}| | ¡d¡| ¡| | ¡d¡t|ƒ}| | ¡d¡dS)NzA BzC DrEr3)rrrZÚfilenor.rfr`rY)rrirjrnr1rrrÚ test_filenoØs  zFileInputTests.test_filenocCsºztdd}| d¡Wnty*Yn0|jddd}tdtfƒt|dd}Wdƒn1sh0Ytdtfƒt|ƒ}Wdƒn1sœ0Y| |gd ¢¡dS) Nrrz-FileInput should reject invalid mode argumentóA B C DÚwbr-ÚU©rFr)r€rúC ÚD)rÚfailÚ ValueErrorrr ÚDeprecationWarningrYrZ)rrnrir7rrrÚtest_opening_modeäs  *&z FileInputTests.test_opening_modecCs\t d¡>}tdƒ|_tdgdd}t|ƒ}| |dg¡Wdƒn1sN0YdS)Nz sys.stdinóspam, bacon, sausage, and spamrNÚrbrŒ)r ZpatchrÚbufferrrYrZ)rZm_stdinrnr7rrrÚtest_stdin_binary_modeós   z%FileInputTests.test_stdin_binary_modecCs^tj}zJtdƒt_| ttjdƒ¡tdgdd}t|ƒ}| |dg¡W|t_n|t_0dS)Nr“r•rNr”rŒ)rarbrr]ÚhasattrrrYrZ)rZ orig_stdinrnr7rrrÚtest_detached_stdin_binary_modeús z.FileInputTests.test_detached_stdin_binary_modecCsÄztddd„d}| d¡Wnty0Yn0ztdd}| d¡Wnty\Yn0Gdd „d ƒ}| d ¡}|ƒ}t|g|d}| ¡Wdƒn1s¨0Y| |jd ¡dS) Nr<cSsdSrr)rrprrrÚrAz7FileInputTests.test_file_opening_hook..)rRr,zGFileInput should raise if both inplace and openhook arguments are given)r,z2FileInput should check openhook for being callablec@seZdZdd„Zdd„ZdS)z=FileInputTests.test_file_opening_hook..CustomOpenHookcSs d|_dSrs)rur$rrrr%szFFileInputTests.test_file_opening_hook..CustomOpenHook.__init__cWsd|_t|ŽSr')rur)rrwrrrryszFFileInputTests.test_file_opening_hook..CustomOpenHook.__call__NrzrrrrÚCustomOpenHooksršrSzopenhook not invoked)rrrrr2Ú assertTrueru)rrnršÚtZcustom_open_hookrrrÚtest_file_opening_hooks     &z%FileInputTests.test_file_opening_hookc Cs2ttdƒ2}| d¡| dd¡| d¡Wdƒn1sB0Y| tt¡tttdƒd´}z4| | ¡d¡| | ¡d ¡| | ¡d ¡Wnt yº|  d ¡Yn0|  t ¡t |ƒWdƒn1sä0Y| | ¡d ¡| | ¡d ¡Wdƒn1s$0YdS) NrŠsA B C s 123456789 ièó€Úascii©rFr,r€rrzRead to end of filer-) rrrrÚ safe_unlinkrrrZr2ÚUnicodeDecodeErrorrÚ assertRaisesrY©rrrnrrrÚ test_readline s&  ( ÿ  &zFileInputTests.test_readlinecCsÀttdƒ}| d¡Wdƒn1s*0Y| tt¡ttdd`}| | ¡d¡| | ¡d¡| | ¡d¡| | ¡d¡| | ¡d¡Wdƒn1s²0YdS) NrŠr‰r”rŒsA sB sC DrA)rrrrr¡rrZr2r¤rrrÚtest_readline_binary_mode7s ( z(FileInputTests.test_readline_binary_modecCsš|jddd}t|ddd0}| ¡}| |d¡tj d¡Wdƒn1sR0Yt|dƒ }| | ¡d¡Wdƒn1sŒ0YdS)Ns Initial text.rŠrr”T)rrRs New line.) rrr2rZrarcrrÚread)rZ temp_fileZfobjr1rrrrÚtest_inplace_binary_write_modeDs * z-FileInputTests.test_inplace_binary_write_modecCsŒ| d¡}| d¡}t||fd}t|ƒ}Wdƒn1s@0Y| |gd¢¡| | ¡d¡| | ¡d¡| |jd¡dS)Nr}r~rErr„rLr)rrrYrZr\r[Ú_filesr…rrrÚtest_context_managerNs  &z#FileInputTests.test_context_managercCsb| d¡}z2t|d}t‚Wdƒn1s00YWn ty\| |jd¡Yn0dS)Nr-rEr)rrÚOSErrorrZr©)rrirnrrrÚtest_close_on_exceptionXs   & z&FileInputTests.test_close_on_exceptioncCs<tgd}| |jd¡Wdƒn1s.0YdS)NrE)rN)rrZr©)rrnrrrÚ.test_empty_files_list_specified_to_constructor`s z=FileInputTests.test_empty_files_list_specified_to_constructor)ÚcategorycCsb| d¡}t|gd8}|d}| |d¡|d}| |d¡Wdƒn1sT0YdS)zNTests invoking FileInput.__getitem__() with the current line numberú line1 line2 rErúline1 r<zline2 N)rrrZ)rrœrnZretval1Zretval2rrrÚtest__getitem__ds   zFileInputTests.test__getitem__c Csv| d¡}| td¡Lt|gd }| |dd¡Wdƒn1sJ0YWdƒn1sh0YdS)Nr¯zUse iterator protocol insteadrErr°)rZassertWarnsRegexr‘rrZ)rrœrnrrrÚtest__getitem___deprecationos  ÿz*FileInputTests.test__getitem___deprecationc Cs|| d¡}t|gdB}| t¡}|dWdƒn1s@0YWdƒn1s^0Y| |jjd¡dS)zZTests invoking FileInput.__getitem__() with an index unequal to the line numberr¯rEr<N)zaccessing lines out of order)rrr£Ú RuntimeErrorrZÚ exceptionrw©rrœrnÚcmrrrÚtest__getitem__invalid_keyvs   Dz)FileInputTests.test__getitem__invalid_keyc Cs|| d¡}t|gdB}| t¡}|dWdƒn1s@0YWdƒn1s^0Y| |jjd¡dS)zZTests invoking FileInput.__getitem__() with the line number but at end-of-inputr-rErN)zend of input reached)rrr£Ú IndexErrorrZr´rwrµrrrÚtest__getitem__eof€s   Dz!FileInputTests.test__getitem__eofcCs”tj}ttƒ}zj| d¡}| tj|d¡t|gdd&}t|ƒ|t_|  ¡Wdƒn1sf0YW|t_n|t_0|  |j d¡dS)z¨Tests invoking FileInput.nextfile() when the attempt to delete the backup file would raise OSError. This error is expected to be silently ignoredrSz.bakTrQNzos.unlink() was not invoked) Úosr rrr«rrr rr.r`r›ru)rZos_unlink_origZos_unlink_replacementrœrnrrrÚ%test_nextfile_oserror_deleting_backupŠs (ÿz4FileInputTests.test_nextfile_oserror_deleting_backupcCsztj}ttƒ}zP| d¡}t|gdd}|t_| ¡Wdƒn1sL0YW|t_n|t_0| |jd¡dS)z{Tests invoking FileInput.readline() when os.fstat() raises OSError. This exception should be silently discarded.rSTrQNúos.fstat() was not invoked) rºÚfstatrrr«rrr2r›ru)rZ os_fstat_origZos_fstat_replacementrœrnrrrÚ%test_readline_os_fstat_raises_OSErrorŸs (ÿz4FileInputTests.test_readline_os_fstat_raises_OSErrorcCsztj}ttƒ}zP| d¡}t|gdd}|t_| ¡Wdƒn1sL0YW|t_n|t_0| |jd¡dS)z{Tests invoking FileInput.readline() when os.chmod() raises OSError. This exception should be silently discarded.rSTrQNr¼) rºÚchmodrrr«rrr2r›ru)rZ os_chmod_origZos_chmod_replacementrœrnrrrÚ%test_readline_os_chmod_raises_OSError±s (ÿz4FileInputTests.test_readline_os_chmod_raises_OSErrorc Cs”Gdd„dtƒ}|ƒ}| d¡}t|gd8}|j}z||_| ¡}W||_n||_0Wdƒn1sj0Y| |jd¡| |dd¡dS)Nc@seZdZdd„Zdd„ZdS)zQFileInputTests.test_fileno_when_ValueError_raised..FilenoRaisesValueErrorcSst |t¡dSr)rrr%rr$rrrr%ÅszZFileInputTests.test_fileno_when_ValueError_raised..FilenoRaisesValueError.__init__cSs | ¡dSr)ryr$rrrr‡ÇszXFileInputTests.test_fileno_when_ValueError_raised..FilenoRaisesValueError.filenoN)rrr r%r‡rrrrÚFilenoRaisesValueErrorÄsrÁrSrEz_file.fileno() was not invokedr3zfileno() should return -1)rrrrÚ_filer‡r›rurZ)rrÁZ unconditionally_raise_ValueErrorrœrnZ file_backupÚresultrrrÚ"test_fileno_when_ValueError_raisedÃs  .ÿz1FileInputTests.test_fileno_when_ValueError_raisedcCsêtƒ}tddg|jd¾}| |jg¡| | ¡d¡| |jdg¡| | ¡d¡| |jdg¡| | ¡d¡| |jddg¡| | ¡d¡| |jdg¡| | ¡d¡| |jg¡Wdƒn1sÜ0YdS©Nz line1 line2zline3 r r°Zline2r-)r!rr,rZr&r2©rÚsrcrnrrrÚtest_readline_bufferingÚs ÿz&FileInputTests.test_readline_bufferingcCsætƒ}tddg|jdº}| |jg¡| t|ƒd¡| |jdg¡| t|ƒd¡| |jdg¡| t|ƒd¡| |jddg¡| tt|¡| |jdg¡| tt|¡| |jg¡Wdƒn1sØ0YdSrÅ)r!rr,rZr&r.r£Ú StopIterationrÆrrrÚtest_iteration_bufferingês ÿz'FileInputTests.test_iteration_bufferingcCs„t| d¡ƒ}t|ƒZ}| ¡}| |d¡| | ¡d¡| | ¡d¡| | ¡t  |¡¡Wdƒn1sv0YdS)Nú Pathlib file.r<) rrrr2rZr[r\r+rºÚfspath)rrirnr1rrrÚtest_pathlib_fileús  z FileInputTests.test_pathlib_filecCs–t| d¡ƒ}t|dd0}| ¡}| |d¡td|ƒWdƒn1sP0Yt|ƒ }| | ¡d¡Wdƒn1sˆ0YdS)NrËT)rRz Modified %szModified Pathlib file. )rrrr2rZrXrr§)rrirnr1rrrrÚtest_pathlib_file_inplaces * z(FileInputTests.test_pathlib_file_inplaceN)rrr r|r†rˆr’r–r˜rr¥r¦r¨rªr¬r­r Zignore_warningsr‘r±r²r·r¹r»r¾rÀrÄrÈrÊrÍrÎrrrrr{®s8           r{c@sbeZdZdZddddœdd„Zd d „Zd d „Zd d„Zdd„Zdd„Z dd„Z dd„Z dd„Z dS)Ú MockFileInputzDA class that mocks out fileinput.FileInput for use during unit testsNFr-Úr)rr,cCs>||_||_||_||_||_d|_t dd„¡|_i|_ dS)NcSsdSr4rrrrrr™rAz(MockFileInput.__init__..) rFrRÚbackuprr,rÂÚ collectionsÚ defaultdictÚinvocation_countsÚ return_values)rrFrRrÑrr,rrrr%szMockFileInput.__init__cCs|jdd7<dS)Nr9r<)rÔr$rrrr9szMockFileInput.closecCs|jdd7<|jdS)Nr`r<©rÔrÕr$rrrr`szMockFileInput.nextfilecCs|jdd7<|jdS)Nr+r<rÖr$rrrr+"szMockFileInput.filenamecCs|jdd7<|jdS)Nr[r<rÖr$rrrr[&szMockFileInput.linenocCs|jdd7<|jdS)Nr\r<rÖr$rrrr\*szMockFileInput.filelinenocCs|jdd7<|jdS)Nr‡r<rÖr$rrrr‡.szMockFileInput.filenocCs|jdd7<|jdS)Nr^r<rÖr$rrrr^2szMockFileInput.isfirstlinecCs|jdd7<|jdS)Nr_r<rÖr$rrrr_6szMockFileInput.isstdin)NFr-) rrr Ú__doc__r%r9r`r+r[r\r‡r^r_rrrrrÏ sÿ rÏc@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚBaseFileInputGlobalMethodsTestzQBase class for unit tests for the global function of the fileinput module.cCstj|_tj|_tt_dSr)Ú fileinputÚ_stateÚ _orig_staterÚ_orig_FileInputrÏr$rrrÚsetUp>sz$BaseFileInputGlobalMethodsTest.setUpcCs|jt_|jt_dSr)rÜrÙrrÛrÚr$rrrÚtearDownCsz'BaseFileInputGlobalMethodsTest.tearDowncCs2|j|}| |d|¡t|jƒ}| |d¡dS©Nr<)rÔrZr5)rZmock_file_inputZ method_nameZ actual_countZactual_total_countrrrÚassertExactlyOneInvocationGs  z9BaseFileInputGlobalMethodsTest.assertExactlyOneInvocationN)rrr r×rÝrÞràrrrrrØ:srØc@s0eZdZdZdd„Zdd„Zdd„Zdd „Zd S) ÚTest_fileinput_inputz Unit tests for fileinput.input()cCsjtƒ}tƒ|_|t_| t¡}t ¡Wdƒn1s<0Y| d|j j ¡|  |tjd¡dS)zþTests invoking fileinput.input() when fileinput._state is not None and its _file attribute is also not None. Expect RuntimeError to be raised with a meaningful error message and for fileinput._state to *not* be modified.N)zinput() already activeúfileinput._state) rÏÚobjectrÂrÙrÚr£r³ÚinputrZr´rwÚassertIs)rÚinstancer¶rrrÚ1test_state_is_not_None_and_state_file_is_not_NoneRs &zFTest_fileinput_input.test_state_is_not_None_and_state_file_is_not_NonecCstƒ}d|_|t_| ¡dS)a\Tests invoking fileinput.input() when fileinput._state is not None but its _file attribute *is* None. Expect it to create and return a new fileinput.FileInput object with all method parameters passed explicitly to the __init__() method; also ensure that fileinput._state is set to the returned instance.N)rÏrÂrÙrÚÚdo_test_call_input©rrærrrÚ-test_state_is_not_None_and_state_file_is_None_szBTest_fileinput_input.test_state_is_not_None_and_state_file_is_NonecCsdt_| ¡dS)a4Tests invoking fileinput.input() when fileinput._state is None Expect it to create and return a new fileinput.FileInput object with all method parameters passed explicitly to the __init__() method; also ensure that fileinput._state is set to the returned instance.N)rÙrÚrèr$rrrÚtest_state_is_Nonejsz'Test_fileinput_input.test_state_is_NonecCs–tƒ}tƒ}tƒ}tƒ}tƒ}tj|||||d}| |tjd¡| ||jd¡| ||jd¡| ||jd¡| ||jd¡| ||j d¡dS) aTests that fileinput.input() creates a new fileinput.FileInput object, passing the given parameters unmodified to fileinput.FileInput.__init__(). Note that this test depends on the monkey patching of fileinput.FileInput done by setUp().)rFrRrÑrr,rârFrRrÑrr,N) rãrÙrärårÚrFrRrÑrr,)rrFrRrÑrr,rÃrrrrèss ÿz'Test_fileinput_input.do_test_call_inputN)rrr r×rçrêrërèrrrrráOs    rác@s eZdZdZdd„Zdd„ZdS)ÚTest_fileinput_closez Unit tests for fileinput.close()cCsdt_t ¡| tj¡dS)zPTests that fileinput.close() does nothing if fileinput._state is NoneN)rÙrÚr9Ú assertIsNoner$rrrrësz'Test_fileinput_close.test_state_is_NonecCs0tƒ}|t_t ¡| |d¡| tj¡dS)z`Tests that fileinput.close() invokes close() on fileinput._state and sets _state=Noner9N)rÏrÙrÚr9ràrírérrrÚtest_state_is_not_None—s  z+Test_fileinput_close.test_state_is_not_NoneN©rrr r×rërîrrrrrìsrìc@s eZdZdZdd„Zdd„ZdS)ÚTest_fileinput_nextfilez#Unit tests for fileinput.nextfile()cCsXdt_| t¡}t ¡Wdƒn1s.0Y| d|jj¡| tj¡dS)z·Tests fileinput.nextfile() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateN©zno active input()) rÙrÚr£r³r`rZr´rwrí©rr¶rrrrë£s  &z*Test_fileinput_nextfile.test_state_is_NonecCsNtƒ}tƒ}||jd<|t_t ¡}| |d¡| ||¡| tj|¡dS)aTests fileinput.nextfile() when fileinput._state is not None. Ensure that it invokes fileinput._state.nextfile() exactly once, returns whatever it returns, and does not modify fileinput._state to point to a different object.r`N)rãrÏrÕrÙrÚr`ràrå)rZnextfile_retvalræÚretvalrrrrî­s   z.Test_fileinput_nextfile.test_state_is_not_NoneNrïrrrrrð s rðc@s eZdZdZdd„Zdd„ZdS)ÚTest_fileinput_filenamez#Unit tests for fileinput.filename()cCsXdt_| t¡}t ¡Wdƒn1s.0Y| d|jj¡| tj¡dS)z·Tests fileinput.filename() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNrñ) rÙrÚr£r³r+rZr´rwríròrrrrë¾s  &z*Test_fileinput_filename.test_state_is_NonecCsNtƒ}tƒ}||jd<|t_t ¡}| |d¡| ||¡| tj|¡dS)aTests fileinput.filename() when fileinput._state is not None. Ensure that it invokes fileinput._state.filename() exactly once, returns whatever it returns, and does not modify fileinput._state to point to a different object.r+N)rãrÏrÕrÙrÚr+ràrå)rZfilename_retvalrærórrrrîÈs   z.Test_fileinput_filename.test_state_is_not_NoneNrïrrrrrô»s rôc@s eZdZdZdd„Zdd„ZdS)ÚTest_fileinput_linenoz!Unit tests for fileinput.lineno()cCsXdt_| t¡}t ¡Wdƒn1s.0Y| d|jj¡| tj¡dS)zµTests fileinput.lineno() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNrñ) rÙrÚr£r³r[rZr´rwríròrrrrëÙs  &z(Test_fileinput_lineno.test_state_is_NonecCsNtƒ}tƒ}||jd<|t_t ¡}| |d¡| ||¡| tj|¡dS)zýTests fileinput.lineno() when fileinput._state is not None. Ensure that it invokes fileinput._state.lineno() exactly once, returns whatever it returns, and does not modify fileinput._state to point to a different object.r[N)rãrÏrÕrÙrÚr[ràrå)rZ lineno_retvalrærórrrrîãs   z,Test_fileinput_lineno.test_state_is_not_NoneNrïrrrrrõÖs rõc@s eZdZdZdd„Zdd„ZdS)ÚTest_fileinput_filelinenoz%Unit tests for fileinput.filelineno()cCsXdt_| t¡}t ¡Wdƒn1s.0Y| d|jj¡| tj¡dS)z¹Tests fileinput.filelineno() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNrñ) rÙrÚr£r³r\rZr´rwríròrrrrëôs  &z,Test_fileinput_filelineno.test_state_is_NonecCsNtƒ}tƒ}||jd<|t_t ¡}| |d¡| ||¡| tj|¡dS)aTests fileinput.filelineno() when fileinput._state is not None. Ensure that it invokes fileinput._state.filelineno() exactly once, returns whatever it returns, and does not modify fileinput._state to point to a different object.r\N)rãrÏrÕrÙrÚr\ràrå)rZfilelineno_retvalrærórrrrîþs   z0Test_fileinput_filelineno.test_state_is_not_NoneNrïrrrrröñs röc@s eZdZdZdd„Zdd„ZdS)ÚTest_fileinput_filenoz!Unit tests for fileinput.fileno()cCsXdt_| t¡}t ¡Wdƒn1s.0Y| d|jj¡| tj¡dS)zµTests fileinput.fileno() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNrñ) rÙrÚr£r³r‡rZr´rwríròrrrrës  &z(Test_fileinput_fileno.test_state_is_NonecCsTtƒ}tƒ}||jd<||_|t_t ¡}| |d¡| ||¡| tj|¡dS)zýTests fileinput.fileno() when fileinput._state is not None. Ensure that it invokes fileinput._state.fileno() exactly once, returns whatever it returns, and does not modify fileinput._state to point to a different object.r‡N) rãrÏrÕÚ fileno_retvalrÙrÚr‡ràrå)rrørærórrrrîs   z,Test_fileinput_fileno.test_state_is_not_NoneNrïrrrrr÷ s r÷c@s eZdZdZdd„Zdd„ZdS)ÚTest_fileinput_isfirstlinez&Unit tests for fileinput.isfirstline()cCsXdt_| t¡}t ¡Wdƒn1s.0Y| d|jj¡| tj¡dS)zºTests fileinput.isfirstline() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNrñ) rÙrÚr£r³r^rZr´rwríròrrrrë+s  &z-Test_fileinput_isfirstline.test_state_is_NonecCsNtƒ}tƒ}||jd<|t_t ¡}| |d¡| ||¡| tj|¡dS)aTests fileinput.isfirstline() when fileinput._state is not None. Ensure that it invokes fileinput._state.isfirstline() exactly once, returns whatever it returns, and does not modify fileinput._state to point to a different object.r^N)rãrÏrÕrÙrÚr^ràrå)rZisfirstline_retvalrærórrrrî5s   z1Test_fileinput_isfirstline.test_state_is_not_NoneNrïrrrrrù(s rùc@s eZdZdZdd„Zdd„ZdS)ÚTest_fileinput_isstdinz"Unit tests for fileinput.isstdin()cCsXdt_| t¡}t ¡Wdƒn1s.0Y| d|jj¡| tj¡dS)z¶Tests fileinput.isstdin() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNrñ) rÙrÚr£r³r_rZr´rwríròrrrrëFs  &z)Test_fileinput_isstdin.test_state_is_NonecCsNtƒ}tƒ}||jd<|t_t ¡}| |d¡| ||¡| tj|¡dS)zÿTests fileinput.isstdin() when fileinput._state is not None. Ensure that it invokes fileinput._state.isstdin() exactly once, returns whatever it returns, and does not modify fileinput._state to point to a different object.r_N)rãrÏrÕrÙrÚr_ràrå)rZisstdin_retvalrærórrrrîPs   z-Test_fileinput_isstdin.test_state_is_not_NoneNrïrrrrrúCs rúc@seZdZdd„Zdd„ZdS)ÚInvocationRecordercCs d|_dSr4)Úinvocation_countr$rrrr%_szInvocationRecorder.__init__cOs|jd7_||f|_dSrß)rüÚlast_invocationrvrrrryaszInvocationRecorder.__call__Nrzrrrrrû^srûc@s|eZdZdZdd„Zdd„Zdd„Ze e d¡d d „ƒZ e e d ¡d d „ƒZ dd„Z dd„Zdd„Zdd„Zedd„ƒZdS)ÚTest_hook_compressedz*Unit tests for fileinput.hook_compressed()cCs tƒ|_dSr)rûÚ fake_openr$rrrrÝhszTest_hook_compressed.setUpcCs| dd¡dS)Nr-r<©Údo_test_use_builtin_openr$rrrÚtest_empty_stringksz&Test_hook_compressed.test_empty_stringcCs| dd¡dS)NZabcdérr$rrrÚ test_no_extnsz Test_hook_compressed.test_no_extzRequires gzip and zlibcCsVtj}|jt_zt dd¡}W|t_n|t_0| |jjd¡| |jjdif¡dS)Nútest.gzr„r<)rr„)ÚgziprrÿrÙÚhook_compressedrZrürý©rÚ original_openrÃrrrÚtest_gz_ext_fakeqsz%Test_hook_compressed.test_gz_ext_fakez Requires bz2cCsVtj}|jt_zt dd¡}W|t_n|t_0| |jjd¡| |jjdif¡dS)Nútest.bz2rHr<)r rH)Úbz2ÚBZ2FilerÿrÙrrZrürýrrrrÚtest_bz2_ext_fake}sz&Test_hook_compressed.test_bz2_ext_fakecCs| dd¡dS)Nz abcd.blahrDrr$rrrÚ test_blah_ext‰sz"Test_hook_compressed.test_blah_extcCs| dd¡dS)Nzabcd.GzrLrr$rrrÚtest_gz_ext_builtinŒsz(Test_hook_compressed.test_gz_ext_builtincCs| dd¡dS)Nzabcd.Bz2érr$rrrÚtest_bz2_ext_builtinsz)Test_hook_compressed.test_bz2_ext_builtinc Cs`| |j¡}zt ||¡}W| |¡n | |¡0| |jjd¡| |jj||fif¡dSrß)Úreplace_builtin_openrÿrÙrrZrürý)rr+rr rÃrrrr’s   ÿz-Test_hook_compressed.do_test_use_builtin_opencCstj}|t_|Sr)Úbuiltinsr)Z new_open_funcr rrrrsz)Test_hook_compressed.replace_builtin_openN)rrr r×rÝrrÚunittestZ skipUnlessrr r rrrrrÚ staticmethodrrrrrrþes    rþc@s(eZdZdZdd„Zdd„Zdd„ZdS) ÚTest_hook_encodedz'Unit tests for fileinput.hook_encoded()c CsÀtƒ}tƒ}tj||d}tƒ}tj}|t_z tƒ}tƒ}|||ƒ}W|t_n|t_0| |jd¡|j\} } |  | d|¡|  | d|¡|  |   d¡|¡|  |   d¡|¡|  | ¡dS)N©Úerrorsr<rÚencodingr) rãrÙrrûrrrZrürýråÚpopr]) rrrrÃrÿr r+rZ open_resultrwrxrrrÚtest¦s$  zTest_hook_encoded.testcsªttdƒ}| d¡Wdƒn1s*0Yˆ tt¡‡fdd„}|ddgƒˆ t¡|ddgƒWdƒn1s„0Y|dd gƒ|d d gƒdS) NrŠs€abccsNttdtd|dd}t|ƒ}Wdƒn1s40Yˆ ||¡dS)NrÐzutf-8r©rFrr,©rrrrYrZ)rÚexpected_linesrnr7r$rrÚcheckÃs  ÿ&z,Test_hook_encoded.test_errors..checkÚignoreÚabcÚstrictÚreplaceu�abcÚbackslashreplacez\x80abc)rrrrr¡r£r¢©rrr rr$rÚ test_errors¾s (    * zTest_hook_encoded.test_errorscsttdƒ}| d¡Wdƒn1s*0Yˆ tt¡‡fdd„}|dgd¢ƒˆ t¡|dgd¢ƒWdƒn1sˆ0Yˆ t¡|dgd¢ƒWdƒn1sÀ0Yˆ t¡|d gd ¢ƒWdƒn1sø0YdS) NrŠs A B C D+IKw-csJtt|tdƒd}t|ƒ}Wdƒn1s00Yˆ ||¡dS)Nzutf-7rr)rrrnr7r$rrr Õs ÿ&z+Test_hook_encoded.test_modes..checkrÐ)r€rrõD€ZrUr‹r”)r€zB zC r() rrrrr¡Z assertWarnsr‘r£rr&rr$rÚ test_modesÏs (   , , zTest_hook_encoded.test_modesN)rrr r×rr'r)rrrrr£src@seZdZdd„ZdS)ÚMiscTestcCst |t¡dSr)r Z check__all__rÙr$rrrÚtest_allæszMiscTest.test_allN)rrr r+rrrrr*äsr*Ú__main__)3r×rºrarVrÙrÒrrrr Ú ImportErrorrÚiorrrrÚpathlibrZ test.supportrrr r r¡rr r r r!ZTestCaser;rrr{rÏrØrárìrðrôrõrör÷rùrúrûrþrr*rÚmainrrrrÚs^           $Sa->>A