Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Side effect for the result handler to tell all are reported."""
return len(sorted_results)
# To simplify the parameters (and prevent copy & pasting) reuse report
# tuples to create the expected result lists from the indexes
expected_results = [results[index] for index in expected_order]
file_checker = mock.Mock(spec=['results', 'display_name'])
file_checker.results = results
file_checker.display_name = 'placeholder'
style_guide = mock.MagicMock(spec=['options', 'processing_file'])
# Create a placeholder manager without arguments or plugins
# Just add one custom file checker which just provides the results
manager = checker.Manager(style_guide, [], [])
manager.checkers = [file_checker]
# _handle_results is the first place which gets the sorted result
# Should something non-private be mocked instead?
handler = mock.Mock(side_effect=count_side_effect)
with mock.patch.object(manager, '_handle_results', handler):
assert manager.report() == (len(results), len(results))
handler.assert_called_once_with('placeholder', expected_results)
def _parallel_checker_manager():
"""Call Manager.run() and return the number of calls to `run_serial`."""
style_guide = style_guide_mock()
manager = checker.Manager(style_guide, [], [])
# multiple checkers is needed for parallel mode
manager.checkers = [mock.Mock(), mock.Mock()]
return manager
def make_file_checker_manager(self):
# type: () -> NoneType
"""Initialize our FileChecker Manager."""
if self.file_checker_manager is None:
self.file_checker_manager = checker.Manager(
style_guide=self.guide,
arguments=self.args,
checker_plugins=self.check_plugins,
)
def make_file_checker_manager(self):
# type: () -> None
"""Initialize our FileChecker Manager."""
if self.file_checker_manager is None:
self.file_checker_manager = checker.Manager(
style_guide=self.guide,
arguments=self.args,
checker_plugins=self.check_plugins,
)
def make_file_checker_manager(self):
# type: () -> None
"""Initialize our FileChecker Manager."""
self.file_checker_manager = checker.Manager(
style_guide=self.guide,
arguments=self.args,
checker_plugins=self.check_plugins,
)
from logging import getLogger
from typing import List, Tuple
from flake8.checker import Manager, FileChecker
from flake8.utils import fnmatch, filenames_from
from .._logic import get_plugin_name, get_plugin_rules, check_include, make_baseline
logger = getLogger('flakehell')
class FlakeHellCheckersManager(Manager):
"""
Patched flake8.checker.Manager to provide `plugins` support
"""
def __init__(self, baseline, **kwargs):
self.baseline = set()
if baseline:
self.baseline = {line.strip() for line in open(baseline)}
super().__init__(**kwargs)
def make_checkers(self, paths: List[str] = None) -> None:
"""
Reloaded checkers generator to provide one checker per file per rule.
Original `make_checkers` provides checker per file with all rules mixed.
It makes difficult to filter checks by codes after all.
"""
if paths is None:
def apply_patch() -> None:
"""This is the only function we export to apply all the patches."""
_patch_report(Manager)
_patch_handle_results(Manager)