Skip to content

Commit

Permalink
Add deprecated .get to GroupedEntryPoints and test to capture expecta…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
jaraco committed Jan 23, 2021
1 parent 28adeb8 commit 342a94b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions importlib_metadata/__init__.py
Expand Up @@ -183,6 +183,14 @@ def __getitem__(self, group) -> EntryPoints:
def groups(self):
return set(ep.group for ep in self)

def get(self, group, default=None):
"""
For backward compatibility, supply .get
"""
msg = "GroupedEntryPoints.get is deprecated. Just use __getitem__."
warnings.warn(msg, DeprecationWarning)
return self[group] or default


class PackagePath(pathlib.PurePosixPath):
"""A reference to a path in a package"""
Expand Down
11 changes: 11 additions & 0 deletions tests/test_api.py
Expand Up @@ -104,6 +104,17 @@ def test_entry_points_dict_construction(self):
assert expected.category is DeprecationWarning
assert "Construction of dict of EntryPoints is deprecated" in str(expected)

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', ()) == entry_points()['missing']

def test_metadata_for_this_package(self):
md = metadata('egginfo-pkg')
assert md['author'] == 'Steven Ma'
Expand Down

0 comments on commit 342a94b

Please sign in to comment.