a  ze/)@sddlmZedZedZddlZddlZddlZddlm Z ddl Z ddl Z ddl Z GdddZ Gd d d e Zejeeed \ZZGd d d e Zejeeed \ZZGdddZejeed\ZZedkre dS))util importlibzimportlib.machineryN) ModuleTypec@seZdZdZdZddZddZddZdd Zd d Z d d Z ddZ ddZ ddZ ddZddZddZddZddZdS) FinderTestsNcCs@d}t |||Wdn1s20YdS)N )r import_state assertIsNonefind)selfmoduler Y/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_importlib/import_/test_path.py test_failures zFinderTests.test_failurecCs`d}d}t|}tj||i|gd&||}|||Wdn1sR0YdS)Nr path_importer_cachepathr mock_specrr check_foundr r rimporterfoundr r r test_sys_paths   zFinderTests.test_sys_pathcCs`d}d}t|}tj||id*|||g}|||Wdn1sR0YdS)Nrrrrrr r r test_path's  zFinderTests.test_pathcCs\d}d}t|}tj||i|gd"||dgWdn1sN0YdS)Nr rr)rrrr r )r r rrr r rtest_empty_list1s  zFinderTests.test_empty_listcCsd}d}t|}tj||d}tj|gdJ|||g}|||||tj| tj||Wdn1s~0YdS)Nrrr) path_hooks) rrmock_path_hookrr rassertInsysrassertIs)r r rrhookrr r rtest_path_hooks:s  zFinderTests.test_path_hooksc Csd}tjig|gdtjdd`}td||d|tj|| t |d| t |dj tWdn1s0YWdn1s0YdS) NZ bogus_path)rrrT)recordalwaysos)rrwarningscatch_warnings simplefilterr r r"r assertEquallen assertTrue issubclasscategory ImportWarning)r Z path_entrywr r rtest_empty_path_hooksGs z!FinderTests.test_empty_path_hookscCsd}d}t|}tjt|d}tj|g|gd8||}||||tt j Wdn1st0YdS)Nrrrr) rrr r(getcwdrr rr!r"r)r rr rr$rr r r%test_path_importer_cache_empty_stringTs   z1FinderTests.test_path_importer_cache_empty_stringc Cstjdd}|ddtj}|ddtj|jj j |j j g}t}tjd|}zjtjtjdd|||d(|j d}||tWdn1s0YW||ur|tjd<n||ur|tjd<0dS)Nremail) meta_pathrrr)r"rinsertrcopypop zipimport zipimporter machinery FileFinder path_hookr_bootstrap_external_get_supported_file_loadersobjectmodulesrrr; import_moduleZassertIsInstancer)r new_pathZnew_path_importer_cacheZnew_path_hooksmissingr:r r r rtest_None_on_sys_path_s.     , z!FinderTests.test_None_on_sys_pathcCsGddd}|}d|_d}tj||id(||jjd|gWdn1s\0Y|}t|_tj||id"|jjd|g}Wdn1s0Y||j tdS)Nc@seZdZddZdS)z.TestFindercSs|jSN) to_returnr fullnamer r r find_modulexszHFinderTests.test_finder_with_find_module..TestFinder.find_moduleN)__name__ __module__ __qualname__rPr r r r TestFinderwsrT testing pathrwhatever) rMrrr rA PathFinder find_spec __loader__r.loader)r rTZfailing_finderrsuccess_finderspecr r rtest_finder_with_find_modulevs"0z(FinderTests.test_finder_with_find_modulecCsGddd}d}tj||id(||jjd|gWdn1sR0Y|}t|_tj||id"|jjd|g}Wdn1s0Y||jtdS)Nc@seZdZdZgZddZdS)z.TestFinderNcSs |j|jfSrL)rZportionsrNr r r find_loaderszHFinderTests.test_finder_with_find_loader..TestFinder.find_loader)rQrRrSrZr^r_r r r rrTsrTrUrrV) rrr rArWrXrYrZr.)r rTrr[r\r r rtest_finder_with_find_loaders"0z(FinderTests.test_finder_with_find_loadercCsGddd}d}tj||id(||jjd|gWdn1sR0Y|}|jdt|_tj||id"|jjd|g}Wdn1s0Y| ||jdS)Nc@seZdZdZdddZdS)z:FinderTests.test_finder_with_find_spec..TestFinderNcSs|jSrL)r\)r rOtargetr r rrXszDFinderTests.test_finder_with_find_spec..TestFinder.find_spec)N)rQrRrSr\rXr r r rrTsrTrUrrV) rrr rArWrX ModuleSpecrYr\r.)r rTrr[Zgotr r rtest_finder_with_find_specs"0z&FinderTests.test_finder_with_find_speccCst}|tj|t}z:t|zt|WntyT|dYn0Wn"t|t|Yn0t j dgd$| |j j dWdn1s0YdS)Nz/platform does not allow the deletion of the cwdr6)rrV)r(r8Z addCleanupchdirtempfilemkdtemprmdirOSErrorZskipTestrrr rArWrX)r Zold_dirZnew_dirr r rtest_deleted_cwds    zFinderTests.test_deleted_cwdcCshGddd}t|d}tj|d|jjWdn1sJ0Y||djdS)Nc@seZdZddZddZdS)z>FinderTests.test_invalidate_caches_finders..FakeFindercSs d|_dS)NFcalledr r r r__init__szGFinderTests.test_invalidate_caches_finders..FakeFinder.__init__cSs d|_dS)NTrjrlr r rinvalidate_cachesszPFinderTests.test_invalidate_caches_finders..FakeFinder.invalidate_cachesN)rQrRrSrmrnr r r r FakeFindersro)Z leave_alonefinder_to_invalidaterrp)rFrrrArWrnr0rk)r rocacher r rtest_invalidate_caches_finderss *z*FinderTests.test_invalidate_caches_finderscCsTddi}tj|d|jjWdn1s60Y|t|ddS)NZ clear_outrr)rrrArWrnr.r/)r rqr r r%test_invalidate_caches_clear_out_Nones*z1FinderTests.test_invalidate_caches_clear_out_None)rQrRrSr rrrrrr%r5r9rKr]r`rcrirrrsr r r rrs       rc@seZdZddZddZdS)FindModuleTestscOs|jjj|i|SrL)rArWrPr argskwargsr r rr szFindModuleTests.findcCs|||dSrL)r#r rrr r rrszFindModuleTests.check_foundNrQrRrSr rr r r rrtsrt)rrAc@seZdZddZddZdS) FindSpecTestscOs|jjj|i|SrL)rArWrXrur r rr szFindSpecTests.findcCs||j|dSrL)r#rZrxr r rrszFindSpecTests.check_foundNryr r r rrzsrzc@seZdZddZddZdS)PathEntryFinderTestscCsbGddd}tj|jgtjdd|gd|jjdWdn1sT0YdS)Nc@s$eZdZdZddZeddZdS)zGPathEntryFinderTests.test_finder_with_failing_find_spec..Finderr]cSs||jkrtdSrL path_location ImportErrorr rr r rrms zPPathEntryFinderTests.test_finder_with_failing_find_spec..Finder.__init__cSsdSrLr rOr r rrPszSPathEntryFinderTests.test_finder_with_failing_find_spec..Finder.find_moduleNrQrRrSr}rm staticmethodrPr r r rFindersrr7r)rrr}r"rrArWrXr rr r r"test_finder_with_failing_find_specs  z7PathEntryFinderTests.test_finder_with_failing_find_speccCsbGddd}tj|jgtjdd|gd|jjdWdn1sT0YdS)Nc@s$eZdZdZddZeddZdS)zIPathEntryFinderTests.test_finder_with_failing_find_module..Finderr]cSs||jkrtdSrLr|rr r rrms zRPathEntryFinderTests.test_finder_with_failing_find_module..Finder.__init__cSsdSrLr rr r rrPszUPathEntryFinderTests.test_finder_with_failing_find_module..Finder.find_moduleNrr r r rrsrr7r)rrr}r"rrArWrPrr r r$test_finder_with_failing_find_modules  z9PathEntryFinderTests.test_finder_with_failing_find_moduleN)rQrRrSrrr r r rr{sr{)rA__main__)r6rZimport_importlibrrAr(r"retypesrZunittestr+r?rrtZ test_bothZFrozen_FindModuleTestsZSource_FindModuleTestsrzZFrozen_FindSpecTestsZSource_FindSpecTestsr{ZFrozen_PEFTestsZSource_PEFTestsrQmainr r r rs2    C  )