From 5b3c20b8d4c485dfff61836310e0fc65b00eecf0 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 29 Apr 2022 13:12:31 -0400 Subject: [PATCH 1/7] Check documentation examples for fatal errors --- doc/test_messages_documentation.py | 6 +++--- tests/testutils/test_functional_testutils.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/test_messages_documentation.py b/doc/test_messages_documentation.py index 9faa834f0b..12e8972240 100644 --- a/doc/test_messages_documentation.py +++ b/doc/test_messages_documentation.py @@ -91,7 +91,7 @@ def __init__(self, test_file: Tuple[str, Path]) -> None: args_list=[ str(test_file[1]), "--disable=all", - f"--enable={test_file[0]}", + f"--enable={test_file[0]},astroid-error,fatal,syntax-error", ], reporter=_test_reporter, config_file=config_file, @@ -146,9 +146,9 @@ def _runTest(self) -> None: expected_messages = self._get_expected() actual_messages = self._get_actual() if self.is_good_test_file(): - assert actual_messages.total() == 0 # type: ignore[attr-defined] + assert actual_messages.total() == 0 if self.is_bad_test_file(): - assert actual_messages.total() > 0 # type: ignore[attr-defined] + assert actual_messages.total() > 0 assert expected_messages == actual_messages diff --git a/tests/testutils/test_functional_testutils.py b/tests/testutils/test_functional_testutils.py index 7365022dad..fb664959cf 100644 --- a/tests/testutils/test_functional_testutils.py +++ b/tests/testutils/test_functional_testutils.py @@ -62,6 +62,7 @@ def test_minimal_messages_config_enabled(pytest_config) -> None: # Always enable fatal errors: important not to have false negatives "astroid-error", "fatal", + "syntax-error", ) ) assert not mod_test._linter.is_message_enabled("unused-import") From 5cc55bcc010e5b255acf4e8bda092a546863e498 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 29 Apr 2022 13:24:32 -0400 Subject: [PATCH 2/7] Update in both places --- pylint/testutils/lint_module_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pylint/testutils/lint_module_test.py b/pylint/testutils/lint_module_test.py index 620928e592..1642f9ba02 100644 --- a/pylint/testutils/lint_module_test.py +++ b/pylint/testutils/lint_module_test.py @@ -71,6 +71,7 @@ def __init__( # Always enable fatal errors messages_to_enable.add("astroid-error") messages_to_enable.add("fatal") + messages_to_enable.add("syntax-error") args.extend(["--disable=all", f"--enable={','.join(messages_to_enable)}"]) _config_initialization( self._linter, args_list=args, config_file=rc_file, reporter=_test_reporter From 6a4189795da54c0ca3ac6c17f300737bd77b51d6 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 29 Apr 2022 13:45:27 -0400 Subject: [PATCH 3/7] Update assertion examples to avoid syntax errors --- doc/data/messages/a/assert-on-string-literal/good.py | 4 +++- doc/data/messages/r/redundant-unittest-assert/good.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/data/messages/a/assert-on-string-literal/good.py b/doc/data/messages/a/assert-on-string-literal/good.py index 436a8502f3..dafd75c023 100644 --- a/doc/data/messages/a/assert-on-string-literal/good.py +++ b/doc/data/messages/a/assert-on-string-literal/good.py @@ -1,2 +1,4 @@ def test(): - # Nothing, as an assert of a string literal will always pass + actual = "test" + wanted = "Directly asserting a string literal will always pass" + assert actual == wanted diff --git a/doc/data/messages/r/redundant-unittest-assert/good.py b/doc/data/messages/r/redundant-unittest-assert/good.py index b176d020da..e0e862d502 100644 --- a/doc/data/messages/r/redundant-unittest-assert/good.py +++ b/doc/data/messages/r/redundant-unittest-assert/good.py @@ -3,4 +3,5 @@ class DummyTestCase(unittest.TestCase): def test_dummy(self): - # Nothing, as an assert of a string literal will always pass + actual = "test_result" + self.assertEqual(actual, "expected") From 5b8eed58d3dc05e58d9f5a97c42f52b9e336dd39 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 29 Apr 2022 13:50:20 -0400 Subject: [PATCH 4/7] restore mypy disables. version diff? --- doc/test_messages_documentation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/test_messages_documentation.py b/doc/test_messages_documentation.py index 12e8972240..19ef0be153 100644 --- a/doc/test_messages_documentation.py +++ b/doc/test_messages_documentation.py @@ -146,9 +146,9 @@ def _runTest(self) -> None: expected_messages = self._get_expected() actual_messages = self._get_actual() if self.is_good_test_file(): - assert actual_messages.total() == 0 + assert actual_messages.total() == 0 # type: ignore[attr-defined] if self.is_bad_test_file(): - assert actual_messages.total() > 0 + assert actual_messages.total() == 0 # type: ignore[attr-defined] assert expected_messages == actual_messages From 158ceb38835e9e80b5e3dc901b57ec8994edec89 Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Fri, 29 Apr 2022 13:51:11 -0400 Subject: [PATCH 5/7] oops --- doc/test_messages_documentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/test_messages_documentation.py b/doc/test_messages_documentation.py index 19ef0be153..76a7f3ca74 100644 --- a/doc/test_messages_documentation.py +++ b/doc/test_messages_documentation.py @@ -148,7 +148,7 @@ def _runTest(self) -> None: if self.is_good_test_file(): assert actual_messages.total() == 0 # type: ignore[attr-defined] if self.is_bad_test_file(): - assert actual_messages.total() == 0 # type: ignore[attr-defined] + assert actual_messages.total() > 0 # type: ignore[attr-defined] assert expected_messages == actual_messages From 0cd085ab721ec1a3e273d93dd036c0057f13444b Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 30 Apr 2022 09:43:43 -0400 Subject: [PATCH 6/7] Add details.rst --- doc/data/messages/a/assert-on-string-literal/details.rst | 1 + doc/data/messages/a/assert-on-string-literal/good.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 doc/data/messages/a/assert-on-string-literal/details.rst diff --git a/doc/data/messages/a/assert-on-string-literal/details.rst b/doc/data/messages/a/assert-on-string-literal/details.rst new file mode 100644 index 0000000000..76c2a271e5 --- /dev/null +++ b/doc/data/messages/a/assert-on-string-literal/details.rst @@ -0,0 +1 @@ +Directly asserting a string literal will always pass. diff --git a/doc/data/messages/a/assert-on-string-literal/good.py b/doc/data/messages/a/assert-on-string-literal/good.py index dafd75c023..2426496978 100644 --- a/doc/data/messages/a/assert-on-string-literal/good.py +++ b/doc/data/messages/a/assert-on-string-literal/good.py @@ -1,4 +1,4 @@ def test(): - actual = "test" - wanted = "Directly asserting a string literal will always pass" - assert actual == wanted + result = "result" + expected = "expected" + assert result == expected From 13f1ac80b7f491bd163e5542cc293e2f9474eedf Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 30 Apr 2022 09:45:56 -0400 Subject: [PATCH 7/7] another details.rst --- doc/data/messages/r/redundant-unittest-assert/details.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/data/messages/r/redundant-unittest-assert/details.rst diff --git a/doc/data/messages/r/redundant-unittest-assert/details.rst b/doc/data/messages/r/redundant-unittest-assert/details.rst new file mode 100644 index 0000000000..76c2a271e5 --- /dev/null +++ b/doc/data/messages/r/redundant-unittest-assert/details.rst @@ -0,0 +1 @@ +Directly asserting a string literal will always pass.