Skip to content

Commit

Permalink
Add docstring with tests for EntryPoint.matches. Ref #373.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 13, 2022
1 parent ee566d0 commit dbe114c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,25 @@ def __iter__(self):
return iter((self.name, self))

def matches(self, **params):
"""
EntryPoint matches the given parameters.
>>> ep = EntryPoint(group='foo', name='bar', value='bing:bong [extra1, extra2]')
>>> ep.matches(group='foo')
True
>>> ep.matches(name='bar', value='bing:bong [extra1, extra2]')
True
>>> ep.matches(group='foo', name='other')
False
>>> ep.matches()
True
>>> ep.matches(extras=['extra1', 'extra2'])
True
>>> ep.matches(module='bing')
True
>>> ep.matches(attr='bong')
True
"""
attrs = (getattr(self, param) for param in params)
return all(map(operator.eq, params.values(), attrs))

Expand Down

0 comments on commit dbe114c

Please sign in to comment.