From ee85728805ca3bc9ab888b9224416aeb4861e0c3 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 27 Oct 2021 11:32:29 +0200 Subject: Fix deprecation 'check function will only accept sequence of string' (#5218) * Fix deprecation 'check function will only accept sequence of string' * Add a test for Pylinter.check() deprecation --- tests/lint/test_pylinter.py | 6 ++++++ tests/test_regr.py | 32 ++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/tests/lint/test_pylinter.py b/tests/lint/test_pylinter.py index 27fc10ebf..900d53fb3 100644 --- a/tests/lint/test_pylinter.py +++ b/tests/lint/test_pylinter.py @@ -35,3 +35,9 @@ def test_crash_in_file( with open(files[0], encoding="utf8") as f: content = f.read() assert "Failed to import module spam." in content + + +def test_check_deprecation(linter: PyLinter, recwarn): + linter.check("myfile.py") + msg = recwarn.pop() + assert "check function will only accept sequence" in str(msg) diff --git a/tests/test_regr.py b/tests/test_regr.py index 3e597d418..63b406b3d 100644 --- a/tests/test_regr.py +++ b/tests/test_regr.py @@ -26,7 +26,7 @@ import signal import sys from contextlib import contextmanager from os.path import abspath, dirname, join -from typing import Iterator +from typing import Callable, Iterator, List import astroid import pytest @@ -62,7 +62,7 @@ def Equals(expected): @pytest.mark.parametrize( - "file_name, check", + "file_names, check", [ (["package.__init__"], Equals("")), (["precedence_test"], Equals("")), @@ -75,22 +75,24 @@ def Equals(expected): ([join(REGR_DATA, "bad_package")], lambda x: "Unused import missing" in x), ], ) -def test_package(finalize_linter, file_name, check): - finalize_linter.check(file_name) +def test_package( + finalize_linter: PyLinter, file_names: List[str], check: Callable +) -> None: + finalize_linter.check(file_names) got = finalize_linter.reporter.finalize().strip() assert check(got) @pytest.mark.parametrize( - "file_name", + "file_names", [ - join(REGR_DATA, "import_assign.py"), - join(REGR_DATA, "special_attr_scope_lookup_crash.py"), - join(REGR_DATA, "try_finally_disable_msg_crash"), + [join(REGR_DATA, "import_assign.py")], + [join(REGR_DATA, "special_attr_scope_lookup_crash.py")], + [join(REGR_DATA, "try_finally_disable_msg_crash")], ], ) -def test_crash(finalize_linter, file_name): - finalize_linter.check(file_name) +def test_crash(finalize_linter: PyLinter, file_names: List[str]) -> None: + finalize_linter.check(file_names) @pytest.mark.parametrize( @@ -156,11 +158,13 @@ def timeout(timeout_s: float): @pytest.mark.skipif(not hasattr(signal, "setitimer"), reason="Assumes POSIX signals") @pytest.mark.parametrize( - "fname,timeout_s", + "file_names,timeout_s", [ - (join(REGR_DATA, "hang", "pkg4972.string"), 30.0), + ([join(REGR_DATA, "hang", "pkg4972.string")], 30.0), ], ) -def test_hang(finalize_linter, fname: str, timeout_s: float) -> None: +def test_hang( + finalize_linter: PyLinter, file_names: List[str], timeout_s: float +) -> None: with timeout(timeout_s): - finalize_linter.check(fname) + finalize_linter.check(file_names) -- cgit v1.2.1