a  zeG"@sddlmZddlmZedZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl Z ddlZGdddejZGd d d eZejeed \ZZGd d d eZejeed \ZZGdddeZejeed \ZZedkre dS))abc)utilzimportlib.machineryN)make_legacy_pycc@seZdZdZddZddZd"ddddd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZddZeejdkdddZd d!ZdS)# FinderTestsaEFor a top-level module, it should just be found directly in the directory being searched. This is true for a directory with source [top-level source], bytecode [top-level bc], or both [top-level both]. There is also the possibility that it is a package [top-level package], in which case there will be a directory with the module name and an __init__.py file. If there is a directory without an __init__.py an ImportWarning is returned [empty dir]. For sub-modules and sub-packages, the same happens as above but only use the tail end of the name [sub module] [sub package] [sub empty]. When there is a conflict between a package and module having the same name in the same directory, the package wins out [package over module]. This is so that imports of modules within the package can occur rather than trigger an import error. When there is a package and module with the same name, always pick the package over the module [package over module]. This is so that imports from the package have the possibility of succeeding. cCs4|jj|jjf|jj|jjfg}|jj|g|RSN) machinerySourceFileLoaderSOURCE_SUFFIXESSourcelessFileLoaderBYTECODE_SUFFIXES FileFinder)selfrootloader_detailsrZ/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_importlib/source/test_finder.py get_finder)szFinderTests.get_findercCs||}|j||ddS)NT loader_only)r_find)rrmodulefinderrrrimport_0s zFinderTests.import_Ncompile_unlinkc Cs|dur|h}tj|}|r6|D]}t||q"|r|D]V}t||zt||Wq>ty}z|jtj kr~WYd}~q>d}~00q>| |d|}| t |d|WdS1s0YdS)zTest the finding of 'test' with the creation of modules listed in 'create'. Any names listed in 'compile_' are byte-compiled. Modules listed in 'unlink' have their source files deleted. N.root load_module) rcreate_modules py_compilecompileosrrOSErrorerrnoENOENTr assertTruehasattr) rtestZcreaterrmappingnameerrorloaderrrrrun_test4s"  zFinderTests.run_testcCs2|d|jddhdhd|jddhddS)NZ top_levelrrr-rrrr test_moduleQs   zFinderTests.test_modulecCs>|ddh|jddhdhdhd|jddhdhddS)NZpkg pkg.__init__rr.r/r0rrr test_package[s zFinderTests.test_packagecCs\tdd<}tj|d}||d}|t|dWdn1sN0YdS)Nr2pkg.subrrrr"pathdirnamerr&r')rr)pkg_dirr,rrrtest_module_in_packagees z"FinderTests.test_module_in_packagecCs`tdd}|<}tj|d}||d}|t|dWdn1sR0YdS)Nr2zpkg.sub.__init__r4rr5)rcontextr)r8r,rrrtest_package_in_packagels   z#FinderTests.test_package_in_packagecCs0d}||d||h}|d||dS)NZ_tempz {0}.__init____init__)r-formatZassertIn get_filename)rr*r,rrrtest_package_over_moduletsz$FinderTests.test_package_over_modulecCsHtd*}||dd}||Wdn1s:0YdS)NZblahrZ sdfsadsadf)rrr assertIsNone)rr)Znothingrrr test_failureys zFinderTests.test_failurec Cs|jd|jj|jjf}tdd}|dWdn1sD0Yz.|j|ddd}|t|dWt dn t d0dS) Nzmod.pywz# test file for importlibmodTrr) rr r r openwriterr&r'r"r)rrfiler,rrrtest_empty_string_for_dir~s (z%FinderTests.test_empty_string_for_dircCs:|jd|jj|jjf}d|_|||jddS)NrB*)rr r r _path_mtimeinvalidate_caches assertEqual)rrrrrtest_invalidate_cachess z"FinderTests.test_invalidate_cachescCstd}t|8}||d}|j|ddd}||Wdn1sL0Y|j|ddd}||dS)NrDrTr)rrrrZassertIsNotNoner@)rrDr)rfoundrrrtest_dir_removal_handlings (z%FinderTests.test_dir_removal_handlingwin32z>os.chmod() does not support the needed arguments under Windowscsnt}t|jjfdd}|||t|jtjtj B| |j}| |d}| ||j dS)Ncs t|j|ddddS)zCleanup function for the temporary directory. Since we muck with the permissions, we want to set them back to their original values to make sure the directory can be properly cleaned up. N)r"chmodr*__exit__)tempdirZ original_moderrcleanupsz3FinderTests.test_no_read_directory..cleanup doesnotexist)tempfileTemporaryDirectoryr"statr*st_modeZ addCleanuprRS_IWUSRS_IXUSRrrrM NOT_FOUND)rrTrVrrOrrUrtest_no_read_directorys   z"FinderTests.test_no_read_directorycCsRt6}||j}||d}|||jWdn1sD0YdS)NrW)rXNamedTemporaryFilerr*rrMr^)rZfile_objrrOrrrtest_ignore_files   zFinderTests.test_ignore_file)N)__name__ __module__ __qualname____doc__rrr-r1r3r9r;r?rArHrNrPunittestZ skipUnlesssysplatformr_rarrrrrs$      rc@seZdZdZdddZdS)FinderTestsPEP451NFcCs||}|dur|jS|Sr) find_specr,)rrr*rspecrrrrs zFinderTestsPEP451._find)Frbrcrdr^rrrrrrisri)rc@seZdZdgfZdddZdS)FinderTestsPEP420NFcCsRt6tdt||}|r,|dn|WdS1sD0YdS)Nignorer)warningscatch_warnings simplefilterDeprecationWarning find_loader)rrr*rZloader_portionsrrrrs   zFinderTestsPEP420._find)Frlrrrrrmsrmc@seZdZdZdddZdS)FinderTestsPEP302NFcCsBt&tdt||WdS1s40YdS)Nrn)rorprqrr find_module)rrr*rrrrrs  zFinderTestsPEP302._find)Frlrrrrrtsrt__main__)rBrrZimport_importlibrr$r"r rZrgrXZ test.supportrrfrorriZ test_bothZFrozen_FinderTestsPEP451ZSource_FinderTestsPEP451rmZFrozen_FinderTestsPEP420ZSource_FinderTestsPEP420rtZFrozen_FinderTestsPEP302ZSource_FinderTestsPEP302rbmainrrrrs6    .