summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2023-01-16 23:04:25 +0100
committerGitHub <noreply@github.com>2023-01-16 23:04:25 +0100
commit4a5b4e63c8177ec1b1c7d1ecb4eb2c448c7481a3 (patch)
tree33c7d491e2462d766aa0c3f360f9499e1cce809e /tests
parenteae0eaff11239db4dc89d570d120ff0a6cbe1e61 (diff)
downloadpylint-git-4a5b4e63c8177ec1b1c7d1ecb4eb2c448c7481a3.tar.gz
[style] Limit line length and complexity using flake8 (#8064)
125 is a good start. The check was activated in pylint with value = 100, but flake8 is less lenient than pylint and does not make any exceptions (for docstrings, strings and comments in particular).
Diffstat (limited to 'tests')
-rw-r--r--tests/checkers/unittest_spelling.py53
-rw-r--r--tests/test_func.py6
-rw-r--r--tests/test_self.py12
3 files changed, 30 insertions, 41 deletions
diff --git a/tests/checkers/unittest_spelling.py b/tests/checkers/unittest_spelling.py
index abeb9dcf8..29783429b 100644
--- a/tests/checkers/unittest_spelling.py
+++ b/tests/checkers/unittest_spelling.py
@@ -286,44 +286,29 @@ class TestSpellingChecker(CheckerTestCase): # pylint:disable=too-many-public-me
@skip_on_missing_package_or_dict
@set_config(spelling_dict=spell_dict)
@pytest.mark.parametrize(
- ",".join(
- (
- "misspelled_portion_of_directive",
- "second_portion_of_directive",
- "description",
- )
- ),
+ "prefix,suffix",
(
- ("fmt", ": on", "black directive to turn on formatting"),
- ("fmt", ": off", "black directive to turn off formatting"),
- ("noqa", "", "pycharm directive"),
- ("noqa", ":", "flake8 / zimports directive"),
- ("nosec", "", "bandit directive"),
- ("isort", ":skip", "isort directive"),
- ("mypy", ":", "mypy top of file directive"),
+ pytest.param("fmt", ": on", id="black directive to turn on formatting"),
+ pytest.param("fmt", ": off", id="black directive to turn off formatting"),
+ pytest.param("noqa", "", id="pycharm directive"),
+ pytest.param("noqa", ":", id="flake8 / zimports directive"),
+ pytest.param("nosec", "", id="bandit directive"),
+ pytest.param("isort", ":skip", id="isort directive"),
+ pytest.param("mypy", ":", id="mypy top of file directive"),
),
)
- def test_skip_tool_directives_at_beginning_of_comments_but_still_raise_error_if_directive_appears_later_in_comment( # pylint:disable=unused-argument
- # Having the extra description parameter allows the description
- # to show up in the pytest output as part of the test name
- # when running parameterized tests.
- self,
- misspelled_portion_of_directive: str,
- second_portion_of_directive: str,
- description: str,
- ) -> None:
- full_comment = f"# {misspelled_portion_of_directive}{second_portion_of_directive} {misspelled_portion_of_directive}"
+ def test_tool_directives_handling(self, prefix: str, suffix: str) -> None:
+ """We're not raising when the directive is at the beginning of comments,
+ but we raise if a directive appears later in comment."""
+ full_comment = f"# {prefix}{suffix} {prefix}"
+ args = (
+ prefix,
+ full_comment,
+ f" {'^' * len(prefix)}",
+ self._get_msg_suggestions(prefix),
+ )
with self.assertAddsMessages(
- MessageTest(
- "wrong-spelling-in-comment",
- line=1,
- args=(
- misspelled_portion_of_directive,
- full_comment,
- f" {'^'*len(misspelled_portion_of_directive)}",
- self._get_msg_suggestions(misspelled_portion_of_directive),
- ),
- )
+ MessageTest("wrong-spelling-in-comment", line=1, args=args)
):
self.checker.process_tokens(_tokenize_str(full_comment))
diff --git a/tests/test_func.py b/tests/test_func.py
index 493489aee..a032baf5d 100644
--- a/tests/test_func.py
+++ b/tests/test_func.py
@@ -73,9 +73,11 @@ class LintTestUsingModule:
self.linter.check(tocheck)
except Exception as ex:
print(f"Exception: {ex} in {tocheck}:: {'‚ '.join(ex.args)}")
- ex.file = tocheck # type: ignore[attr-defined] # This is legacy code we're trying to remove, not worth it to type correctly
+ # This is legacy code we're trying to remove, not worth it to type correctly
+ ex.file = tocheck # type: ignore[attr-defined]
print(ex)
- ex.__str__ = exception_str # type: ignore[assignment] # This is legacy code we're trying to remove, impossible to type correctly
+ # This is legacy code we're trying to remove, not worth it to type correctly
+ ex.__str__ = exception_str # type: ignore[assignment]
raise
assert isinstance(self.linter.reporter, GenericTestReporter)
self._check_result(self.linter.reporter.finalize())
diff --git a/tests/test_self.py b/tests/test_self.py
index 9cec1b1c9..076f2a22f 100644
--- a/tests/test_self.py
+++ b/tests/test_self.py
@@ -1052,19 +1052,21 @@ a.py:1:4: E0001: Parsing failed: 'invalid syntax (<unknown>, line 1)' (syntax-er
[
(
"text",
- "tests/regrtest_data/unused_variable.py:4:4: W0612: Unused variable 'variable' (unused-variable)",
+ "{path}:4:4: W0612: Unused variable 'variable' (unused-variable)",
),
(
"parseable",
- "tests/regrtest_data/unused_variable.py:4: [W0612(unused-variable), test] Unused variable 'variable'",
+ "{path}:4: [W0612(unused-variable), test] Unused variable 'variable'",
),
(
"msvs",
- "tests/regrtest_data/unused_variable.py(4): [W0612(unused-variable)test] Unused variable 'variable'",
+ "{path}(4): [W0612(unused-variable)test] Unused variable 'variable'",
),
(
"colorized",
- "tests/regrtest_data/unused_variable.py:4:4: W0612: \x1B[35mUnused variable 'variable'\x1B[0m (\x1B[35munused-variable\x1B[0m)",
+ (
+ "{path}:4:4: W0612: \x1B[35mUnused variable 'variable'\x1B[0m (\x1B[35munused-variable\x1B[0m)"
+ ),
),
("json", '"message": "Unused variable \'variable\'",'),
],
@@ -1077,7 +1079,7 @@ a.py:1:4: E0001: Parsing failed: 'invalid syntax (<unknown>, line 1)' (syntax-er
self._test_output_file(
[path, f"--output={output_file}", f"--output-format={output_format}"],
output_file,
- expected_output,
+ expected_output.format(path="tests/regrtest_data/unused_variable.py"),
)
def test_output_file_can_be_combined_with_custom_reporter(