a  zel@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ej ej edZej edZGdddejZedkre dS)N)maindatazpy2_test_grammar.pyc@sLeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS)TestMaincCs d|_dSN)temp_dirselfr K/opt/bitninja-python-dojo/embedded/lib/python3.9/lib2to3/tests/test_main.pysetUpszTestMain.setUpcCs$tjjdd=|jr t|jdSr)loggingroothandlersrshutilrmtreerr r r tearDownszTestMain.tearDowncCs^tj}tj}tj}|t_|t_|t_z td|W|t_|t_|t_S|t_|t_|t_0dS)Nz lib2to3.fixes)sysstdinstdoutstderrr)rargsZ in_captureZ out_captureZ err_captureZ save_stdinZ save_stdoutZ save_stderrr r r run_2to3_captures$ zTestMain.run_2to3_capturecCsttd}t}td|}t}|dg|||}||d|d}| d|| d|dS)Nuprint 'nothing' print u'über' ascii-rz-print 'nothing'z9WARNING: couldn't encode 's diff for your terminal) ioStringIOBytesIOcodecs getwriterr assertEqualgetvaluedecodeassertIn)rZ input_streamoutZout_encerrretoutputr r r test_unencodable_diff,s   zTestMain.test_unencodable_diffcCst|_tj|jd|_tj|jd|_t|jt|jg|_ t tj|jdd |j dt t|j|j tjttj|jd|_tj|jd|_t |jd}|dWdn1s0Y|j ddS)z5Setup a test source tree and output destination tree.Zpython2_projectZpython3_projectz __init__.pywz trivial.pyz#print 'I need a simple conversion.'N)tempfilemkdtemprospathjoin py2_src_dir py3_dest_dirmkdir setup_filesopencloseappendrcopyPY2_TEST_MODULEbasenametrivial_py2_file init_py2_filewrite)rZtrivialr r r setup_test_source_trees8s    (z TestMain.setup_test_source_treesc s|t}t}d|ddddd|j|jgtd||}||d|}|d ||d |j|jf||t fd d |j Dt t |j|j D]4}|d t j |j|t j |j|f|qtt j}||dd|||dd|dS)z92to3 a single directory with a new output dir and suffix.ZTEST-nz --add-suffix--write-unchanged-files --no-diffs --output-dirrz implies -w.6Output in %r will mirror the input directory %r layoutc3s|]}|VqdSrr .0namesuffixr r \zGTestMain.test_filename_changing_on_output_single_dir..zWriting converted %s to %szNo changes to .*/__init__\.py/zNo changes to .*/trivial\.pyN)r;rrrr/r.rr r"setr1r+listdirr,r-reescapesepZ assertRegexreplaceZassertNotRegex)rr#r$r%rrDrNr rEr +test_filename_changing_on_output_single_dirKsJ       z4TestMain.test_filename_changing_on_output_single_dircCs|t}|j|jg}tdd|D}|ddddd|jg|tdt|}||d | }| d |j|j f|||tt |jd S) z62to3 two files in one directory with a new output dir.css|]}tj|VqdSr)r+r,r7rBr r r rGmrHzFTestMain.test_filename_changing_on_output_two_files..r<-wr=r>r?r@rrAN)r;rrr8r9rJrr/rr r"r.r+rK)rr$Z py2_filesZexpected_filesr%rr r r *test_filename_changing_on_output_two_fileshs*  z3TestMain.test_filename_changing_on_output_two_filescCs|t}|dddd|j|jgtdt|}||d|}|d|j|j f||t t j |jgt t |jdS) z)2to3 a single file with a new output dir.r<rQr>r?r@rrAN)r;rrrr/r8rr r"r.rJr+r,r7rK)rr$r%rr r r ,test_filename_changing_on_output_single_fileys&  z5TestMain.test_filename_changing_on_output_single_fileN) __name__ __module__ __qualname__r rrr'r;rPrRrSr r r r rs r__main__)rrr r+rLrrr)ZunittestZlib2to3rr,r-dirname__file__Z TEST_DATA_DIRr6ZTestCaserrTr r r r s w