mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-08 05:54:17 +00:00
Refactor NotifierBuilder into its own mixin
This allows for easier unit testing
This commit is contained in:
parent
b0a258fe79
commit
ebdc935ffc
2 changed files with 42 additions and 10 deletions
|
|
@ -253,16 +253,8 @@ class PluginTypeManager(object):
|
||||||
list(self.manager.map(call_provide_options))
|
list(self.manager.map(call_provide_options))
|
||||||
|
|
||||||
|
|
||||||
class Checkers(PluginTypeManager):
|
class NotifierBuilder(object):
|
||||||
"""All of the checkers registered through entry-ponits."""
|
"""Mixin class that builds a Notifier from a PluginManager."""
|
||||||
|
|
||||||
namespace = 'flake8.extension'
|
|
||||||
|
|
||||||
|
|
||||||
class Listeners(PluginTypeManager):
|
|
||||||
"""All of the listeners registered through entry-points."""
|
|
||||||
|
|
||||||
namespace = 'flake8.listen'
|
|
||||||
|
|
||||||
def build_notifier(self):
|
def build_notifier(self):
|
||||||
"""Build a Notifier for our Listeners.
|
"""Build a Notifier for our Listeners.
|
||||||
|
|
@ -279,6 +271,18 @@ class Listeners(PluginTypeManager):
|
||||||
return notifier_trie
|
return notifier_trie
|
||||||
|
|
||||||
|
|
||||||
|
class Checkers(PluginTypeManager):
|
||||||
|
"""All of the checkers registered through entry-ponits."""
|
||||||
|
|
||||||
|
namespace = 'flake8.extension'
|
||||||
|
|
||||||
|
|
||||||
|
class Listeners(PluginTypeManager, NotifierBuilder):
|
||||||
|
"""All of the listeners registered through entry-points."""
|
||||||
|
|
||||||
|
namespace = 'flake8.listen'
|
||||||
|
|
||||||
|
|
||||||
class ReportFormatters(PluginTypeManager):
|
class ReportFormatters(PluginTypeManager):
|
||||||
"""All of the report formatters registered through entry-points."""
|
"""All of the report formatters registered through entry-points."""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,3 +165,31 @@ def test_provide_options(PluginManager):
|
||||||
plugin.provide_options.assert_called_with(optmanager,
|
plugin.provide_options.assert_called_with(optmanager,
|
||||||
options,
|
options,
|
||||||
extra_args)
|
extra_args)
|
||||||
|
|
||||||
|
|
||||||
|
class FakePluginTypeManager(manager.NotifierBuilder):
|
||||||
|
"""Provide an easy way to test the NotifierBuilder."""
|
||||||
|
|
||||||
|
def __init__(self, manager):
|
||||||
|
"""Initialize with our fake manager."""
|
||||||
|
self.names = sorted(manager.keys())
|
||||||
|
self.manager = manager
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def notifier_builder():
|
||||||
|
"""Create a fake plugin type manager."""
|
||||||
|
return FakePluginTypeManager(manager={
|
||||||
|
'T100': object(),
|
||||||
|
'T101': object(),
|
||||||
|
'T110': object(),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def test_build_notifier(notifier_builder):
|
||||||
|
"""Verify we properly build a Notifier object."""
|
||||||
|
notifier = notifier_builder.build_notifier()
|
||||||
|
for name in ('T100', 'T101', 'T110'):
|
||||||
|
assert list(notifier.listeners_for(name)) == [
|
||||||
|
notifier_builder.manager[name]
|
||||||
|
]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue