| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							| 
									
										
										
										
											2021-05-02 17:03:40 -04:00
										 |  |  | import copy | 
					
						
							| 
									
										
										
										
											2023-12-21 15:04:05 -05:00
										 |  |  | import json | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | import shutil | 
					
						
							| 
									
										
										
										
											2020-04-15 13:55:43 -04:00
										 |  |  | import pathlib | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | import tempfile | 
					
						
							|  |  |  | import textwrap | 
					
						
							| 
									
										
										
										
											2022-06-25 21:04:28 -04:00
										 |  |  | import functools | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | import contextlib | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-20 17:11:00 -04:00
										 |  |  | from test.support import import_helper | 
					
						
							| 
									
										
										
										
											2024-03-20 23:01:24 -04:00
										 |  |  | from test.support import os_helper | 
					
						
							| 
									
										
										
										
											2021-12-16 15:49:42 -05:00
										 |  |  | from test.support import requires_zlib | 
					
						
							| 
									
										
										
										
											2023-04-20 22:12:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | from . import _path | 
					
						
							|  |  |  | from ._path import FilesSpec | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-19 14:14:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-16 15:49:42 -05:00
										 |  |  | try: | 
					
						
							| 
									
										
										
										
											2022-01-22 21:39:00 -05:00
										 |  |  |     from importlib import resources  # type: ignore | 
					
						
							| 
									
										
										
										
											2021-12-16 15:49:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     getattr(resources, 'files') | 
					
						
							|  |  |  |     getattr(resources, 'as_file') | 
					
						
							|  |  |  | except (ImportError, AttributeError): | 
					
						
							|  |  |  |     import importlib_resources as resources  # type: ignore | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | @contextlib.contextmanager | 
					
						
							|  |  |  | def tempdir(): | 
					
						
							|  |  |  |     tmpdir = tempfile.mkdtemp() | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         yield pathlib.Path(tmpdir) | 
					
						
							|  |  |  |     finally: | 
					
						
							|  |  |  |         shutil.rmtree(tmpdir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @contextlib.contextmanager | 
					
						
							|  |  |  | def save_cwd(): | 
					
						
							|  |  |  |     orig = os.getcwd() | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         yield | 
					
						
							|  |  |  |     finally: | 
					
						
							|  |  |  |         os.chdir(orig) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @contextlib.contextmanager | 
					
						
							|  |  |  | def tempdir_as_cwd(): | 
					
						
							|  |  |  |     with tempdir() as tmp: | 
					
						
							|  |  |  |         with save_cwd(): | 
					
						
							|  |  |  |             os.chdir(str(tmp)) | 
					
						
							|  |  |  |             yield tmp | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 21:58:47 -05:00
										 |  |  | @contextlib.contextmanager | 
					
						
							|  |  |  | def install_finder(finder): | 
					
						
							|  |  |  |     sys.meta_path.append(finder) | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         yield | 
					
						
							|  |  |  |     finally: | 
					
						
							|  |  |  |         sys.meta_path.remove(finder) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Fixtures: | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |     def setUp(self): | 
					
						
							| 
									
										
										
										
											2020-04-15 13:55:43 -04:00
										 |  |  |         self.fixtures = contextlib.ExitStack() | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |         self.addCleanup(self.fixtures.close) | 
					
						
							| 
									
										
										
										
											2020-02-11 21:58:47 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SiteDir(Fixtures): | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							| 
									
										
										
										
											2021-12-16 15:49:42 -05:00
										 |  |  |         super().setUp() | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |         self.site_dir = self.fixtures.enter_context(tempdir()) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 21:58:47 -05:00
										 |  |  | class OnSysPath(Fixtures): | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |     @staticmethod | 
					
						
							|  |  |  |     @contextlib.contextmanager | 
					
						
							|  |  |  |     def add_sys_path(dir): | 
					
						
							|  |  |  |         sys.path[:0] = [str(dir)] | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             yield | 
					
						
							|  |  |  |         finally: | 
					
						
							|  |  |  |             sys.path.remove(str(dir)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							| 
									
										
										
										
											2021-12-16 15:49:42 -05:00
										 |  |  |         super().setUp() | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |         self.fixtures.enter_context(self.add_sys_path(self.site_dir)) | 
					
						
							| 
									
										
										
										
											2024-03-20 17:11:00 -04:00
										 |  |  |         self.fixtures.enter_context(import_helper.isolated_modules()) | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 15:04:05 -05:00
										 |  |  | class SiteBuilder(SiteDir): | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							|  |  |  |         super().setUp() | 
					
						
							|  |  |  |         for cls in self.__class__.mro(): | 
					
						
							|  |  |  |             with contextlib.suppress(AttributeError): | 
					
						
							|  |  |  |                 build_files(cls.files, prefix=self.site_dir) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DistInfoPkg(OnSysPath, SiteBuilder): | 
					
						
							| 
									
										
										
										
											2023-04-20 22:12:48 -04:00
										 |  |  |     files: FilesSpec = { | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |         "distinfo_pkg-1.0.0.dist-info": { | 
					
						
							|  |  |  |             "METADATA": """
 | 
					
						
							|  |  |  |                 Name: distinfo-pkg | 
					
						
							|  |  |  |                 Author: Steven Ma | 
					
						
							|  |  |  |                 Version: 1.0.0 | 
					
						
							|  |  |  |                 Requires-Dist: wheel >= 1.0 | 
					
						
							|  |  |  |                 Requires-Dist: pytest; extra == 'test' | 
					
						
							| 
									
										
										
										
											2021-04-24 10:13:51 -04:00
										 |  |  |                 Keywords: sample package | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 Once upon a time | 
					
						
							|  |  |  |                 There was a distinfo pkg | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |                 """,
 | 
					
						
							|  |  |  |             "RECORD": "mod.py,sha256=abc,20\n", | 
					
						
							|  |  |  |             "entry_points.txt": """
 | 
					
						
							|  |  |  |                 [entries] | 
					
						
							|  |  |  |                 main = mod:main | 
					
						
							| 
									
										
										
										
											2019-07-28 14:59:24 -04:00
										 |  |  |                 ns:sub = mod:main | 
					
						
							| 
									
										
										
										
											2020-12-31 12:56:43 -05:00
										 |  |  |             """,
 | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |         "mod.py": """
 | 
					
						
							|  |  |  |             def main(): | 
					
						
							|  |  |  |                 print("hello world") | 
					
						
							|  |  |  |             """,
 | 
					
						
							| 
									
										
										
										
											2020-12-31 12:56:43 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-02 17:03:40 -04:00
										 |  |  |     def make_uppercase(self): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Rewrite metadata with everything uppercase. | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         shutil.rmtree(self.site_dir / "distinfo_pkg-1.0.0.dist-info") | 
					
						
							|  |  |  |         files = copy.deepcopy(DistInfoPkg.files) | 
					
						
							|  |  |  |         info = files["distinfo_pkg-1.0.0.dist-info"] | 
					
						
							|  |  |  |         info["METADATA"] = info["METADATA"].upper() | 
					
						
							|  |  |  |         build_files(files, self.site_dir) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 15:04:05 -05:00
										 |  |  | class DistInfoPkgEditable(DistInfoPkg): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Package with a PEP 660 direct_url.json. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     some_hash = '524127ce937f7cb65665130c695abd18ca386f60bb29687efb976faa1596fdcc' | 
					
						
							|  |  |  |     files: FilesSpec = { | 
					
						
							|  |  |  |         'distinfo_pkg-1.0.0.dist-info': { | 
					
						
							| 
									
										
										
										
											2024-03-20 23:01:24 -04:00
										 |  |  |             'direct_url.json': json.dumps({ | 
					
						
							|  |  |  |                 "archive_info": { | 
					
						
							|  |  |  |                     "hash": f"sha256={some_hash}", | 
					
						
							|  |  |  |                     "hashes": {"sha256": f"{some_hash}"}, | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 "url": "file:///path/to/distinfo_pkg-1.0.0.editable-py3-none-any.whl", | 
					
						
							|  |  |  |             }) | 
					
						
							| 
									
										
										
										
											2023-12-21 15:04:05 -05:00
										 |  |  |         }, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DistInfoPkgWithDot(OnSysPath, SiteBuilder): | 
					
						
							| 
									
										
										
										
											2023-04-20 22:12:48 -04:00
										 |  |  |     files: FilesSpec = { | 
					
						
							| 
									
										
										
										
											2020-12-31 12:56:43 -05:00
										 |  |  |         "pkg_dot-1.0.0.dist-info": { | 
					
						
							|  |  |  |             "METADATA": """
 | 
					
						
							|  |  |  |                 Name: pkg.dot | 
					
						
							|  |  |  |                 Version: 1.0.0 | 
					
						
							|  |  |  |                 """,
 | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 15:04:05 -05:00
										 |  |  | class DistInfoPkgWithDotLegacy(OnSysPath, SiteBuilder): | 
					
						
							| 
									
										
										
										
											2023-04-20 22:12:48 -04:00
										 |  |  |     files: FilesSpec = { | 
					
						
							| 
									
										
										
										
											2020-12-31 12:56:43 -05:00
										 |  |  |         "pkg.dot-1.0.0.dist-info": { | 
					
						
							|  |  |  |             "METADATA": """
 | 
					
						
							|  |  |  |                 Name: pkg.dot | 
					
						
							|  |  |  |                 Version: 1.0.0 | 
					
						
							|  |  |  |                 """,
 | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         "pkg.lot.egg-info": { | 
					
						
							|  |  |  |             "METADATA": """
 | 
					
						
							|  |  |  |                 Name: pkg.lot | 
					
						
							|  |  |  |                 Version: 1.0.0 | 
					
						
							|  |  |  |                 """,
 | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 15:04:05 -05:00
										 |  |  | class DistInfoPkgOffPath(SiteBuilder): | 
					
						
							|  |  |  |     files = DistInfoPkg.files | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 15:04:05 -05:00
										 |  |  | class EggInfoPkg(OnSysPath, SiteBuilder): | 
					
						
							| 
									
										
										
										
											2023-04-20 22:12:48 -04:00
										 |  |  |     files: FilesSpec = { | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |         "egginfo_pkg.egg-info": { | 
					
						
							|  |  |  |             "PKG-INFO": """
 | 
					
						
							|  |  |  |                 Name: egginfo-pkg | 
					
						
							|  |  |  |                 Author: Steven Ma | 
					
						
							|  |  |  |                 License: Unknown | 
					
						
							|  |  |  |                 Version: 1.0.0 | 
					
						
							|  |  |  |                 Classifier: Intended Audience :: Developers | 
					
						
							|  |  |  |                 Classifier: Topic :: Software Development :: Libraries | 
					
						
							| 
									
										
										
										
											2021-04-24 10:13:51 -04:00
										 |  |  |                 Keywords: sample package | 
					
						
							|  |  |  |                 Description: Once upon a time | 
					
						
							|  |  |  |                         There was an egginfo package | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |                 """,
 | 
					
						
							|  |  |  |             "SOURCES.txt": """
 | 
					
						
							|  |  |  |                 mod.py | 
					
						
							|  |  |  |                 egginfo_pkg.egg-info/top_level.txt | 
					
						
							|  |  |  |             """,
 | 
					
						
							|  |  |  |             "entry_points.txt": """
 | 
					
						
							|  |  |  |                 [entries] | 
					
						
							|  |  |  |                 main = mod:main | 
					
						
							|  |  |  |             """,
 | 
					
						
							|  |  |  |             "requires.txt": """
 | 
					
						
							|  |  |  |                 wheel >= 1.0; python_version >= "2.7" | 
					
						
							|  |  |  |                 [test] | 
					
						
							|  |  |  |                 pytest | 
					
						
							|  |  |  |             """,
 | 
					
						
							| 
									
										
										
										
											2020-12-31 12:56:43 -05:00
										 |  |  |             "top_level.txt": "mod\n", | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |         "mod.py": """
 | 
					
						
							|  |  |  |             def main(): | 
					
						
							|  |  |  |                 print("hello world") | 
					
						
							|  |  |  |             """,
 | 
					
						
							| 
									
										
										
										
											2020-12-31 12:56:43 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 15:04:05 -05:00
										 |  |  | class EggInfoPkgPipInstalledNoToplevel(OnSysPath, SiteBuilder): | 
					
						
							| 
									
										
										
										
											2023-04-20 22:12:48 -04:00
										 |  |  |     files: FilesSpec = { | 
					
						
							|  |  |  |         "egg_with_module_pkg.egg-info": { | 
					
						
							|  |  |  |             "PKG-INFO": "Name: egg_with_module-pkg", | 
					
						
							|  |  |  |             # SOURCES.txt is made from the source archive, and contains files | 
					
						
							|  |  |  |             # (setup.py) that are not present after installation. | 
					
						
							|  |  |  |             "SOURCES.txt": """
 | 
					
						
							|  |  |  |                 egg_with_module.py | 
					
						
							|  |  |  |                 setup.py | 
					
						
							|  |  |  |                 egg_with_module_pkg.egg-info/PKG-INFO | 
					
						
							|  |  |  |                 egg_with_module_pkg.egg-info/SOURCES.txt | 
					
						
							|  |  |  |                 egg_with_module_pkg.egg-info/top_level.txt | 
					
						
							|  |  |  |             """,
 | 
					
						
							|  |  |  |             # installed-files.txt is written by pip, and is a strictly more | 
					
						
							|  |  |  |             # accurate source than SOURCES.txt as to the installed contents of | 
					
						
							|  |  |  |             # the package. | 
					
						
							|  |  |  |             "installed-files.txt": """
 | 
					
						
							|  |  |  |                 ../egg_with_module.py | 
					
						
							|  |  |  |                 PKG-INFO | 
					
						
							|  |  |  |                 SOURCES.txt | 
					
						
							|  |  |  |                 top_level.txt | 
					
						
							|  |  |  |             """,
 | 
					
						
							|  |  |  |             # missing top_level.txt (to trigger fallback to installed-files.txt) | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         "egg_with_module.py": """
 | 
					
						
							|  |  |  |             def main(): | 
					
						
							|  |  |  |                 print("hello world") | 
					
						
							|  |  |  |             """,
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 15:04:05 -05:00
										 |  |  | class EggInfoPkgPipInstalledNoModules(OnSysPath, SiteBuilder): | 
					
						
							| 
									
										
										
										
											2023-04-20 22:12:48 -04:00
										 |  |  |     files: FilesSpec = { | 
					
						
							|  |  |  |         "egg_with_no_modules_pkg.egg-info": { | 
					
						
							|  |  |  |             "PKG-INFO": "Name: egg_with_no_modules-pkg", | 
					
						
							|  |  |  |             # SOURCES.txt is made from the source archive, and contains files | 
					
						
							|  |  |  |             # (setup.py) that are not present after installation. | 
					
						
							|  |  |  |             "SOURCES.txt": """
 | 
					
						
							|  |  |  |                 setup.py | 
					
						
							|  |  |  |                 egg_with_no_modules_pkg.egg-info/PKG-INFO | 
					
						
							|  |  |  |                 egg_with_no_modules_pkg.egg-info/SOURCES.txt | 
					
						
							|  |  |  |                 egg_with_no_modules_pkg.egg-info/top_level.txt | 
					
						
							|  |  |  |             """,
 | 
					
						
							|  |  |  |             # installed-files.txt is written by pip, and is a strictly more | 
					
						
							|  |  |  |             # accurate source than SOURCES.txt as to the installed contents of | 
					
						
							|  |  |  |             # the package. | 
					
						
							|  |  |  |             "installed-files.txt": """
 | 
					
						
							|  |  |  |                 PKG-INFO | 
					
						
							|  |  |  |                 SOURCES.txt | 
					
						
							|  |  |  |                 top_level.txt | 
					
						
							|  |  |  |             """,
 | 
					
						
							|  |  |  |             # top_level.txt correctly reflects that no modules are installed | 
					
						
							|  |  |  |             "top_level.txt": b"\n", | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 15:04:05 -05:00
										 |  |  | class EggInfoPkgSourcesFallback(OnSysPath, SiteBuilder): | 
					
						
							| 
									
										
										
										
											2023-04-20 22:12:48 -04:00
										 |  |  |     files: FilesSpec = { | 
					
						
							|  |  |  |         "sources_fallback_pkg.egg-info": { | 
					
						
							|  |  |  |             "PKG-INFO": "Name: sources_fallback-pkg", | 
					
						
							|  |  |  |             # SOURCES.txt is made from the source archive, and contains files | 
					
						
							|  |  |  |             # (setup.py) that are not present after installation. | 
					
						
							|  |  |  |             "SOURCES.txt": """
 | 
					
						
							|  |  |  |                 sources_fallback.py | 
					
						
							|  |  |  |                 setup.py | 
					
						
							|  |  |  |                 sources_fallback_pkg.egg-info/PKG-INFO | 
					
						
							|  |  |  |                 sources_fallback_pkg.egg-info/SOURCES.txt | 
					
						
							|  |  |  |             """,
 | 
					
						
							|  |  |  |             # missing installed-files.txt (i.e. not installed by pip) and | 
					
						
							|  |  |  |             # missing top_level.txt (to trigger fallback to SOURCES.txt) | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         "sources_fallback.py": """
 | 
					
						
							|  |  |  |             def main(): | 
					
						
							|  |  |  |                 print("hello world") | 
					
						
							|  |  |  |             """,
 | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-21 15:04:05 -05:00
										 |  |  | class EggInfoFile(OnSysPath, SiteBuilder): | 
					
						
							| 
									
										
										
										
											2023-04-20 22:12:48 -04:00
										 |  |  |     files: FilesSpec = { | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  |         "egginfo_file.egg-info": """
 | 
					
						
							|  |  |  |             Metadata-Version: 1.0 | 
					
						
							|  |  |  |             Name: egginfo_file | 
					
						
							|  |  |  |             Version: 0.1 | 
					
						
							|  |  |  |             Summary: An example package | 
					
						
							|  |  |  |             Home-page: www.example.com | 
					
						
							|  |  |  |             Author: Eric Haffa-Vee | 
					
						
							|  |  |  |             Author-email: eric@example.coms | 
					
						
							|  |  |  |             License: UNKNOWN | 
					
						
							|  |  |  |             Description: UNKNOWN | 
					
						
							|  |  |  |             Platform: UNKNOWN | 
					
						
							|  |  |  |             """,
 | 
					
						
							| 
									
										
										
										
											2020-12-31 12:56:43 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-20 22:12:48 -04:00
										 |  |  | # dedent all text strings before writing | 
					
						
							|  |  |  | orig = _path.create.registry[str] | 
					
						
							|  |  |  | _path.create.register(str, lambda content, path: orig(DALS(content), path)) | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-20 22:12:48 -04:00
										 |  |  | build_files = _path.build | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-20 22:12:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | def build_record(file_defs): | 
					
						
							|  |  |  |     return ''.join(f'{name},,\n' for name in record_names(file_defs)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def record_names(file_defs): | 
					
						
							|  |  |  |     recording = _path.Recording() | 
					
						
							|  |  |  |     _path.build(file_defs, recording) | 
					
						
							|  |  |  |     return recording.record | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-07 10:57:45 -04:00
										 |  |  | class FileBuilder: | 
					
						
							|  |  |  |     def unicode_filename(self): | 
					
						
							| 
									
										
										
										
											2024-03-20 23:01:24 -04:00
										 |  |  |         return os_helper.FS_NONASCII or self.skip( | 
					
						
							|  |  |  |             "File system does not support non-ascii." | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2020-06-07 10:57:45 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-24 19:59:01 -04:00
										 |  |  | def DALS(str): | 
					
						
							|  |  |  |     "Dedent and left-strip" | 
					
						
							|  |  |  |     return textwrap.dedent(str).lstrip() | 
					
						
							| 
									
										
										
										
											2020-02-11 21:58:47 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-16 15:49:42 -05:00
										 |  |  | @requires_zlib() | 
					
						
							|  |  |  | class ZipFixtures: | 
					
						
							| 
									
										
										
										
											2024-03-20 17:11:00 -04:00
										 |  |  |     root = 'test.test_importlib.metadata.data' | 
					
						
							| 
									
										
										
										
											2021-12-16 15:49:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def _fixture_on_path(self, filename): | 
					
						
							|  |  |  |         pkg_file = resources.files(self.root).joinpath(filename) | 
					
						
							|  |  |  |         file = self.resources.enter_context(resources.as_file(pkg_file)) | 
					
						
							|  |  |  |         assert file.name.startswith('example'), file.name | 
					
						
							|  |  |  |         sys.path.insert(0, str(file)) | 
					
						
							|  |  |  |         self.resources.callback(sys.path.pop, 0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def setUp(self): | 
					
						
							|  |  |  |         # Add self.zip_name to the front of sys.path. | 
					
						
							|  |  |  |         self.resources = contextlib.ExitStack() | 
					
						
							|  |  |  |         self.addCleanup(self.resources.close) | 
					
						
							| 
									
										
										
										
											2022-06-25 21:04:28 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def parameterize(*args_set): | 
					
						
							|  |  |  |     """Run test method with a series of parameters.""" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def wrapper(func): | 
					
						
							|  |  |  |         @functools.wraps(func) | 
					
						
							|  |  |  |         def _inner(self): | 
					
						
							|  |  |  |             for args in args_set: | 
					
						
							|  |  |  |                 with self.subTest(**args): | 
					
						
							|  |  |  |                     func(self, **args) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return _inner | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return wrapper |