a  zey@s.ddlmZedZedZedZddlZddlZddl m Z ddl Z ddl Z ddl Z Gdd d ZGd d d eZGd d d eZGdddZejeeed\ZZGdddZejeeeed\ZZGdddZejeeeed\ZZGdddZejeeed\ZZedkr*e dS))util importlibzimportlib.machineryzimportlib.utilN) CleanImportc@s>eZdZdddZddZddZdd Zd d Zd d ZdS) TestLoaderNcCs||_||_dSN)pathpackage)selfr is_packager Q/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_importlib/test_spec.py__init__szTestLoader.__init__cCsdS)Nzr r r r r __repr__szTestLoader.__repr__cCs2|dkr|jdur|jS|dkr&|jSt|dS)N get_filenamer )r _get_filename _is_packageAttributeErrorr namer r r __getattr__s zTestLoader.__getattr__cCs|jSr)rrr r r r szTestLoader._get_filenamecCs|jSr)r rr r r r#szTestLoader._is_packagecCsdSrr r specr r r create_module&szTestLoader.create_module)NN) __name__ __module__ __qualname__rrrrrrr r r r rs  rc@seZdZdZddZdS) NewLoaderrcCs |j|_dSr)EGGSeggsr moduler r r exec_module.szNewLoader.exec_moduleN)rrrrr#r r r r r*src@sZeZdZdZe2edeedZ e j ddZ Wdn1sL0YdS) LegacyLoaderignoreZFrozencCs |j|_|Sr)HAMhamr!r r r load_module;szLegacyLoader.load_moduleN) rrrr'warningscatch_warnings simplefilterDeprecationWarningrZ frozen_utilmodule_for_loaderr)r r r r r$2s   r$c@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'S)(ModuleSpecTestscCs^d|_d|_|j|j|_t|_|j|j|j|_ |jj|j|j|jd|_ d|j _ dSNspamspam.pyoriginT rrrcache_from_sourcecachedrloader machinery ModuleSpecrloc_spec _set_fileattrrr r r setUpCszModuleSpecTests.setUpcCsz|j|j|j}||j|j||j|j||jd||jd||jd||j d| |j dSr r9r:rr8 assertEqualassertIsr4 loader_statesubmodule_search_locationsr7 assertFalse has_locationrr r r test_defaultMszModuleSpecTests.test_defaultcCsv|j|jd}||j|j||jd||jd||jd||jd||j d| |j dSr) r9r:rr?r@r8r4rArBr7rCrDrr r r test_default_no_loaderXsz&ModuleSpecTests.test_default_no_loadercCs~|jj|j|jdd}||j|j||j|j||jd||jd||jd||j d| |j dSNFr r>rr r r test_default_is_package_falsecsz-ModuleSpecTests.test_default_is_package_falsecCs~|jj|j|jdd}||j|j||j|j||jd||jd||jg||j d| |j dSNTrHr>rr r r test_default_is_package_trueosz,ModuleSpecTests.test_default_is_package_truecCs8|jj|j|jdd}||jd|_||jdS)NZ somewherer3T)r9r:rr8rCrD assertTruerr r r test_has_location_setter{s  z(ModuleSpecTests.test_has_location_settercCs2ttj|j|jddddd}||j|kdS)NFrr8r4rBrDr7)typesysimplementationrr8rLrr otherr r r test_equalitys zModuleSpecTests.test_equalitycCs4ttj|j|j|jdd|jd}||j|dS)NTrN) rOrPrQrr8rr7r?r;rRr r r test_equality_locations z&ModuleSpecTests.test_equality_locationcCs.ttjd|jddddd}||j|dS)Nr(FrN)rOrPrQr8assertNotEqualrrRr r r test_inequalitys zModuleSpecTests.test_inequalitycCs(ttj|j|jd}||j|dS)N)rr8)rOrPrQrr8rVrrRr r r test_inequality_incompletes z*ModuleSpecTests.test_inequality_incompletecCs"|jd|j}||jddS)N spam.eggsr1r9r:r8r?parentrr r r test_packageszModuleSpecTests.test_packagecCs&|jjd|jdd}||jddS)NrYTrHrZrr r r test_package_is_packages z'ModuleSpecTests.test_package_is_packagecCs4|jj}d|j_|jj}||d||ddS)NZthere)rr7r@r?)r beforeZafterr r r test_cached_sets  zModuleSpecTests.test_cached_setcCs$|j|j|j}||jddSr)r9r:rr8r@r7rr r r test_cached_no_originsz%ModuleSpecTests.test_cached_no_origincCs*|jj|j|j|jd}||jddS)Nr3)r9r:rr8rr@r7rr r r $test_cached_with_origin_not_locationsz4ModuleSpecTests.test_cached_with_origin_not_locationcCs"|j|j}||jj|dSr)rr6rr?r;r7)r Zexpectedr r r test_cached_sourcesz"ModuleSpecTests.test_cached_sourcecCsd|j_||jjddS)Nzspam.spamspamspam)r;r4r@r7rr r r !test_cached_source_unknown_suffixsz1ModuleSpecTests.test_cached_source_unknown_suffixcCs@tjj}dtj_z|jj}W|tj_n |tj_0||ddSr)rPrQ cache_tagr;r7r@)r Zoriginalr7r r r $test_cached_source_missing_cache_tags  z4ModuleSpecTests.test_cached_source_missing_cache_tagcCsd|j_||jjddS)Nzspam.pyc)r;r4r?r7rr r r test_cached_sourcelesssz&ModuleSpecTests.test_cached_sourcelessN)rrrr=rErFrIrKrMrTrUrWrXr\r]r_r`rarbrcrerfr r r r r/As&         r/)rr9c@seZdZeddZddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZddZddZddZdS) ModuleSpecMethodsTestscCs|jjSrinit _bootstraprr r r bootstrapsz ModuleSpecMethodsTests.bootstrapcCs^d|_d|_|j|j|_t|_|j|j|j|_ |jj|j|j|jd|_ d|j _ dSr0r5rr r r r=szModuleSpecMethodsTests.setUpcCsVt|j_|j|j}|tj|j<|t |d|j |j|| |j ddS)Nr r)rrr8rmodule_from_specrPmodulesrrChasattrrk_execr?r r!r r r test_execs   z ModuleSpecMethodsTests.test_execcCspt|j_t|jj,|j|j}tj|jj}Wdn1sH0Y| |j d| ||dSNr) rrr8rrrk_loadrPrmr?r r@)r loaded installedr r r test_loads  ,z ModuleSpecMethodsTests.test_loadcstGfdddt}||j_t|jj,|j|j}tj |jj}Wdn1sb0Y| || |dS)NcseZdZfddZdS)zBModuleSpecMethodsTests.test_load_replaced..ReplacingLoadercstj|j<dSr)rPrmrr!Z replacementr r r#szNModuleSpecMethodsTests.test_load_replaced..ReplacingLoader.exec_moduleNrrrr#r rvr r ReplacingLoadersrx) objectrrr8rrrkrrrPrmr@)r rxrsrtr rvr test_load_replaceds , z)ModuleSpecMethodsTests.test_load_replacedc CsGdddt}||j_t|jjZ|t|j|j}Wdn1sV0Y| |jjt j Wdn1s0YdS)Nc@seZdZddZdS)z=ModuleSpecMethodsTests.test_load_failed..FailedLoadercSstdSr) RuntimeErrorr!r r r r#szIModuleSpecMethodsTests.test_load_failed..FailedLoader.exec_moduleNrwr r r r FailedLoadersr| rrr8rrZ assertRaisesr{rkrrZ assertNotInrPrmr r|rsr r r test_load_faileds   ,z'ModuleSpecMethodsTests.test_load_failedc CsGdddt}||j_t|jjZ|t|j|j}Wdn1sV0Y| |jjt j Wdn1s0YdS)Nc@seZdZddZdS)zEModuleSpecMethodsTests.test_load_failed_removed..FailedLoadercSstj|j=tdSr)rPrmrr{r!r r r r#(s zQModuleSpecMethodsTests.test_load_failed_removed..FailedLoader.exec_moduleNrwr r r r r|'sr|r}r~r r r test_load_failed_removed&s   ,z/ModuleSpecMethodsTests.test_load_failed_removedcCsVt|j_t|jj|j|j}Wdn1s:0Y||jddSNr%) r$rr8rrrkrrr?r(r rsr r r test_load_legacy1s ,z'ModuleSpecMethodsTests.test_load_legacycCs|t|j_t|jj|j|j}Wdn1s:0Y||j|jj| |j |jj ||j |jdSr) r$rr8rrrkrrr@ __loader__r? __package__r[__spec__rr r r test_load_legacy_attributes8s  ,z2ModuleSpecMethodsTests.test_load_legacy_attributescsxtGfdddt}||j_t|jj4|j|j}|t j |jjWdn1sj0YdS)NcseZdZfddZdS)zUModuleSpecMethodsTests.test_load_legacy_attributes_immutable..ImmutableLoadercstj|<Sr)rPrmrr"r r r)Ds zaModuleSpecMethodsTests.test_load_legacy_attributes_immutable..ImmutableLoader.load_moduleN)rrrr)r rr r ImmutableLoaderCsr) ryrrr8rrrkrrr@rPrm)r rrsr rr %test_load_legacy_attributes_immutableAs  z.LoadercSs d|jS)Nz)formatrr!r r r module_reprszNModuleReprTests.test_module___loader___module_repr..Loader.module_reprNrrrrr r r r Loadersrz)r"rrk _module_reprr?r rmodreprr r r "test_module___loader___module_reprs z2ModuleReprTests.test_module___loader___module_reprcCs>Gdddt}||j_|j|j}||dddS)Nc@seZdZddZdS)zFModuleReprTests.test_module___loader___module_repr_bad..LoadercSstdSr) Exceptionr!r r r rszRModuleReprTests.test_module___loader___module_repr_bad..Loader.module_reprNrr r r r rsr#)>r1rr"rrkrr?rrr r r &test_module___loader___module_repr_bads  z6ModuleReprTests.test_module___loader___module_repr_badcCs<d}||j_|j|j_|j|j}||dd|dS)Nzin a hole, in the groundzr1)rr4r"rrkrr?r)r r4rr r r test_module___spec__s  z$ModuleReprTests.test_module___spec__cCsDd}||j_d|j_|j|j_|j|j}||dd|dS)Nzin_a_galaxy_far_far_away.pyTr1) rr4r<r"rrkrr?r)r locationrr r r test_module___spec___locations  z-ModuleReprTests.test_module___spec___locationcCs8t|j_|j|j_|j|j}||dddSNrr1) rrr8r"rrkrr?rr rr r r test_module___spec___no_origins   z.ModuleReprTests.test_module___spec___no_origincCs6d|j_|j|j_|j|j}||dddSN r1)rr8r"rrkrr?rrr r r (test_module___spec___no_origin_no_loaders z8ModuleReprTests.test_module___spec___no_origin_no_loadercCs*|j`|j|j}||dddS)Nr?)r"rrkrr?rrr r r test_module_no_namesz#ModuleReprTests.test_module_no_namecCs2d}||j_|j|j}||dd|dS)Nze/i/e/i/o/spam.pyrr1)r"rrkrr?r)r filenamerr r r test_module_with_files  z%ModuleReprTests.test_module_with_filecCs.t|j_|j|j}||dddSrrrr r r test_module_no_files  z#ModuleReprTests.test_module_no_filecCs$|j|j}||dddSr)rkrr"r?rrr r r test_module_no_file_no_loadersz-ModuleReprTests.test_module_no_file_no_loaderN)rrrrrkr=rrrrrrrrrrr r r r rs    rc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Zd3d4Zd5d6Zd7S)8 FactoryTestscCsJd|_tjd|_|j|j|_t|_t|j|_ t|jd|_ dS)Nr1r2T) rrrabspathrr6r7rr8 fileloader pkgloaderrr r r r=s  zFactoryTests.setUpcCsz|j|j|j}||j|j||j|j||jd||jd||jd||j d| |j dSr rspec_from_loaderrr8r?r@r4rArBr7rCrDrr r r test_spec_from_loader_defaultsz*FactoryTests.test_spec_from_loader_defaultcCsGddd}|}|j|j|}||j|j||j|||jd||jd||jd||j d| |j dS)Nc@seZdZddZdS)zNFactoryTests.test_spec_from_loader_default_with_bad_is_package..LoadercSstdSr ImportErrorrr r r r szYFactoryTests.test_spec_from_loader_default_with_bad_is_package..Loader.is_packageNrrrr r r r r r sr) rrrr?r8r@r4rArBr7rCrDr rr8rr r r 1test_spec_from_loader_default_with_bad_is_packagesz>FactoryTests.test_spec_from_loader_default_with_bad_is_packagecCsd}|jj|j|j|d}||j|j||j|j||j|||jd||jd||j d| |j dS)Nzsomewhere over the rainbowr3rr r4rr r r test_spec_from_loader_originsz)FactoryTests.test_spec_from_loader_origincCs~|jj|j|jdd}||j|j||j|j||jd||jd||jd||j d| |j dSrGrrr r r &test_spec_from_loader_is_package_false$sz3FactoryTests.test_spec_from_loader_is_package_falsecCs~|jj|j|jdd}||j|j||j|j||jd||jd||jg||j d| |j dSrJrrr r r %test_spec_from_loader_is_package_true0sz2FactoryTests.test_spec_from_loader_is_package_truecCsd}|jj|j|j|dd}||j|j||j|j||j|||jd||jg||j d| |j dS)Nzwhere the streets have no nameT)r4r rrr r r +test_spec_from_loader_origin_and_is_package<sz8FactoryTests.test_spec_from_loader_origin_and_is_packagecCstdd}|j|j|}||j|j||j|||jd||jd||j d||j d| |j dSrG rrrrr?r8r@r4rArBr7rCrDr r8rr r r 2test_spec_from_loader_is_package_with_loader_falseIs z?FactoryTests.test_spec_from_loader_is_package_with_loader_falsecCstdd}|j|j|}||j|j||j|||jd||jd||j g||j d| |j dSrJrrr r r 1test_spec_from_loader_is_package_with_loader_trueUs z>FactoryTests.test_spec_from_loader_is_package_with_loader_truecCs~|j|j|j}||j|j||j|j||j|j||j d||j d||j |j | |j dSrrrrrr?r8r4rr@rArBr7rLrDrr r r .test_spec_from_loader_default_with_file_loaderasz;FactoryTests.test_spec_from_loader_default_with_file_loadercCs|jj|j|jdd}||j|j||j|j||j|j||j d||j d||j |j | |j dSrGrrr r r 6test_spec_from_loader_is_package_false_with_fileloaderlszCFactoryTests.test_spec_from_loader_is_package_false_with_fileloadercCs|jj|j|jdd}||j|j||j|j||j|j||j d||j t g||j |j ||jdSrJ)rrrrr?r8r4rr@rArBrgetcwdr7rLrDrr r r 5test_spec_from_loader_is_package_true_with_fileloaderxszBFactoryTests.test_spec_from_loader_is_package_true_with_fileloadercCs|j|j|j}||j|j||j|jjjj ||jj|j||jj|j||j |j| |j d| |j d||j|j||jdSr)rspec_from_file_locationrrr?ZassertIsInstancer8abcr9SourceFileLoaderr4r@rArBr7rLrDrr r r $test_spec_from_file_location_defaults z1FactoryTests.test_spec_from_file_location_defaultcCs,|j|jt|j}||j|jdSr)rrrpathlibPurePathrr?r4rr r r *test_spec_from_file_location_path_like_args  z7FactoryTests.test_spec_from_file_location_path_like_argcCs|j|j}||ddSrrrrr@rr r r 5test_spec_from_file_location_default_without_locationszBFactoryTests.test_spec_from_file_location_default_without_locationcCs |j|jd}||ddS)NrYrrr r r /test_spec_from_file_location_default_bad_suffixsz) rrrr8r?r4r@rArBr7rLrDrr r r ?test_spec_from_file_location_loader_no_location_no_get_filenames zLFactoryTests.test_spec_from_file_location_loader_no_location_no_get_filenamecCsGddd}|}|jj|j|d}||j|j||j|||jd||jd||jd||j d| |j dS)Nc@seZdZddZdS)z]FactoryTests.test_spec_from_file_location_loader_no_location_bad_get_filename..LoadercSstdSrrrr r r rszjFactoryTests.test_spec_from_file_location_loader_no_location_bad_get_filename..Loader.get_filenameN)rrrrr r r r rsrrr) rrrr?r8r4r@rArBr7rLrDrr r r @test_spec_from_file_location_loader_no_location_bad_get_filenameszMFactoryTests.test_spec_from_file_location_loader_no_location_bad_get_filenamecCs|jj|j|j|jdd}||j|j||j|j||j|j||j d||j d||j |j | |j dSNr8rBrrrrrr?r8r4r@rArBr7rLrDrr r r &test_spec_from_file_location_smsl_nonesz3FactoryTests.test_spec_from_file_location_smsl_nonecCs|jj|j|j|jgd}||j|j||j|j||j|j||j d||j t g||j |j ||jdSr)rrrrrr?r8r4r@rArBrrr7rLrDrr r r 'test_spec_from_file_location_smsl_emptysz4FactoryTests.test_spec_from_file_location_smsl_emptycCs|jj|j|j|jdgd}||j|j||j|j||j|j||j d||j dg||j |j | |j dS)Nr rrrr r r +test_spec_from_file_location_smsl_not_emptysz8FactoryTests.test_spec_from_file_location_smsl_not_emptycCs|jj|j|j|jd}||j|j||j|j||j|j||j d||j t g||j |j ||jdSr)rrrrrr?r8r4r@rArBrrr7rLrDrr r r )test_spec_from_file_location_smsl_defaultsz6FactoryTests.test_spec_from_file_location_smsl_defaultcCsGddd}|}|jj|j|j|d}||j|j||j|||j|j||jd||j d||j |j | |j dS)Nc@seZdZddZdS)zRFactoryTests.test_spec_from_file_location_smsl_default_not_package..LoadercSsdSrr rr r r r sz]FactoryTests.test_spec_from_file_location_smsl_default_not_package..Loader.is_packageNrr r r r rsrr rrrrr?r8r4r@rArBr7rLrDrr r r 5test_spec_from_file_location_smsl_default_not_packageszBFactoryTests.test_spec_from_file_location_smsl_default_not_packagecCs|jj|j|j|jd}||j|j||j|j||j|j||j d||j d||j |j | |j dSrrrr r r 7test_spec_from_file_location_smsl_default_no_is_packageszDFactoryTests.test_spec_from_file_location_smsl_default_no_is_packagecCsGddd}|}|jj|j|j|d}||j|j||j|||j|j||jd||j d||j |j | |j dS)Nc@seZdZddZdS)zUFactoryTests.test_spec_from_file_location_smsl_default_bad_is_package..LoadercSstdSrrrr r r r sz`FactoryTests.test_spec_from_file_location_smsl_default_bad_is_package..Loader.is_packageNrr r r r rsrrrrr r r 8test_spec_from_file_location_smsl_default_bad_is_packageszEFactoryTests.test_spec_from_file_location_smsl_default_bad_is_packagecCs|jj|jtj|j|jd}||j|j||j|j||j tj|j| |j d| |j d||j tj|j ||jdSr)rrrrrbasenamerr?r8r4r@rArBr7relpathrLrDrr r r *test_spec_from_file_location_relative_path,s z7FactoryTests.test_spec_from_file_location_relative_pathN)rrrr=rrrrrrrrrrrrrrrrrrrrrrrrrrr r r r rs6                 r__main__) rZ test_utilZimport_importlibrir9Zos.pathrrZ test.supportrZunittestrPr*rrr$r/Z test_bothZFrozen_ModuleSpecTestsZSource_ModuleSpecTestsrgZFrozen_ModuleSpecMethodsTestsZSource_ModuleSpecMethodsTestsrZFrozen_ModuleReprTestsZSource_ModuleReprTestsrZFrozen_FactoryTestsZSource_FactoryTestsrmainr r r r sL     && [ K