summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib/test_zip.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_importlib/test_zip.py')
-rw-r--r--Lib/test/test_importlib/test_zip.py26
1 files changed, 16 insertions, 10 deletions
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'):