diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2019-05-24 19:59:01 -0400 |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2019-05-24 16:59:01 -0700 |
commit | 1bbf7b661f0ac8aac12d5531928d9a85c98ec1a9 (patch) | |
tree | c0c36b2d2756929655da47e4843188363886fce5 /Lib/test/test_importlib/test_zip.py | |
parent | 6dbbe748e101a173b4cff8aada41e9313e287e0f (diff) | |
download | cpython-1bbf7b661f0ac8aac12d5531928d9a85c98ec1a9.tar.gz cpython-1bbf7b661f0ac8aac12d5531928d9a85c98ec1a9.zip |
bpo-34632: Add importlib.metadata (GH-12547)
Add importlib.metadata module as forward port of the standalone importlib_metadata.
Diffstat (limited to 'Lib/test/test_importlib/test_zip.py')
-rw-r--r-- | Lib/test/test_importlib/test_zip.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Lib/test/test_importlib/test_zip.py b/Lib/test/test_importlib/test_zip.py new file mode 100644 index 00000000000..db39e190ea7 --- /dev/null +++ b/Lib/test/test_importlib/test_zip.py @@ -0,0 +1,56 @@ +import sys +import unittest + +from contextlib import ExitStack +from importlib.metadata import distribution, entry_points, files, version +from importlib.resources import path + + +class TestZip(unittest.TestCase): + root = 'test.test_importlib.data' + + 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) + + def test_zip_version(self): + self.assertEqual(version('example'), '21.12') + + def test_zip_entry_points(self): + scripts = dict(entry_points()['console_scripts']) + entry_point = scripts['example'] + self.assertEqual(entry_point.value, 'example:main') + + def test_missing_metadata(self): + self.assertIsNone(distribution('example').read_text('does not exist')) + + def test_case_insensitive(self): + self.assertEqual(version('Example'), '21.12') + + def test_files(self): + for file in files('example'): + path = str(file.dist.locate_file(file)) + assert '.whl/' in path, path + + +class TestEgg(TestZip): + def setUp(self): + # Find the path to the example-*.egg 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) + 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) + + def test_files(self): + for file in files('example'): + path = str(file.dist.locate_file(file)) + assert '.egg/' in path, path |