mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-08 05:54:17 +00:00
Fix logic for Notifier.listeners_for
Add tests for proper logic around notifier
This commit is contained in:
parent
222be9ac49
commit
37b92cd4b4
3 changed files with 34 additions and 23 deletions
|
|
@ -8,7 +8,7 @@ class _Listener(object):
|
|||
self.was_notified = False
|
||||
|
||||
def notify(self, error_code, *args, **kwargs):
|
||||
assert self.error_code == error_code
|
||||
assert error_code.startswith(self.error_code)
|
||||
self.was_notified = True
|
||||
|
||||
|
||||
|
|
@ -18,14 +18,18 @@ class TestNotifier(object):
|
|||
self.notifier = notifier.Notifier()
|
||||
self.listener_map = {}
|
||||
|
||||
for i in range(10):
|
||||
for j in range(30):
|
||||
error_code = 'E{0}{1:02d}'.format(i, j)
|
||||
listener = _Listener(error_code)
|
||||
self.listener_map[error_code] = listener
|
||||
self.notifier.register_listener(error_code, listener)
|
||||
def add_listener(error_code):
|
||||
listener = _Listener(error_code)
|
||||
self.listener_map[error_code] = listener
|
||||
self.notifier.register_listener(error_code, listener)
|
||||
|
||||
def test_notify_a_single_error_code(self):
|
||||
for i in range(10):
|
||||
add_listener('E{0}'.format(i))
|
||||
for j in range(30):
|
||||
add_listener('E{0}{1:02d}'.format(i, j))
|
||||
|
||||
def test_notify(self):
|
||||
"""Show that we notify a specific error code."""
|
||||
self.notifier.notify('E111', 'extra', 'args')
|
||||
assert self.listener_map['E111'].was_notified is True
|
||||
assert self.listener_map['E1'].was_notified is True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue