From 98357e71db4591ecf9e74321608def35125aa40d Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Fri, 19 Feb 2016 18:55:01 -0600 Subject: [PATCH] Fix Notifier.listeners_for If no Trie.find returns None, then node.data will return an AttributeError. --- flake8/plugins/notifier.py | 3 ++- tests/unit/test_notifier.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/flake8/plugins/notifier.py b/flake8/plugins/notifier.py index 323ea1d..dc255c4 100644 --- a/flake8/plugins/notifier.py +++ b/flake8/plugins/notifier.py @@ -31,7 +31,8 @@ class Notifier(object): path = error_code while path: node = self.listeners.find(path) - for listener in node.data: + listeners = getattr(node, 'data', []) + for listener in listeners: yield listener path = path[:-1] diff --git a/tests/unit/test_notifier.py b/tests/unit/test_notifier.py index effcc88..6a162cf 100644 --- a/tests/unit/test_notifier.py +++ b/tests/unit/test_notifier.py @@ -38,3 +38,17 @@ class TestNotifier(object): self.notifier.notify('E111', 'extra', 'args') assert self.listener_map['E111'].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)