mirror of
https://github.com/python/cpython.git
synced 2025-11-26 13:22:51 +00:00
bpo-43428: Sync with importlib_metadata 3.7. (GH-24782)
* bpo-43428: Sync with importlib_metadata 3.7.2 (67234b6) * Add blurb * Reformat blurb to create separate paragraphs for each change included.
This commit is contained in:
parent
2256a2876b
commit
f917efccf8
8 changed files with 343 additions and 43 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import re
|
||||
import textwrap
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from . import fixtures
|
||||
from importlib.metadata import (
|
||||
|
|
@ -64,18 +65,97 @@ class APITests(
|
|||
self.assertEqual(top_level.read_text(), 'mod\n')
|
||||
|
||||
def test_entry_points(self):
|
||||
entries = dict(entry_points()['entries'])
|
||||
eps = entry_points()
|
||||
assert 'entries' in eps.groups
|
||||
entries = eps.select(group='entries')
|
||||
assert 'main' in entries.names
|
||||
ep = entries['main']
|
||||
self.assertEqual(ep.value, 'mod:main')
|
||||
self.assertEqual(ep.extras, [])
|
||||
|
||||
def test_entry_points_distribution(self):
|
||||
entries = dict(entry_points()['entries'])
|
||||
entries = entry_points(group='entries')
|
||||
for entry in ("main", "ns:sub"):
|
||||
ep = entries[entry]
|
||||
self.assertIn(ep.dist.name, ('distinfo-pkg', 'egginfo-pkg'))
|
||||
self.assertEqual(ep.dist.version, "1.0.0")
|
||||
|
||||
def test_entry_points_unique_packages(self):
|
||||
"""
|
||||
Entry points should only be exposed for the first package
|
||||
on sys.path with a given name.
|
||||
"""
|
||||
alt_site_dir = self.fixtures.enter_context(fixtures.tempdir())
|
||||
self.fixtures.enter_context(self.add_sys_path(alt_site_dir))
|
||||
alt_pkg = {
|
||||
"distinfo_pkg-1.1.0.dist-info": {
|
||||
"METADATA": """
|
||||
Name: distinfo-pkg
|
||||
Version: 1.1.0
|
||||
""",
|
||||
"entry_points.txt": """
|
||||
[entries]
|
||||
main = mod:altmain
|
||||
""",
|
||||
},
|
||||
}
|
||||
fixtures.build_files(alt_pkg, alt_site_dir)
|
||||
entries = entry_points(group='entries')
|
||||
assert not any(
|
||||
ep.dist.name == 'distinfo-pkg' and ep.dist.version == '1.0.0'
|
||||
for ep in entries
|
||||
)
|
||||
# ns:sub doesn't exist in alt_pkg
|
||||
assert 'ns:sub' not in entries
|
||||
|
||||
def test_entry_points_missing_name(self):
|
||||
with self.assertRaises(KeyError):
|
||||
entry_points(group='entries')['missing']
|
||||
|
||||
def test_entry_points_missing_group(self):
|
||||
assert entry_points(group='missing') == ()
|
||||
|
||||
def test_entry_points_dict_construction(self):
|
||||
"""
|
||||
Prior versions of entry_points() returned simple lists and
|
||||
allowed casting those lists into maps by name using ``dict()``.
|
||||
Capture this now deprecated use-case.
|
||||
"""
|
||||
with warnings.catch_warnings(record=True) as caught:
|
||||
warnings.filterwarnings("default", category=DeprecationWarning)
|
||||
eps = dict(entry_points(group='entries'))
|
||||
|
||||
assert 'main' in eps
|
||||
assert eps['main'] == entry_points(group='entries')['main']
|
||||
|
||||
# check warning
|
||||
expected = next(iter(caught))
|
||||
assert expected.category is DeprecationWarning
|
||||
assert "Construction of dict of EntryPoints is deprecated" in str(expected)
|
||||
|
||||
def test_entry_points_groups_getitem(self):
|
||||
"""
|
||||
Prior versions of entry_points() returned a dict. Ensure
|
||||
that callers using '.__getitem__()' are supported but warned to
|
||||
migrate.
|
||||
"""
|
||||
with warnings.catch_warnings(record=True):
|
||||
entry_points()['entries'] == entry_points(group='entries')
|
||||
|
||||
with self.assertRaises(KeyError):
|
||||
entry_points()['missing']
|
||||
|
||||
def test_entry_points_groups_get(self):
|
||||
"""
|
||||
Prior versions of entry_points() returned a dict. Ensure
|
||||
that callers using '.get()' are supported but warned to
|
||||
migrate.
|
||||
"""
|
||||
with warnings.catch_warnings(record=True):
|
||||
entry_points().get('missing', 'default') == 'default'
|
||||
entry_points().get('entries', 'default') == entry_points()['entries']
|
||||
entry_points().get('missing', ()) == ()
|
||||
|
||||
def test_metadata_for_this_package(self):
|
||||
md = metadata('egginfo-pkg')
|
||||
assert md['author'] == 'Steven Ma'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue