a 7źdgE*ć@shddlZddlZddlZddlZddlZddlmZejdd„ƒZejdd„ƒZ Gdd„dej ƒZ Gd d „d e ƒZ Gd d „d e ƒZ Gd d„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd „d e ƒZGd!d"„d"e ƒZGd#d$„d$e ƒZGd%d&„d&e ƒZed'krde ”dS)(éN)Śutilc csZtj}tj ”}z&dVW|t_tj ”tj |”n|t_tj ”tj |”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)ŚsysŚmodulesŚcopyŚclearŚupdate)Zsys_modules_savedZsys_modules_copy©rśC/usr/local/lib/python3.9/test/test_importlib/test_namespace_pkgs.pyŚsys_modules_contexts   ž r c ks€| dtj”| dtj”tjfi|¤Ž}|<tƒdVWdƒn1sT0YWdƒn1sr0YdS)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@s6eZdZdZej ej e”d”Z dd„Z dd„Z dS)ŚNamespacePackageTestzj Subclasses should define self.root and self.paths (under that root) to be added to sys.path. Znamespace_pkgscs2‡fdd„ˆjDƒˆ_tˆjdˆ_ˆj ”dS)Ncsg|]}tj ˆj|”‘qSr)ŚosŚpathŚjoinŚroot)Ś.0r©Śselfrr Ś =sz.NamespacePackageTest.setUp..)r)ŚpathsZresolved_pathsrŚctxŚ __enter__rrrr ŚsetUp<s  ’zNamespacePackageTest.setUpcCs|j ddd”dS)N)rŚ__exit__rrrr ŚtearDownCszNamespacePackageTest.tearDownN) Ś__name__Ś __module__Ś __qualname__Ś__doc__rrrŚdirnameŚ__file__rrrrrrr r5src@s*eZdZdgZdd„Zdd„Zdd„ZdS) ŚSingleNamespacePackageŚportion1cCsddl}| |jjd”dS©Nrśportion1 foo one©Śfoo.oneŚ assertEqualŚoneŚattr©rŚfoorrr Śtest_simple_packageKsz*SingleNamespacePackage.test_simple_packagecCs6| t”ddl}Wdƒn1s(0YdS©Nr©Ś assertRaisesŚ ImportErrorŚfoo.twor.rrr Śtest_cant_import_otherOs z-SingleNamespacePackage.test_cant_import_othercCsddl}| t|ƒd”dS)Nrz)r*r+Śreprr.rrr Śtest_module_reprSsz'SingleNamespacePackage.test_module_reprN)rr r!rr0r6r8rrrr r%Hsr%c@seZdZdgZdd„ZdS)ŚDynamicPathNamespacePackager&cCs~ddl}| |jjd”| t”ddl}Wdƒn1s@0Ytj  t j  |j d””ddl}| |j jd”dS)Nrr(Śportion2śportion2 foo two)r*r+r,r-r3r4r5rrŚappendrrrŚtwor.rrr Śtest_dynamic_path[s &z-DynamicPathNamespacePackage.test_dynamic_pathN)rr r!rr>rrrr r9Xsr9c@seZdZdgZdd„ZdS)ŚCombinedNamespacePackagesŚ both_portionscCs4ddl}ddl}| |jjd”| |jjd”dS©Nrzboth_portions foo oneśboth_portions foo two©r*r5r+r,r-r=r.rrr Ś test_importsnsz&CombinedNamespacePackages.test_importsN©rr r!rrDrrrr r?ksr?c@seZdZddgZdd„ZdS)ŚSeparatedNamespacePackagesr&r:cCs4ddl}ddl}| |jjd”| |jjd”dS)Nrr(r;rCr.rrr rDxsz'SeparatedNamespacePackages.test_importsNrErrrr rFusrFc@s,eZdZddgZdd„Zdd„Zdd„Zd S) Ś%SeparatedOverlappingNamespacePackagesr&r@cCs4ddl}ddl}| |jjd”| |jjd”dS©Nrr(rBrCr.rrr Śtest_first_path_wins‚sz:SeparatedOverlappingNamespacePackages.test_first_path_winscCs>tj ”ddl}ddl}| |jjd”| |jjd”dSrA) rrŚreverser*r5r+r,r-r=r.rrr Śtest_first_path_wins_againˆs  z@SeparatedOverlappingNamespacePackages.test_first_path_wins_againcCs4ddl}ddl}| |jjd”| |jjd”dSrH)r5r*r+r,r-r=r.rrr Ś+test_first_path_wins_importing_second_firstszQSeparatedOverlappingNamespacePackages.test_first_path_wins_importing_second_firstN)rr r!rrIrKrLrrrr rGsrGc@s"eZdZdgZdd„Zdd„ZdS)ŚSingleZipNamespacePackageśtop_level_portion1.zipcCsddl}| |jjd”dSr'r)r.rrr r0™sz-SingleZipNamespacePackage.test_simple_packagecCs6| t”ddl}Wdƒn1s(0YdSr1r2r.rrr r6s z0SingleZipNamespacePackage.test_cant_import_otherN©rr r!rr0r6rrrr rM–srMc@seZdZddgZdd„ZdS)ŚSeparatedZipNamespacePackagesrNr:cCsTddl}ddl}| |jjd”| |jjd”| d|jj”| d|jj”dS)Nrr(r;rNś.zip) r*r5r+r,r-r=ŚassertInr$Ś assertNotInr.rrr rD„s z*SeparatedZipNamespacePackages.test_importsNrErrrr rP¢srPc@s"eZdZdgZdd„Zdd„ZdS)ŚSingleNestedZipNamespacePackageś#nested_portion1.zip/nested_portion1cCsddl}| |jjd”dSr'r)r.rrr r0±sz3SingleNestedZipNamespacePackage.test_simple_packagecCs6| t”ddl}Wdƒn1s(0YdSr1r2r.rrr r6µs z6SingleNestedZipNamespacePackage.test_cant_import_otherNrOrrrr rT®srTc@seZdZddgZdd„ZdS)Ś#SeparatedNestedZipNamespacePackagesrUr:cCsbddl}ddl}| |jjd”| |jjd”tj dd”}|  ||jj ”|  d|jj ”dS)Nrr(r;znested_portion1.zipZnested_portion1rQ) r*r5r+r,r-r=rrrrRr$rS)rr/Śfnrrr rD½sz0SeparatedNestedZipNamespacePackages.test_importsNrErrrr rVŗsrVc@seZdZgd¢Zdd„ZdS)Ś LegacySupport)Znot_a_namespace_pkgr&r:r@cCsbddl}| t”ddl}Wdƒn1s00Y| d|j”| dt|jƒ  ””dS)NrŚ__init__Ś namespace) r*r3r4r5rRr$rSŚstrŚ __loader__Ślowerr.rrr Ś+test_non_namespace_package_takes_precedenceŹs  &z9LegacySupport.test_non_namespace_package_takes_precedenceN)rr r!rr^rrrr rXĒsrXc@s$eZdZddgZdd„Zdd„ZdS)ŚDynamicPathCalculationZproject1Zproject2cCsÜddl}| t|jƒd”| t|jjƒd”ddl}| t|jƒd”| t|jjƒd”| |jjjd”| |jjjd”|  t ”ddl }Wdƒn1sØ0Y| t|jƒd”| t|jjƒd”dS)Nréśparent child oneśparent child two) Śparent.child.oner+ŚlenŚ__path__ŚchildŚparent.child.twor,r-r=r3r4Śparent.child.three©rŚparentrrr Śtest_project3_failsÕs &z*DynamicPathCalculation.test_project3_failscCsddl}| t|jƒd”| t|jjƒd”ddl}| t|jƒd”| t|jjƒd”| |jjjd”| |jjjd”|  t ”ddl }Wdƒn1sØ0Yt j  tj  |jd””ddl }| t|jƒd”| t|jjƒd”| |jjjd”dS)Nrr`rarbZproject3ézparent child three)rcr+rdrerfrgr,r-r=r3r4rhrrr<rrrZthreerirrr Śtest_project3_succeedsęs &z-DynamicPathCalculation.test_project3_succeedsN)rr r!rrkrmrrrr r_Ņsr_c@s(eZdZdgZejdd„ƒZdd„ZdS)ŚZipWithMissingDirectoryzmissing_directory.zipcCs ddl}dSr1)r*r.rrr Śtest_missing_directorysz.ZipWithMissingDirectory.test_missing_directorycCsddl}| |jjd”dS)Nrzmissing_directory foo two)Zbar.twor+r=r-)rZbarrrr Śtest_present_directorysz.ZipWithMissingDirectory.test_present_directoryN)rr r!rŚunittestZexpectedFailurerorprrrr rn’s rnc@seZdZdgZdd„ZdS)Ś"ModuleAndNamespacePackageInSameDirZmodule_and_namespace_packagecCsddl}| |jd”dS)Nrz in module)Śa_testr+r-)rrsrrr Ś$test_module_before_namespace_packageszGModuleAndNamespacePackageInSameDir.test_module_before_namespace_packageN)rr r!rrtrrrr rrsrrc@s*eZdZdgZdd„Zdd„Zdd„ZdS) Ś ReloadTestsr&cCs&ddl}t |”}| |jjd”dSr')r*Ś importlibŚreloadr+r,r-r.rrr r0%s zReloadTests.test_simple_packagecCszddl}| t”ddl}Wdƒn1s00Yt |”}| t”ddl}Wdƒn1sl0YdSr1)r/r3r4r5rvrwr.rrr r6*s  &  z"ReloadTests.test_cant_import_othercCsxddl}| t”ddl}Wdƒn1s00Ytj tj |j d””t   |”}ddl}|  |j jd”dS)Nrr:r;)r*r3r4r5rrr<rrrrvrwr+r=r-r.rrr r>2s & zReloadTests.test_dynamic_pathN)rr r!rr0r6r>rrrr ru"sruc@s*eZdZdgZdd„Zdd„Zdd„ZdS) Ś LoaderTestsr&cCs*ddl}| |j|jj”| |j”dSr1)r/r+r\Ś__spec__ŚloaderZassertIsNotNoner.rrr Ś!test_namespace_loader_consistencyCsz-LoaderTests.test_namespace_loader_consistencycCs&ddl}| |jj”| |j”dSr1)r/Z assertIsNoneryŚoriginr$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_importlibrŚcontextmanagerr rZTestCaserr%r9r?rFrGrMrPrTrVrXr_rnrrrurxrŚmainrrrr Śs6          -