a ze?@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z Gdddej ZGdddej Zed kredS) z#Test harness for the zipapp module.N) requires_zlib)patchc@s eZdZdZddZddZddZdd Zd d Zd d Z ddZ e ddZ ddZ ddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zeej d2kd3d4d5Z!eej d2kd3d6d7Z"d8S)9 ZipAppTestz!Test zipapp module functionality.cCs&t}||jt|j|_dSNtempfileTemporaryDirectoryZ addCleanupcleanuppathlibPathnametmpdirselfr rD/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_zipapp.pysetUps zZipAppTest.setUpcCsN|jd}||d|jd}tt|t|||dSNsource __main__.py source.pyzr mkdirtouchzipappcreate_archivestr assertTrueis_filerrtargetrrrtest_create_archives    zZipAppTest.test_create_archivecCsF|jd}||d|jd}t||||dSr)r rrrrrrrrrr test_create_archive_with_pathlib!s     z+ZipAppTest.test_create_archive_with_pathlibcCs|jd}||d|d|d|ddt}tt|||dt |d0}| d| | d | Wdn1s0YdS) NrrfooZbarz __init__.pyrrzfoo/zbar/) r rrioBytesIOrrrseekzipfileZipFileassertInnamelistrrr zrrr test_create_archive_with_subdirs*s     z+ZipAppTest.test_create_archive_with_subdirscCsdd}|jd}||d|d|d|jd}tj|||dt|d @}|d||d|| d|Wdn1s0YdS) NcSs |jdkS)Nz.pyc)suffixpathrrrskip_pyc_files<szBZipAppTest.test_create_archive_with_filter..skip_pyc_filesrrtest.pyztest.pycrfilterr$) r rrrrr(r)r*r+Z assertNotIn)rr2rr r-rrrtest_create_archive_with_filter9s     z*ZipAppTest.test_create_archive_with_filtercCsdd}|jd}||d|d|d|dd|jd}tj|||d t|d D}|t| d | d| | d| Wdn1s0YdS) NcSs|jddkS)Nrdummy)partsr0rrrskip_dummy_dirOszIZipAppTest.test_create_archive_filter_exclude_dir..skip_dummy_dirrrr3r7ztest2.pyrr4r$) r rrrrr(r) assertEquallenr+r*)rr9rr r-rrr&test_create_archive_filter_exclude_dirKs     z1ZipAppTest.test_create_archive_filter_exclude_dircCsH|jd}||dtt||jd}||dSrr)rrZexpected_targetrrr"test_create_archive_default_target_s    z-ZipAppTest.test_create_archive_default_targetcCs|jd}||d|d|jd}tj||ddt|d0}dD]}|||j tj qVWdn1s0YdS) Nrrr3rT) compressedr$)rr3) r rrrrr(r)r;ZgetinfoZ compress_type ZIP_DEFLATED)rrr r-r rrr$test_create_archive_with_compressionhs    z/ZipAppTest.test_create_archive_with_compressioncCsl|jd}||d|jd}|tj$tt|t|Wdn1s^0YdS)Nrfoo.pyrr rr assertRaisesr ZipAppErrorrrrrrr test_no_mainws    zZipAppTest.test_no_maincCsp|jd}||d|jd}|tj(tjt|t|ddWdn1sb0YdS)Nrrr pkg.mod:fnmainrCrrrrtest_main_and_main_pys    z ZipAppTest.test_main_and_main_pycCs|jd}||d|jd}tjt|t|ddtt|d2}|d| |d| dWdn1s0YdS) NrrBrrGrHr$rs pkg.mod.fn()) r rrrrrr(r)r*r+readr,rrrtest_main_writtens   zZipAppTest.test_main_writtencCs|jd}||d|d|jd}tjt|t|ddtt|d&}|d| d Wdn1s0YdS) NrrBzbar.pyrrGrHr$r) r rrrrrr(r)r;r+countr,rrrtest_main_only_written_onces    z&ZipAppTest.test_main_only_written_oncec Cs|jd}||jd}gd}|D]t}|j|dT|tj(tjt|t||dWdn1st0YWdq(1s0Yq(dS)Nrr) r#zfoo:z:barz12:barza.b.c.:dz.a:bza:b.za:.bz a:silly namerH)r rZsubTestrDrrErr)rrr ZproblemsrIrrrtest_main_validations  zZipAppTest.test_main_validationcCs||jd}||d|jd}tt|t||d"}||ddWdn1sn0YdS)Nrrrrbr:#!) r rrrrropenZassertNotEqualrKrrr frrrtest_default_no_shebangs    z"ZipAppTest.test_default_no_shebangcCs|jd}||d|jd}tjt|t|dd|d2}||dd|d | Wdn1s0YdS) NrrrpythonZ interpreterrRr:rSspython ) r rrrrrrTr;rKreadlinerUrrrtest_custom_interpreters    z"ZipAppTest.test_custom_interpretercCsR|jd}||dt}tjt||dd|| ddS)NrrrXrYs #!python ) r rrr%r&rrrrgetvalue startswithrrrrtest_pack_to_fileobjs   zZipAppTest.test_pack_to_fileobjcCsZ|jd}||d|jd}tjt|t|dd|tt|ddSNrrrrXrYr rrrrrr;get_interpreterrrrrtest_read_shebangs    zZipAppTest.test_read_shebangcCsV|jd}||d|jd}tt|t||tt|ddSrr`rrrrtest_read_missing_shebangs    z$ZipAppTest.test_read_missing_shebangcCs||jd}||d|jd}tjt|t|dd|jd}tjt|t|dd|tt|ddS)NrrrrXrY changed.pyz python2.7r`rrr new_targetrrrtest_modify_shebangs    zZipAppTest.test_modify_shebangcCst|jd}||d|jd}tjt|t|ddt}tjt||dd|| ddS)NrrrrXrYre #!python2.7 ) r rrrrrr%r&rr\r]rfrrrtest_write_shebang_to_fileobjs   z(ZipAppTest.test_write_shebang_to_fileobjcCsh|jd}||d|jd}|jd}tj||ddtj||dd|t|ddS)Nrrz target1.pyzz target2.pyzrXrYre)r rrrrr;ra)rrZtarget1Ztarget2rrrtest_read_from_pathobjs    z!ZipAppTest.test_read_from_pathobjcCs~|jd}||d|jd}t}tjt||ddt}|dtj||dd| | ddS) NrrrrXrYrreri) r rrr%r&rrrr'rr\r])rrr Z temp_archivergrrrtest_read_from_fileobjs    z!ZipAppTest.test_read_from_fileobjcCs||jd}||d|jd}tjt|t|dd|jd}tjt|t|dd|tt|ddS)NrrrrXrYrdr`rfrrrtest_remove_shebangs    zZipAppTest.test_remove_shebangcCs|jd}||dt}tjt||ddt}|dtj||dd|dt |d&}| t | dhWdn1s0YdS)NrrrXrYrr$)r rrr%r&rrrr'r(r)r;setr+)rrr rgr-rrrtest_content_of_copied_archives    z)ZipAppTest.test_content_of_copied_archivewin32z*Windows does not support an executable bitcCsZ|jd}||d|jd}tjt|t|dd||jtj @dSr_) r rrrrrrstatst_modeS_IEXECrrrrtest_shebang_is_executable.s    z%ZipAppTest.test_shebang_is_executablecCsZ|jd}||d|jd}tjt|t|dd||jtj @dS)NrrrrY) r rrrrrZ assertFalserqrrrsrrrr!test_no_shebang_is_not_executable9s    z,ZipAppTest.test_no_shebang_is_not_executableN)#__name__ __module__ __qualname____doc__rr!r"r.r6r=r>rrArFrJrLrOrQrWr[r^rbrcrhrjrkrlrmrounittestZskipIfsysplatformrtrurrrrrsD                   rc@s^eZdZdZddZddZddZdd Zd d Zd d Z e de j dddZ ddZdS)ZipAppCmdlineTestz$Test zipapp module command line API.cCs&t}||jt|j|_dSrrrrrrrIs zZipAppCmdlineTest.setUpcCs8|jd}||d|jd}t|||Sr)r rrrrrrrr make_archiveNs     zZipAppCmdlineTest.make_archivecCsN|jd}||dt|g}t||d}||dS)Nrrz.pyz) r rrrrrI with_suffixrr)rrargsr rrrtest_cmdline_createWs     z%ZipAppCmdlineTest.test_cmdline_createcCs@|}|jd}t|dt|g}t|||dSN target.pyz-o)r~r rrrIrr)roriginalr rrrrtest_cmdline_copyas   z#ZipAppCmdlineTest.test_cmdline_copycCsj|}|jd}t|dt|g}|t}t|Wdn1sN0Y||jj dSr r~r rrD SystemExitrrIr exceptioncoderrr rcmrrrtest_cmdline_copy_inplaceis   (z+ZipAppCmdlineTest.test_cmdline_copy_inplacecCsn|}|jd}t|dt|ddg}|t}t|Wdn1sR0Y||jj dS)Nrrz-mzfoo:barrrrrrtest_cmdline_copy_change_mainss   (z/ZipAppCmdlineTest.test_cmdline_copy_change_mainz sys.stdout)Z new_callablecCsl|}t|dg}|t}t|Wdn1s>0Y||jjd|| ddS)N--inforzInterpreter: ) r~rrDrrrIr;rrr\)rZ mock_stdoutr rrrrrtest_info_command}s   (z#ZipAppCmdlineTest.test_info_commandcCs\|jd}t|dg}|t}t|Wdn1s@0Y||jjdS)Nz dummy.pyzr) r rrDrrrIrrr)rr rrrrrtest_info_errors    (z!ZipAppCmdlineTest.test_info_errorN)rvrwrxryrr~rrrrrr%StringIOrrrrrrr}Es     r}__main__)ryr%r rqr{rrzrr(Z test.supportrZ unittest.mockrZTestCaserr}rvrIrrrrs   8M