a  zeE*@shddlZddlZddlZddlZddlZddlmZejddZejddZ Gdddej Z Gd d d e Z Gd d d e Z Gd dde ZGddde ZGddde ZGddde ZGddde ZGddde ZGddde ZGddde ZGddde ZGdd d e ZGd!d"d"e ZGd#d$d$e ZGd%d&d&e Zed'krdedS)(N)utilc csZtj}tj}z&dVW|t_tjtj|n|t_tjtj|0dS)z Make sure sys.modules is the same object and has the same content when exiting the context as when entering. Similar to importlib.test.util.uncache, but doesn't require explicit names. N)sysmodulescopyclearupdate)Zsys_modules_savedZsys_modules_copyr[/opt/bitninja-python-dojo/embedded/lib/python3.9/test/test_importlib/test_namespace_pkgs.pysys_modules_contexts    r c ks|dtj|dtjtjfi|}|<tdVWdn1sT0YWdn1sr0YdS)z Save import state and sys.modules cache and restore it on exit. Typical usage: >>> with namespace_tree_context(path=['/tmp/xxyy/portion1', ... '/tmp/xxyy/portion2']): ... pass meta_path path_hooksN) setdefaultrr r rZ import_stater )kwargsZimport_contextrrr namespace_tree_context$s rc@s6eZdZdZejejedZ ddZ ddZ dS)NamespacePackageTestzj Subclasses should define self.root and self.paths (under that root) to be added to sys.path. Znamespace_pkgscs2fddjD_tjd_jdS)Ncsg|]}tjj|qSr)ospathjoinroot).0rselfrr =sz.NamespacePackageTest.setUp..)r)pathsZresolved_pathsrctx __enter__rrrr setUp<s  zNamespacePackageTest.setUpcCs|jddddS)N)r__exit__rrrr tearDownCszNamespacePackageTest.tearDownN) __name__ __module__ __qualname____doc__rrrdirname__file__rrrrrrr r5src@s*eZdZdgZddZddZddZdS) SingleNamespacePackageportion1cCsddl}||jjddSNrportion1 foo onefoo.one assertEqualoneattrrfoorrr test_simple_packageKsz*SingleNamespacePackage.test_simple_packagecCs6|tddl}Wdn1s(0YdSNr assertRaises ImportErrorfoo.twor.rrr test_cant_import_otherOs z-SingleNamespacePackage.test_cant_import_othercCsddl}|t|ddS)Nrz)r*r+reprr.rrr test_module_reprSsz'SingleNamespacePackage.test_module_reprN)rr r!rr0r6r8rrrr r%Hsr%c@seZdZdgZddZdS)DynamicPathNamespacePackager&cCs~ddl}||jjd|tddl}Wdn1s@0Ytj t j |j dddl}||j jddS)Nrr(portion2portion2 foo two)r*r+r,r-r3r4r5rrappendrrrtwor.rrr test_dynamic_path[s &z-DynamicPathNamespacePackage.test_dynamic_pathN)rr r!rr>rrrr r9Xsr9c@seZdZdgZddZdS)CombinedNamespacePackages both_portionscCs4ddl}ddl}||jjd||jjddSNrzboth_portions foo oneboth_portions foo twor*r5r+r,r-r=r.rrr test_importsnsz&CombinedNamespacePackages.test_importsNrr r!rrDrrrr r?ksr?c@seZdZddgZddZdS)SeparatedNamespacePackagesr&r:cCs4ddl}ddl}||jjd||jjddS)Nrr(r;rCr.rrr rDxsz'SeparatedNamespacePackages.test_importsNrErrrr rFusrFc@s,eZdZddgZddZddZddZd S) %SeparatedOverlappingNamespacePackagesr&r@cCs4ddl}ddl}||jjd||jjddSNrr(rBrCr.rrr test_first_path_winssz:SeparatedOverlappingNamespacePackages.test_first_path_winscCs>tjddl}ddl}||jjd||jjddSrA) rrreverser*r5r+r,r-r=r.rrr test_first_path_wins_agains  z@SeparatedOverlappingNamespacePackages.test_first_path_wins_againcCs4ddl}ddl}||jjd||jjddSrH)r5r*r+r,r-r=r.rrr +test_first_path_wins_importing_second_firstszQSeparatedOverlappingNamespacePackages.test_first_path_wins_importing_second_firstN)rr r!rrIrKrLrrrr rGsrGc@s"eZdZdgZddZddZdS)SingleZipNamespacePackagetop_level_portion1.zipcCsddl}||jjddSr'r)r.rrr r0sz-SingleZipNamespacePackage.test_simple_packagecCs6|tddl}Wdn1s(0YdSr1r2r.rrr r6s z0SingleZipNamespacePackage.test_cant_import_otherNrr r!rr0r6rrrr rMsrMc@seZdZddgZddZdS)SeparatedZipNamespacePackagesrNr:cCsTddl}ddl}||jjd||jjd|d|jj|d|jjdS)Nrr(r;rN.zip) r*r5r+r,r-r=assertInr$ assertNotInr.rrr rDs z*SeparatedZipNamespacePackages.test_importsNrErrrr rPsrPc@s"eZdZdgZddZddZdS)SingleNestedZipNamespacePackage#nested_portion1.zip/nested_portion1cCsddl}||jjddSr'r)r.rrr r0sz3SingleNestedZipNamespacePackage.test_simple_packagecCs6|tddl}Wdn1s(0YdSr1r2r.rrr r6s z6SingleNestedZipNamespacePackage.test_cant_import_otherNrOrrrr rTsrTc@seZdZddgZddZdS)#SeparatedNestedZipNamespacePackagesrUr:cCsbddl}ddl}||jjd||jjdtjdd}| ||jj | d|jj dS)Nrr(r;znested_portion1.zipZnested_portion1rQ) r*r5r+r,r-r=rrrrRr$rS)rr/fnrrr rDsz0SeparatedNestedZipNamespacePackages.test_importsNrErrrr rVsrVc@seZdZgdZddZdS) LegacySupport)Znot_a_namespace_pkgr&r:r@cCsbddl}|tddl}Wdn1s00Y|d|j|dt|j dS)Nr__init__ namespace) r*r3r4r5rRr$rSstr __loader__lowerr.rrr +test_non_namespace_package_takes_precedences  &z9LegacySupport.test_non_namespace_package_takes_precedenceN)rr r!rr^rrrr rXsrXc@s$eZdZddgZddZddZdS)DynamicPathCalculationZproject1Zproject2cCsddl}|t|jd|t|jjdddl}|t|jd|t|jjd||jjjd||jjjd| t ddl }Wdn1s0Y|t|jd|t|jjddS)Nrparent child oneparent child two) parent.child.oner+len__path__childparent.child.twor,r-r=r3r4parent.child.threerparentrrr test_project3_failss &z*DynamicPathCalculation.test_project3_failscCsddl}|t|jd|t|jjdddl}|t|jd|t|jjd||jjjd||jjjd| t ddl }Wdn1s0Yt j tj |jdddl }|t|jd|t|jjd||jjjddS)Nrr`rarbZproject3zparent child three)rcr+rdrerfrgr,r-r=r3r4rhrrr<rrrZthreerirrr test_project3_succeedss &z-DynamicPathCalculation.test_project3_succeedsN)rr r!rrkrmrrrr r_sr_c@s(eZdZdgZejddZddZdS)ZipWithMissingDirectoryzmissing_directory.zipcCs ddl}dSr1)r*r.rrr test_missing_directorysz.ZipWithMissingDirectory.test_missing_directorycCsddl}||jjddS)Nrzmissing_directory foo two)Zbar.twor+r=r-)rZbarrrr test_present_directorysz.ZipWithMissingDirectory.test_present_directoryN)rr r!runittestZexpectedFailurerorprrrr rns rnc@seZdZdgZddZdS)"ModuleAndNamespacePackageInSameDirZmodule_and_namespace_packagecCsddl}||jddS)Nrz in module)a_testr+r-)rrsrrr $test_module_before_namespace_packageszGModuleAndNamespacePackageInSameDir.test_module_before_namespace_packageN)rr r!rrtrrrr rrsrrc@s*eZdZdgZddZddZddZdS) ReloadTestsr&cCs&ddl}t|}||jjddSr')r* importlibreloadr+r,r-r.rrr r0%s zReloadTests.test_simple_packagecCszddl}|tddl}Wdn1s00Yt|}|tddl}Wdn1sl0YdSr1)r/r3r4r5rvrwr.rrr r6*s  &  z"ReloadTests.test_cant_import_othercCsxddl}|tddl}Wdn1s00Ytjtj|j dt |}ddl}| |j jddS)Nrr:r;)r*r3r4r5rrr<rrrrvrwr+r=r-r.rrr r>2s & zReloadTests.test_dynamic_pathN)rr r!rr0r6r>rrrr ru"sruc@s*eZdZdgZddZddZddZdS) LoaderTestsr&cCs*ddl}||j|jj||jdSr1)r/r+r\__spec__loaderZassertIsNotNoner.rrr !test_namespace_loader_consistencyCsz-LoaderTests.test_namespace_loader_consistencycCs&ddl}||jj||jdSr1)r/Z assertIsNoneryoriginr$r.rrr !test_namespace_origin_consistencyIsz-LoaderTests.test_namespace_origin_consistencycCs0ddl}tj|jdd}||jd|dS)Nrr&r/)r/rrrrr+re)rr/Z expected_pathrrr test_path_indexableOszLoaderTests.test_path_indexableN)rr r!rr{r}r~rrrr rx@srx__main__) contextlibrvrrrqZtest.test_importlibrcontextmanagerr rZTestCaserr%r9r?rFrGrMrPrTrVrXr_rnrrrurxrmainrrrr s6          -