a zeW@sLdZddlZddlZddlZddlZddlZddlZddlZddlZz ddl Z Wne yfdZ Yn0z ddl Z Wne ydZ Yn0ddl m Z mZddlmZmZddlmZddlmZmZmZddlmZddlmZdd lmZGd d d ZGd d d ZGdddeejZGdddZ GdddeejZ!GdddZ"GdddejZ#Gddde#Z$Gddde#Z%Gddde#Z&Gddde#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-ejZ.Gd.d/d/ejZ/Gd0d1d1ejZ0e1d2krHe2dS)3z, Tests for fileinput module. Nick Mathewson N)BytesIOStringIO) FileInput hook_encoded)Path)verboseTESTFNcheck_warnings)unlink)support)mockc@seZdZddddZdS) BaseTestswmodecCsRt\}}|tj|t||}||Wdn1sD0Y|SN)tempfilemkstemp addCleanupr r openwrite)selfZcontentrfdnamefrG/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_fileinput.pywriteTmp(s   (zBaseTests.writeTmpN)__name__ __module__ __qualname__rrrrrr %sr c@sDeZdZddZeddZddZddd Zdd d Zd dZ dS) LineReadercCs g|_dSr _linesreadrrrr__init__1szLineReader.__init__cCs$z|jddWg|_Sg|_0dSrr"r$rrr linesread4s zLineReader.linesreadcCst|d|_|SNT)iter splitlinesit)rfilenamerrrropenhook;szLineReader.openhookNcCst|jd}|j||S)N)nextr*r#append)rsizelinerrrreadline?s  zLineReader.readlinecCs@g}d}|}|s|S|||t|7}||kr|SqdSNr)r2r/len)rhintlinesr0r1rrr readlinesDs  zLineReader.readlinescCsdSrrr$rrrclosePszLineReader.close)N)r3) rrr r%propertyr&r,r2r8r9rrrrr!/s   r!c@seZdZddZdS)BufferSizesTestsc Cs|dddtdD}|dddtdD}|dddtdD}|dd dtd D}td }trtd t||||fd }t|}| | t |d| |dd| |dd| | d| | |trtdt||||fd }d}|r@|dkr@|}q$| | || | d| |d||||trtd|| |d| | d| trtdt||||dfd }tj} zTtdt_t|}| t |d| |dd | | d!|W| t_n| t_0tr^td"t||||fd }| | d#| | d|| | d#| | dtrtd$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.0irrr Vz5BufferSizesTests.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@XrAcss|]}d|dVqdS)zLine %s of file 4 r<Nrr=rrrr@YrAr<zLINE (\d+) OF FILE (\d+)z1. Simple iterationfileszLine 5 of file 1 zLine 1 of file 4 z2. Status variablesxzLine 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. InplacerFinplacer3 )rjoinrangerecompilerprintrlistr9 assertEqualr5linenor+r2 filelineno assertFalse isfirstlineisstdinnextfilesysstdinrstdoutuppermatchassertNotEqualintgroup) rt1t2t3t4patfir7sZ savestdinZ savestdoutr1mrrrtest_buffer_sizesTs       z"BufferSizesTests.test_buffer_sizesN)rrr rqrrrrr;Ssr;c@seZdZddZddZdS)UnconditionallyRaisecCs||_d|_dSNF)exception_typeinvoked)rrtrrrr%szUnconditionallyRaise.__init__cOsd|_|dSr')rurtrargskwargsrrr__call__szUnconditionallyRaise.__call__Nrrr r%ryrrrrrrsrrc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZejedddZddZejedd d!Zejedd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4S)5FileInputTestscCs|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)rrirjrkrlrnr1rrrtest_zero_byte_filess       z#FileInputTests.test_zero_byte_filescCs^|d}|d}t||fd}t|}||gd||d||ddS)NA B CD E FrEA B CzD zE FrL)rrrYrZr\r[rrirjrnr7rrr%test_files_that_dont_end_with_newlines  z4FileInputTests.test_files_that_dont_end_with_newlinecCs~|d}|d}t||fd}||dt|}||d|||dt|}||ddS)NzA BzC DrEr3)rrrZfilenor.rfr`rY)rrirjrnr1rrr test_filenos  zFileInputTests.test_filenocCsztdd}|dWnty*Yn0|jddd}tdtft|dd}Wdn1sh0Ytdtft|}Wdn1s0Y||gd dS) Nrrz-FileInput should reject invalid mode argumentA B C Dwbr-UrFr)rrC D)rfail ValueErrorrr DeprecationWarningrYrZ)rrnrir7rrrtest_opening_modes  *&z FileInputTests.test_opening_modecCs\td>}td|_tdgdd}t|}||dgWdn1sN0YdS)Nz sys.stdinspam, bacon, sausage, and spamrNrbr)r ZpatchrbufferrrYrZ)rZm_stdinrnr7rrrtest_stdin_binary_modes   z%FileInputTests.test_stdin_binary_modecCs^tj}zJtdt_|ttjdtdgdd}t|}||dgW|t_n|t_0dS)NrrrNrr)rarbrr]hasattrrrYrZ)rZ orig_stdinrnr7rrrtest_detached_stdin_binary_modes z.FileInputTests.test_detached_stdin_binary_modecCsztdddd}|dWnty0Yn0ztdd}|dWnty\Yn0Gdd d }|d }|}t|g|d}|Wdn1s0Y||jd dS) Nr<cSsdSrr)rrprrrrAz7FileInputTests.test_file_opening_hook..)rRr,zGFileInput should raise if both inplace and openhook arguments are given)r,z2FileInput should check openhook for being callablec@seZdZddZddZdS)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__NrzrrrrCustomOpenHooksrrSzopenhook not invoked)rrrrr2 assertTrueru)rrnrtZcustom_open_hookrrrtest_file_opening_hooks     &z%FileInputTests.test_file_opening_hookc Cs2ttd2}|d|dd|dWdn1sB0Y|tttttdd}z4||d||d ||d Wnt y| d Yn0| t t |Wdn1s0Y||d ||d Wdn1s$0YdS) NrsA B C s 123456789 iasciirFr,rrrzRead to end of filer-) rrrr safe_unlinkrrrZr2UnicodeDecodeErrorr assertRaisesrYrrrnrrr test_readline s&  (   &zFileInputTests.test_readlinecCsttd}|dWdn1s*0Y|ttttdd`}||d||d||d||d||dWdn1s0YdS) NrrrrsA sB sC DrA)rrrrrrrZr2rrrrtest_readline_binary_mode7s ( z(FileInputTests.test_readline_binary_modecCs|jddd}t|ddd0}|}||dtjdWdn1sR0Yt|d }||dWdn1s0YdS)Ns Initial text.rrrT)rrRs New line.) rrr2rZrarcrrread)rZ temp_fileZfobjr1rrrrtest_inplace_binary_write_modeDs * z-FileInputTests.test_inplace_binary_write_modecCs|d}|d}t||fd}t|}Wdn1s@0Y||gd||d||d||jddS)Nr}r~rErrrLr)rrrYrZr\r[_filesrrrrtest_context_managerNs  &z#FileInputTests.test_context_managercCsb|d}z2t|d}tWdn1s00YWn ty\||jdYn0dS)Nr-rEr)rrOSErrorrZr)rrirnrrrtest_close_on_exceptionXs   & z&FileInputTests.test_close_on_exceptioncCs<tgd}||jdWdn1s.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}||dWdn1sT0YdS)zNTests invoking FileInput.__getitem__() with the current line number line1 line2 rErline1 r<zline2 N)rrrZ)rrrnZretval1Zretval2rrrtest__getitem__ds   zFileInputTests.test__getitem__c Csv|d}|tdLt|gd }||ddWdn1sJ0YWdn1sh0YdS)NrzUse iterator protocol insteadrErr)rZassertWarnsRegexrrrZ)rrrnrrrtest__getitem___deprecationos  z*FileInputTests.test__getitem___deprecationc Cs||d}t|gdB}|t}|dWdn1s@0YWdn1s^0Y||jjddS)zZTests invoking FileInput.__getitem__() with an index unequal to the line numberrrEr<N)zaccessing lines out of order)rrr RuntimeErrorrZ exceptionrwrrrncmrrrtest__getitem__invalid_keyvs   Dz)FileInputTests.test__getitem__invalid_keyc Cs||d}t|gdB}|t}|dWdn1s@0YWdn1s^0Y||jjddS)zZTests invoking FileInput.__getitem__() with the line number but at end-of-inputr-rErN)zend of input reached)rrr IndexErrorrZrrwrrrrtest__getitem__eofs   Dz!FileInputTests.test__getitem__eofcCstj}tt}zj|d}|tj|dt|gdd&}t||t_| Wdn1sf0YW|t_n|t_0| |j ddS)zTests 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 rrrrrr rr.r`rru)rZos_unlink_origZos_unlink_replacementrrnrrr%test_nextfile_oserror_deleting_backups (z4FileInputTests.test_nextfile_oserror_deleting_backupcCsztj}tt}zP|d}t|gdd}|t_|Wdn1sL0YW|t_n|t_0||jddS)z{Tests invoking FileInput.readline() when os.fstat() raises OSError. This exception should be silently discarded.rSTrQNos.fstat() was not invoked) rfstatrrrrrr2rru)rZ os_fstat_origZos_fstat_replacementrrnrrr%test_readline_os_fstat_raises_OSErrors (z4FileInputTests.test_readline_os_fstat_raises_OSErrorcCsztj}tt}zP|d}t|gdd}|t_|Wdn1sL0YW|t_n|t_0||jddS)z{Tests invoking FileInput.readline() when os.chmod() raises OSError. This exception should be silently discarded.rSTrQNr) rchmodrrrrrr2rru)rZ os_chmod_origZos_chmod_replacementrrnrrr%test_readline_os_chmod_raises_OSErrors (z4FileInputTests.test_readline_os_chmod_raises_OSErrorc CsGdddt}|}|d}t|gd8}|j}z||_|}W||_n||_0Wdn1sj0Y||jd||dddS)Nc@seZdZddZddZdS)zQFileInputTests.test_fileno_when_ValueError_raised..FilenoRaisesValueErrorcSst|tdSr)rrr%rr$rrrr%szZFileInputTests.test_fileno_when_ValueError_raised..FilenoRaisesValueError.__init__cSs |dSr)ryr$rrrrszXFileInputTests.test_fileno_when_ValueError_raised..FilenoRaisesValueError.filenoN)rrr r%rrrrrFilenoRaisesValueErrorsrrSrEz_file.fileno() was not invokedr3zfileno() should return -1)rrrr_filerrrurZ)rrZ unconditionally_raise_ValueErrorrrnZ file_backupresultrrr"test_fileno_when_ValueError_raiseds  .z1FileInputTests.test_fileno_when_ValueError_raisedcCst}tddg|jd}||jg||d||jdg||d||jdg||d||jddg||d||jdg||d||jgWdn1s0YdSNz line1 line2zline3 rrZline2r-)r!rr,rZr&r2rsrcrnrrrtest_readline_bufferings z&FileInputTests.test_readline_bufferingcCst}tddg|jd}||jg|t|d||jdg|t|d||jdg|t|d||jddg|tt|||jdg|tt|||jgWdn1s0YdSr)r!rr,rZr&r.r StopIterationrrrrtest_iteration_bufferings z'FileInputTests.test_iteration_bufferingcCst|d}t|Z}|}||d||d||d||t |Wdn1sv0YdS)N Pathlib file.r<) rrrr2rZr[r\r+rfspath)rrirnr1rrrtest_pathlib_files  z FileInputTests.test_pathlib_filecCst|d}t|dd0}|}||dtd|Wdn1sP0Yt| }||dWdn1s0YdS)NrT)rRz Modified %szModified Pathlib file. )rrrr2rZrXrr)rrirnr1rrrrtest_pathlib_file_inplaces * z(FileInputTests.test_pathlib_file_inplaceN)rrr r|rrrrrrrrrrrrr Zignore_warningsrrrrrrrrrrrrrrrrrr{s8           r{c@sbeZdZdZddddddZd d Zd d Zd dZddZddZ ddZ ddZ ddZ dS) MockFileInputzDA class that mocks out fileinput.FileInput for use during unit testsNFr-r)rr,cCs>||_||_||_||_||_d|_tdd|_i|_ dS)NcSsdSr4rrrrrrrAz(MockFileInput.__init__..) rFrRbackuprr,r collections defaultdictinvocation_counts return_values)rrFrRrrr,rrrr%szMockFileInput.__init__cCs|jdd7<dS)Nr9r<)rr$rrrr9szMockFileInput.closecCs|jdd7<|jdS)Nr`r<rrr$rrrr`szMockFileInput.nextfilecCs|jdd7<|jdS)Nr+r<rr$rrrr+"szMockFileInput.filenamecCs|jdd7<|jdS)Nr[r<rr$rrrr[&szMockFileInput.linenocCs|jdd7<|jdS)Nr\r<rr$rrrr\*szMockFileInput.filelinenocCs|jdd7<|jdS)Nrr<rr$rrrr.szMockFileInput.filenocCs|jdd7<|jdS)Nr^r<rr$rrrr^2szMockFileInput.isfirstlinecCs|jdd7<|jdS)Nr_r<rr$rrrr_6szMockFileInput.isstdin)NFr-) rrr __doc__r%r9r`r+r[r\rr^r_rrrrr s rc@s(eZdZdZddZddZddZdS) BaseFileInputGlobalMethodsTestzQBase class for unit tests for the global function of the fileinput module.cCstj|_tj|_tt_dSr) fileinput_state _orig_stater_orig_FileInputrr$rrrsetUp>sz$BaseFileInputGlobalMethodsTest.setUpcCs|jt_|jt_dSr)rrrrrr$rrrtearDownCsz'BaseFileInputGlobalMethodsTest.tearDowncCs2|j|}||d|t|j}||ddSNr<)rrZr5)rZmock_file_inputZ method_nameZ actual_countZactual_total_countrrrassertExactlyOneInvocationGs  z9BaseFileInputGlobalMethodsTest.assertExactlyOneInvocationN)rrr rrrrrrrrr:src@s0eZdZdZddZddZddZdd Zd S) Test_fileinput_inputz Unit tests for fileinput.input()cCsjt}t|_|t_|t}tWdn1s<0Y|d|j j | |tjddS)zTests 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 activefileinput._state) robjectrrrrrinputrZrrwassertIs)rinstancerrrr1test_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)rrrrdo_test_call_inputrrrrr-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)rrrr$rrrtest_state_is_Nonejsz'Test_fileinput_input.test_state_is_NonecCst}t}t}t}t}tj|||||d}||tjd|||jd|||jd|||jd|||jd|||j ddS) 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().)rFrRrrr,rrFrRrrr,N) rrrrrrFrRrrr,)rrFrRrrr,rrrrrss z'Test_fileinput_input.do_test_call_inputN)rrr rrrrrrrrrrOs    rc@s eZdZdZddZddZdS)Test_fileinput_closez Unit tests for fileinput.close()cCsdt_t|tjdS)zPTests that fileinput.close() does nothing if fileinput._state is NoneN)rrr9 assertIsNoner$rrrrsz'Test_fileinput_close.test_state_is_NonecCs0t}|t_t||d|tjdS)z`Tests that fileinput.close() invokes close() on fileinput._state and sets _state=Noner9N)rrrr9rrrrrrtest_state_is_not_Nones  z+Test_fileinput_close.test_state_is_not_NoneNrrr rrrrrrrrsrc@s eZdZdZddZddZdS)Test_fileinput_nextfilez#Unit tests for fileinput.nextfile()cCsXdt_|t}tWdn1s.0Y|d|jj|tjdS)zTests fileinput.nextfile() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNzno active input()) rrrrr`rZrrwrrrrrrrs  &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)rrrrrr`rr)rZnextfile_retvalrretvalrrrrs   z.Test_fileinput_nextfile.test_state_is_not_NoneNrrrrrrs rc@s eZdZdZddZddZdS)Test_fileinput_filenamez#Unit tests for fileinput.filename()cCsXdt_|t}tWdn1s.0Y|d|jj|tjdS)zTests fileinput.filename() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNr) rrrrr+rZrrwrrrrrrs  &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)rrrrrr+rr)rZfilename_retvalrrrrrrs   z.Test_fileinput_filename.test_state_is_not_NoneNrrrrrrs rc@s eZdZdZddZddZdS)Test_fileinput_linenoz!Unit tests for fileinput.lineno()cCsXdt_|t}tWdn1s.0Y|d|jj|tjdS)zTests fileinput.lineno() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNr) rrrrr[rZrrwrrrrrrs  &z(Test_fileinput_lineno.test_state_is_NonecCsNt}t}||jd<|t_t}||d||||tj|dS)zTests 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)rrrrrr[rr)rZ lineno_retvalrrrrrrs   z,Test_fileinput_lineno.test_state_is_not_NoneNrrrrrrs rc@s eZdZdZddZddZdS)Test_fileinput_filelinenoz%Unit tests for fileinput.filelineno()cCsXdt_|t}tWdn1s.0Y|d|jj|tjdS)zTests fileinput.filelineno() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNr) rrrrr\rZrrwrrrrrrs  &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)rrrrrr\rr)rZfilelineno_retvalrrrrrrs   z0Test_fileinput_filelineno.test_state_is_not_NoneNrrrrrrs rc@s eZdZdZddZddZdS)Test_fileinput_filenoz!Unit tests for fileinput.fileno()cCsXdt_|t}tWdn1s.0Y|d|jj|tjdS)zTests fileinput.fileno() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNr) rrrrrrZrrwrrrrrrs  &z(Test_fileinput_fileno.test_state_is_NonecCsTt}t}||jd<||_|t_t}||d||||tj|dS)zTests 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.rN) rrr fileno_retvalrrrrr)rrrrrrrrs   z,Test_fileinput_fileno.test_state_is_not_NoneNrrrrrr s rc@s eZdZdZddZddZdS)Test_fileinput_isfirstlinez&Unit tests for fileinput.isfirstline()cCsXdt_|t}tWdn1s.0Y|d|jj|tjdS)zTests fileinput.isfirstline() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNr) rrrrr^rZrrwrrrrrr+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)rrrrrr^rr)rZisfirstline_retvalrrrrrr5s   z1Test_fileinput_isfirstline.test_state_is_not_NoneNrrrrrr(s rc@s eZdZdZddZddZdS)Test_fileinput_isstdinz"Unit tests for fileinput.isstdin()cCsXdt_|t}tWdn1s.0Y|d|jj|tjdS)zTests fileinput.isstdin() when fileinput._state is None. Ensure that it raises RuntimeError with a meaningful error message and does not modify fileinput._stateNr) rrrrr_rZrrwrrrrrrFs  &z)Test_fileinput_isstdin.test_state_is_NonecCsNt}t}||jd<|t_t}||d||||tj|dS)zTests 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)rrrrrr_rr)rZisstdin_retvalrrrrrrPs   z-Test_fileinput_isstdin.test_state_is_not_NoneNrrrrrrCs rc@seZdZddZddZdS)InvocationRecordercCs d|_dSr4)invocation_countr$rrrr%_szInvocationRecorder.__init__cOs|jd7_||f|_dSr)rlast_invocationrvrrrryaszInvocationRecorder.__call__Nrzrrrrr^src@s|eZdZdZddZddZddZee dd d Z ee d d d Z ddZ ddZddZddZeddZdS)Test_hook_compressedz*Unit tests for fileinput.hook_compressed()cCs t|_dSr)r fake_openr$rrrrhszTest_hook_compressed.setUpcCs|dddS)Nr-r<do_test_use_builtin_openr$rrrtest_empty_stringksz&Test_hook_compressed.test_empty_stringcCs|dddS)NZabcdrr$rrr test_no_extnsz Test_hook_compressed.test_no_extzRequires gzip and zlibcCsVtj}|jt_ztdd}W|t_n|t_0||jjd||jjdifdS)Ntest.gzrr<)rr)gziprrrhook_compressedrZrrr original_openrrrrtest_gz_ext_fakeqsz%Test_hook_compressed.test_gz_ext_fakez Requires bz2cCsVtj}|jt_ztdd}W|t_n|t_0||jjd||jjdifdS)Ntest.bz2rHr<)r rH)bz2BZ2FilerrrrZrrrrrrtest_bz2_ext_fake}sz&Test_hook_compressed.test_bz2_ext_fakecCs|dddS)Nz abcd.blahrDrr$rrr test_blah_extsz"Test_hook_compressed.test_blah_extcCs|dddS)Nzabcd.GzrLrr$rrrtest_gz_ext_builtinsz(Test_hook_compressed.test_gz_ext_builtincCs|dddS)Nzabcd.Bz2rr$rrrtest_bz2_ext_builtinsz)Test_hook_compressed.test_bz2_ext_builtinc Cs`||j}zt||}W||n ||0||jjd||jj||fifdSr)replace_builtin_openrrrrZrr)rr+rr rrrrrs   z-Test_hook_compressed.do_test_use_builtin_opencCstj}|t_|Sr)builtinsr)Z new_open_funcr rrrrsz)Test_hook_compressed.replace_builtin_openN)rrr rrrrunittestZ skipUnlessrr r rrrrr staticmethodrrrrrres    rc@s(eZdZdZddZddZddZdS) Test_hook_encodedz'Unit tests for fileinput.hook_encoded()c Cst}t}tj||d}t}tj}|t_z t}t}|||}W|t_n|t_0||jd|j\} } | | d|| | d|| | d|| | d|| | dS)Nerrorsr<rencodingr) rrrrrrrZrrrpopr]) rrrrrr r+rZ open_resultrwrxrrrtests$  zTest_hook_encoded.testcsttd}|dWdn1s*0Yttfdd}|ddgt|ddgWdn1s0Y|dd g|d d gdS) NrsabccsNttdtd|dd}t|}Wdn1s40Y||dS)Nrzutf-8rrFrr,rrrrYrZ)rexpected_linesrnr7r$rrchecks  &z,Test_hook_encoded.test_errors..checkignoreabcstrictreplaceu�abcbackslashreplacez\x80abc)rrrrrrrrrr rr$r test_errorss (    * zTest_hook_encoded.test_errorscsttd}|dWdn1s*0Yttfdd}|dgdt|dgdWdn1s0Yt|dgdWdn1s0Yt|d gd Wdn1s0YdS) Nrs A B C D+IKw-csJtt|tdd}t|}Wdn1s00Y||dS)Nzutf-7rr)rrrnr7r$rrr s &z+Test_hook_encoded.test_modes..checkr)rrrD€ZrUrr)rzB zC r() rrrrrZ assertWarnsrrrr&rr$r test_modess (   , , zTest_hook_encoded.test_modesN)rrr rrr'r)rrrrrsrc@seZdZddZdS)MiscTestcCst|tdSr)r Z check__all__rr$rrrtest_allszMiscTest.test_allN)rrr r+rrrrr*sr*__main__)3rrrarVrrrrrr  ImportErrorriorrrrpathlibrZ test.supportrrr r rrr r r r!ZTestCaser;rrr{rrrrrrrrrrrrrrr*rmainrrrrs^           $Sa->>A