mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
gh-97781: Apply changes from importlib_metadata 5. (GH-97785)
* gh-97781: Apply changes from importlib_metadata 5. * Apply changes from upstream * Apply changes from upstream.
This commit is contained in:
parent
2b5f1360ea
commit
8af04cdef2
5 changed files with 88 additions and 302 deletions
|
@ -1,8 +1,6 @@
|
|||
import re
|
||||
import json
|
||||
import pickle
|
||||
import unittest
|
||||
import warnings
|
||||
import importlib.metadata
|
||||
|
||||
try:
|
||||
|
@ -260,14 +258,6 @@ class TestEntryPoints(unittest.TestCase):
|
|||
"""EntryPoints should be hashable"""
|
||||
hash(self.ep)
|
||||
|
||||
def test_json_dump(self):
|
||||
"""
|
||||
json should not expect to be able to dump an EntryPoint
|
||||
"""
|
||||
with self.assertRaises(Exception):
|
||||
with warnings.catch_warnings(record=True):
|
||||
json.dumps(self.ep)
|
||||
|
||||
def test_module(self):
|
||||
assert self.ep.module == 'value'
|
||||
|
||||
|
|
|
@ -124,62 +124,6 @@ class APITests(
|
|||
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 suppress_known_deprecation() as caught:
|
||||
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_by_index(self):
|
||||
"""
|
||||
Prior versions of Distribution.entry_points would return a
|
||||
tuple that allowed access by index.
|
||||
Capture this now deprecated use-case
|
||||
See python/importlib_metadata#300 and bpo-44246.
|
||||
"""
|
||||
eps = distribution('distinfo-pkg').entry_points
|
||||
with suppress_known_deprecation() as caught:
|
||||
eps[0]
|
||||
|
||||
# check warning
|
||||
expected = next(iter(caught))
|
||||
assert expected.category is DeprecationWarning
|
||||
assert "Accessing entry points by index 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 suppress_known_deprecation():
|
||||
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 suppress_known_deprecation():
|
||||
entry_points().get('missing', 'default') == 'default'
|
||||
entry_points().get('entries', 'default') == entry_points()['entries']
|
||||
entry_points().get('missing', ()) == ()
|
||||
|
||||
def test_entry_points_allows_no_attributes(self):
|
||||
ep = entry_points().select(group='entries', name='main')
|
||||
with self.assertRaises(AttributeError):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue