a  ze{$@sddlmZddlmZedZddlmZddlZddlZddl Z Gdddej Z ej e ed \Z ZGd d d ej Z ej e ed \ZZGd d d Zej eed \ZZedkredS))abc)utilzimportlib.machinery)captured_stdoutNc@sHeZdZddZddZddZddZd d Zd d Zd Z ddZ d S)ExecModuleTestsc Cst|t}|jj||jjd|jj|d}t|}||_ |jj || |j | t |d||j jd||fWdWdS1s0YWdn1s0YdS)Nfrozen)origin is_package__spec__)runcacher machinery ModuleSpecFrozenImporterr types ModuleTyper exec_module assertTrue initializedhasattr assertEqualrgetvalue)selfnamestdoutspecmodulerZ/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_importlib/frozen/test_loader.pyrs    zExecModuleTests.exec_modulecCs^d}||\}}d|i}|D]\}}|t|||q"||d|t|ddS)N __hello____name__ Hello world! r )ritemsrgetattrrr)rrroutputcheckattrvaluerrr test_modules zExecModuleTests.test_modulec Csbd}||\}}d|i}|D].\}}t||}|||dj||||dq"||ddS)N __phello__rz,for {name}.{attr}, {given!r} != {expected!r}rr%ZgivenZexpectedr )rr!r"rformatrrrr#r$r%r& attr_valuerrr test_package%s zExecModuleTests.test_packagec Csd}tdj||\}}d|i}|D].\}}t||}|||dj||||dq.||dWdn1s~0YdS)N__phello__.spamr(rz*for {name}.{attr}, {given} != {expected!r}r)r )rr rr!r"rr*r+rrrtest_lacking_parent1s  z#ExecModuleTests.test_lacking_parentcCsdd}||\}}t*tdt|jj|}Wdn1sJ0Y||ddSNrignore) rwarningscatch_warnings simplefilterDeprecationWarningr r module_reprr)rrrr#repr_strrrrtest_module_repr>s  ,z ExecModuleTests.test_module_reprcCs&d}||\}}|t|ddSNrr2)rrrepr)rrrr#rrrtest_module_repr_indirectGs  z)ExecModuleTests.test_module_repr_indirectNcCsH|t}|dWdn1s*0Y||jjddSNZ _not_real) assertRaises ImportErrorrr exceptionrrcmrrrtest_unloadablePs (zExecModuleTests.test_unloadable) r __module__ __qualname__rr'r-r/r9r<test_state_after_failurerCrrrrr s    r)r c@sHeZdZddZddZddZddZd d Zd d Zd Z ddZ d S) LoaderTestsc Cstdt}t*tdt|jj d}Wdn1sL0Ydd|jjd}| D]\}}| t |||qn| | d|t|dWdn1s0YWdn1s0YdS)Nrr1r __package__ __loader__r __file__)rr rr3r4r5r6r r load_moduler!rr"r assertFalser)rrrr$r%r&rrrr'^s  ,zLoaderTests.test_modulec Cstdt}t*tdt|jj d}Wdn1sL0Yddg|jjd}| D]*\}}t ||}| ||d|||fqp| | d|t|dWdn1s0YWdn1s0YdS)Nr(r1)rrJ__path__rKzfor __phello__.%s, %r != %rr rLrr rr3r4r5r6r rrMr!r"rrrNrrrrr$r%r&r,rrrr-ls$  , zLoaderTests.test_packagec Cstddt}t*tdt|jj d}Wdn1sN0Ydd|jjd}| D]*\}}t ||}| ||d|||fqp| | d|t|dWdn1s0YWdn1s0YdS)Nr(r.r1rIz for __phello__.spam.%s, %r != %rr rLrPrQrrrr/~s(  , zLoaderTests.test_lacking_parentc Cstdt|}t8tdt|jj d}|jj d}Wdn1sZ0Y| ||| | dWdn1s0YWdn1s0YdS)Nrr1zHello world! Hello world! ) rr rr3r4r5r6r rrMZassertIsrr)rrZmodule1Zmodule2rrrtest_module_reuses  ,  zLoaderTests.test_module_reusec Cstdtlt8tdt|jj d}|jj |}Wdn1sZ0Y| |dWdn1s0YWdn1s0YdSr0) rr rr3r4r5r6r rrMr7r)rrr8rrrr9s  ,zLoaderTests.test_module_reprc CsrtdDt|jjd}Wdn1s60YWdn1sT0Y|t|ddSr:)rr rr rrMrr;)rrrrrr<s J z%LoaderTests.test_module_repr_indirectNcCsL|t}|jjdWdn1s.0Y||jjddSr=)r>r?r rrMrr@rrArrrrCs ,zLoaderTests.test_unloadable) rrDrEr'r-r/rRr9r<rFrCrrrrrG\s  rGc@s0eZdZdZddZddZddZdd Zd S) InspectLoaderTestsz7Tests for the InspectLoader methods for FrozenImporter.cCsrd}tT}|jj|}t|}t||j|t |d| | dWdn1sd0YdS)Nrrr ) rr rget_coderrexec__dict__rrrr)rrrcodemodrrr test_get_codes  z InspectLoaderTests.test_get_codecCs|jjd}||dS)Nr)r r get_sourceZ assertIsNone)rresultrrrtest_get_sourcesz"InspectLoaderTests.test_get_sourcecCs4d}|D]&\}}|jj|}|t||qdS)N))rF)r(T)r.F)r rr rbool)rZtest_forrr r[rrrtest_is_packages z"InspectLoaderTests.test_is_packagec Cs^dD]T}t|jj|}|t}|dWdn1s>0Y||jjdqdS)N)rTrZr importlib)r"r rr>r?rr@r)rZ meth_namemethodrBrrr test_failures  &zInspectLoaderTests.test_failureN)rrDrE__doc__rYr\r^rarrrrrSs  rS__main__)rHrrZimport_importlibr Z test.supportrrZunittestr3rGrZ test_bothZFrozen_ExecModuleTestsZSource_ExecModuleTestsZFrozen_LoaderTestsZSource_LoaderTestsrSZFrozen_ILTestsZSource_ILTestsrmainrrrrs(    M Y %