summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_importlib/test_metadata_api.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2023-04-21 02:12:48 (GMT)
committerGitHub <noreply@github.com>2023-04-21 02:12:48 (GMT)
commit3e0fec7e07a71bdeeab7554e980110fbc47763b9 (patch)
treec95fc47a9ee48d5606f4eb6cc45703f7be568769 /Lib/test/test_importlib/test_metadata_api.py
parent5c00a6224d55f8818ef567b93f484b5429e2ae80 (diff)
downloadcpython-3e0fec7e07a71bdeeab7554e980110fbc47763b9.zip
cpython-3e0fec7e07a71bdeeab7554e980110fbc47763b9.tar.gz
cpython-3e0fec7e07a71bdeeab7554e980110fbc47763b9.tar.bz2
Sync with importlib_metadata 6.5 (GH-103584)
Diffstat (limited to 'Lib/test/test_importlib/test_metadata_api.py')
-rw-r--r--Lib/test/test_importlib/test_metadata_api.py56
1 files changed, 48 insertions, 8 deletions
diff --git a/Lib/test/test_importlib/test_metadata_api.py b/Lib/test/test_importlib/test_metadata_api.py
index 71c47e6..33c6e85 100644
--- a/Lib/test/test_importlib/test_metadata_api.py
+++ b/Lib/test/test_importlib/test_metadata_api.py
@@ -27,12 +27,14 @@ def suppress_known_deprecation():
class APITests(
fixtures.EggInfoPkg,
+ fixtures.EggInfoPkgPipInstalledNoToplevel,
+ fixtures.EggInfoPkgPipInstalledNoModules,
+ fixtures.EggInfoPkgSourcesFallback,
fixtures.DistInfoPkg,
fixtures.DistInfoPkgWithDot,
fixtures.EggInfoFile,
unittest.TestCase,
):
-
version_pattern = r'\d+\.\d+(\.\d)?'
def test_retrieves_version_of_self(self):
@@ -63,15 +65,28 @@ class APITests(
distribution(prefix)
def test_for_top_level(self):
- self.assertEqual(
- distribution('egginfo-pkg').read_text('top_level.txt').strip(), 'mod'
- )
+ tests = [
+ ('egginfo-pkg', 'mod'),
+ ('egg_with_no_modules-pkg', ''),
+ ]
+ for pkg_name, expect_content in tests:
+ with self.subTest(pkg_name):
+ self.assertEqual(
+ distribution(pkg_name).read_text('top_level.txt').strip(),
+ expect_content,
+ )
def test_read_text(self):
- top_level = [
- path for path in files('egginfo-pkg') if path.name == 'top_level.txt'
- ][0]
- self.assertEqual(top_level.read_text(), 'mod\n')
+ tests = [
+ ('egginfo-pkg', 'mod\n'),
+ ('egg_with_no_modules-pkg', '\n'),
+ ]
+ for pkg_name, expect_content in tests:
+ with self.subTest(pkg_name):
+ top_level = [
+ path for path in files(pkg_name) if path.name == 'top_level.txt'
+ ][0]
+ self.assertEqual(top_level.read_text(), expect_content)
def test_entry_points(self):
eps = entry_points()
@@ -137,6 +152,28 @@ class APITests(
classifiers = md.get_all('Classifier')
assert 'Topic :: Software Development :: Libraries' in classifiers
+ def test_missing_key_legacy(self):
+ """
+ Requesting a missing key will still return None, but warn.
+ """
+ md = metadata('distinfo-pkg')
+ with suppress_known_deprecation():
+ assert md['does-not-exist'] is None
+
+ def test_get_key(self):
+ """
+ Getting a key gets the key.
+ """
+ md = metadata('egginfo-pkg')
+ assert md.get('Name') == 'egginfo-pkg'
+
+ def test_get_missing_key(self):
+ """
+ Requesting a missing key will return None.
+ """
+ md = metadata('distinfo-pkg')
+ assert md.get('does-not-exist') is None
+
@staticmethod
def _test_files(files):
root = files[0].root
@@ -159,6 +196,9 @@ class APITests(
def test_files_egg_info(self):
self._test_files(files('egginfo-pkg'))
+ self._test_files(files('egg_with_module-pkg'))
+ self._test_files(files('egg_with_no_modules-pkg'))
+ self._test_files(files('sources_fallback-pkg'))
def test_version_egg_info_file(self):
self.assertEqual(version('egginfo-file'), '0.1')