mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 14:54:17 +00:00
Fix Notifier.listeners_for
If no Trie.find returns None, then node.data will return an AttributeError.
This commit is contained in:
parent
58b2ca69e4
commit
98357e71db
2 changed files with 16 additions and 1 deletions
|
|
@ -31,7 +31,8 @@ class Notifier(object):
|
||||||
path = error_code
|
path = error_code
|
||||||
while path:
|
while path:
|
||||||
node = self.listeners.find(path)
|
node = self.listeners.find(path)
|
||||||
for listener in node.data:
|
listeners = getattr(node, 'data', [])
|
||||||
|
for listener in listeners:
|
||||||
yield listener
|
yield listener
|
||||||
path = path[:-1]
|
path = path[:-1]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,3 +38,17 @@ class TestNotifier(object):
|
||||||
self.notifier.notify('E111', 'extra', 'args')
|
self.notifier.notify('E111', 'extra', 'args')
|
||||||
assert self.listener_map['E111'].was_notified is True
|
assert self.listener_map['E111'].was_notified is True
|
||||||
assert self.listener_map['E1'].was_notified is True
|
assert self.listener_map['E1'].was_notified is True
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('code', ['W123', 'W12', 'W1', 'W'])
|
||||||
|
def test_no_listeners_for(self, code):
|
||||||
|
"""Show that we return an empty list of listeners."""
|
||||||
|
assert list(self.notifier.listeners_for(code)) == []
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('code,expected', [
|
||||||
|
('E101', ['E101', 'E1']),
|
||||||
|
('E211', ['E211', 'E2']),
|
||||||
|
])
|
||||||
|
def test_listeners_for(self, code, expected):
|
||||||
|
"""Verify that we retrieve the correct listeners."""
|
||||||
|
assert ([l.error_code for l in self.notifier.listeners_for(code)] ==
|
||||||
|
expected)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue