Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Get a mock FileChecker class with plugin_target registered.
Useful as a starting point for mocking reports/results.
"""
# Mock an entry point returning the plugin target
entry_point = mock.Mock(spec=['load'])
entry_point.name = plugin_target.name
entry_point.load.return_value = plugin_target
# Load the checker plugins using the entry point mock
with mock.patch.object(
importlib_metadata,
'entry_points',
return_value={'flake8.extension': [entry_point]},
):
checks = manager.Checkers()
# Prevent it from reading lines from stdin or somewhere else
with mock.patch('flake8.processor.FileProcessor.read_lines',
return_value=['Line 1']):
file_checker = checker.FileChecker(
'-',
checks.to_dictionary(),
mock.MagicMock()
)
return file_checker
:param config.ConfigFileFinder config_finder:
The finder for finding and reading configuration files.
:param str config_file:
The optional configuraiton file to override all other configuration
files (i.e., the --config option).
:param bool ignore_config_files:
Determine whether to parse configuration files or not. (i.e., the
--isolated option).
"""
local_plugins = config.get_local_plugins(
config_finder, config_file, ignore_config_files
)
sys.path.extend(local_plugins.paths)
self.check_plugins = plugin_manager.Checkers(local_plugins.extension)
self.formatting_plugins = plugin_manager.ReportFormatters(
local_plugins.report
)
self.check_plugins.load_plugins()
self.formatting_plugins.load_plugins()
If :attr:`check_plugins`, :attr:`listening_plugins`, or
:attr:`formatting_plugins` are ``None`` then this method will update
them with the appropriate plugin manager instance. Given the expense
of finding plugins (via :mod:`pkg_resources`) we want this to be
idempotent and so only update those attributes if they are ``None``.
"""
if self.local_plugins is None:
self.local_plugins = config.get_local_plugins(
self.config_finder,
self.prelim_opts.config,
self.prelim_opts.isolated,
)
if self.check_plugins is None:
self.check_plugins = plugin_manager.Checkers(
self.local_plugins.extension)
if self.listening_plugins is None:
self.listening_plugins = plugin_manager.Listeners()
if self.formatting_plugins is None:
self.formatting_plugins = plugin_manager.ReportFormatters(
self.local_plugins.report)
self.check_plugins.load_plugins()
self.listening_plugins.load_plugins()
self.formatting_plugins.load_plugins()