def test_disable_global_option_end_of_line(): """ Test for issue with disabling tokenizer messages that extend beyond the scope of the ast tokens """ file_ = tempfile.NamedTemporaryFile("w", delete=False) with file_: file_.write( """ mylist = [ None ] """ ) try: linter = lint.PyLinter() checker = FormatChecker(linter) linter.register_checker(checker) args = linter.load_command_line_configuration( [file_.name, "-d", "bad-continuation"] ) myreporter = reporters.CollectingReporter() linter.set_reporter(myreporter) linter.check(args) assert not myreporter.messages finally: os.remove(file_.name)
def run_pylint(self, path): with warnings.catch_warnings(): # suppress this warnings from output warnings.filterwarnings( "ignore", category=PendingDeprecationWarning, ) warnings.filterwarnings( "ignore", category=DeprecationWarning, ) warnings.filterwarnings( "ignore", category=ImportWarning, ) linter = lint.PyLinter() # Register standard checkers. linter.load_default_plugins() linter.set_reporter(reporters.CollectingReporter()) # we can simply use linter.error_mode(), # but I prefer to filter errors later. linter.global_set_option("ignored-modules", self.ignored_modules) linter.global_set_option("ignored-classes", self.ignored_classes) linter.global_set_option("disable", self.disable_ids) linter.check(path) return linter.reporter.messages
def _worker_initialize(linter, arguments=None): global _worker_linter # pylint: disable=global-statement _worker_linter = linter # On the worker process side the messages are just collected and passed back to # parent process as _worker_check_file function's return value _worker_linter.set_reporter(reporters.CollectingReporter()) _worker_linter.open() # Patch sys.path so that each argument is importable just like in single job mode _patch_sys_path(arguments or ())
def _worker_initialize( linter: bytes, arguments: Union[None, str, Sequence[str]] = None ) -> None: """Function called to initialize a worker for a Process within a multiprocessing Pool :param linter: A linter-class (PyLinter) instance pickled with dill :param arguments: File or module name(s) to lint and to be added to sys.path """ global _worker_linter # pylint: disable=global-statement _worker_linter = dill.loads(linter) # On the worker process side the messages are just collected and passed back to # parent process as _worker_check_file function's return value _worker_linter.set_reporter(reporters.CollectingReporter()) _worker_linter.open() # Patch sys.path so that each argument is importable just like in single job mode _patch_sys_path(arguments or ())
def test_disable_global_option_end_of_line() -> None: """Test for issue with disabling tokenizer messages that extend beyond the scope of the ast tokens """ file_ = tempfile.NamedTemporaryFile("w", delete=False) with file_: file_.write(""" 1 """) try: linter = lint.PyLinter() checker = BasicChecker(linter) linter.register_checker(checker) args = linter._arguments_manager._parse_command_line_configuration( [file_.name, "-d", "pointless-statement"]) myreporter = reporters.CollectingReporter() linter.set_reporter(myreporter) linter.check(args) assert not myreporter.messages finally: os.remove(file_.name)