diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-06-05 20:34:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-05 20:34:16 (GMT) |
commit | 161541ab45278df6603dd870113b10f13e4d9e16 (patch) | |
tree | 53d4dd1133a5912092faf71918550202864f2475 /Lib/test/test_importlib | |
parent | 5fe1df1886e2e53b04bf76ef916857271d3c8f20 (diff) | |
download | cpython-161541ab45278df6603dd870113b10f13e4d9e16.zip cpython-161541ab45278df6603dd870113b10f13e4d9e16.tar.gz cpython-161541ab45278df6603dd870113b10f13e4d9e16.tar.bz2 |
bpo-39791: Refresh importlib.metadata from importlib_metadata 1.6.1. (GH-20659)
* Refresh importlib.metadata from importlib_metadata 1.6.1.
* 📜🤖 Added by blurb_it.
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_importlib')
-rw-r--r-- | Lib/test/test_importlib/fixtures.py | 15 | ||||
-rw-r--r-- | Lib/test/test_importlib/test_main.py | 16 | ||||
-rw-r--r-- | Lib/test/test_importlib/test_zip.py | 26 |
3 files changed, 47 insertions, 10 deletions
diff --git a/Lib/test/test_importlib/fixtures.py b/Lib/test/test_importlib/fixtures.py index d923cec..b25febb 100644 --- a/Lib/test/test_importlib/fixtures.py +++ b/Lib/test/test_importlib/fixtures.py @@ -161,6 +161,21 @@ class EggInfoFile(OnSysPath, SiteDir): build_files(EggInfoFile.files, prefix=self.site_dir) +class LocalPackage: + files = { + "setup.py": """ + import setuptools + setuptools.setup(name="local-pkg", version="2.0.1") + """, + } + + def setUp(self): + self.fixtures = contextlib.ExitStack() + self.addCleanup(self.fixtures.close) + self.fixtures.enter_context(tempdir_as_cwd()) + build_files(self.files) + + def build_files(file_defs, prefix=pathlib.Path()): """Build a set of files/directories, as described by the diff --git a/Lib/test/test_importlib/test_main.py b/Lib/test/test_importlib/test_main.py index 42a7999..7b18c3d 100644 --- a/Lib/test/test_importlib/test_main.py +++ b/Lib/test/test_importlib/test_main.py @@ -246,3 +246,19 @@ class TestEntryPoints(unittest.TestCase): """ with self.assertRaises(Exception): json.dumps(self.ep) + + def test_module(self): + assert self.ep.module == 'value' + + def test_attr(self): + assert self.ep.attr is None + + +class FileSystem(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase): + def test_unicode_dir_on_sys_path(self): + """ + Ensure a Unicode subdirectory of a directory on sys.path + does not crash. + """ + fixtures.build_files({'☃': {}}, prefix=self.site_dir) + list(distributions()) diff --git a/Lib/test/test_importlib/test_zip.py b/Lib/test/test_importlib/test_zip.py index fa87cd7..a5399c1 100644 --- a/Lib/test/test_importlib/test_zip.py +++ b/Lib/test/test_importlib/test_zip.py @@ -3,9 +3,10 @@ import unittest from contextlib import ExitStack from importlib.metadata import ( - distribution, entry_points, files, PackageNotFoundError, version, + distribution, entry_points, files, PackageNotFoundError, + version, distributions, ) -from importlib.resources import path +from importlib import resources from test.support import requires_zlib @@ -14,15 +15,19 @@ from test.support import requires_zlib class TestZip(unittest.TestCase): root = 'test.test_importlib.data' + 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): # Find the path to the example-*.whl so we can add it to the front of # sys.path, where we'll then try to find the metadata thereof. self.resources = ExitStack() self.addCleanup(self.resources.close) - wheel = self.resources.enter_context( - path(self.root, 'example-21.12-py3-none-any.whl')) - sys.path.insert(0, str(wheel)) - self.resources.callback(sys.path.pop, 0) + self._fixture_on_path('example-21.12-py3-none-any.whl') def test_zip_version(self): self.assertEqual(version('example'), '21.12') @@ -49,6 +54,10 @@ class TestZip(unittest.TestCase): path = str(file.dist.locate_file(file)) assert '.whl/' in path, path + def test_one_distribution(self): + dists = list(distributions(path=sys.path[:1])) + assert len(dists) == 1 + @requires_zlib() class TestEgg(TestZip): @@ -57,10 +66,7 @@ class TestEgg(TestZip): # sys.path, where we'll then try to find the metadata thereof. self.resources = ExitStack() self.addCleanup(self.resources.close) - egg = self.resources.enter_context( - path(self.root, 'example-21.12-py3.6.egg')) - sys.path.insert(0, str(egg)) - self.resources.callback(sys.path.pop, 0) + self._fixture_on_path('example-21.12-py3.6.egg') def test_files(self): for file in files('example'): |