summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMark Bell <mark00bell@googlemail.com>2021-07-17 12:58:49 +0100
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-07-17 23:47:07 +0200
commit332c35b98dd872c969f24b13ea4167013b44fd6d (patch)
treee704d75a0f0f09ba3e128b91d8072af3b1670581 /tests
parente0d40ccdb2a9171959c1cf7b2eb8c879c3469b81 (diff)
downloadpylint-git-332c35b98dd872c969f24b13ea4167013b44fd6d.tar.gz
Added unit tests and allow fail-under to apply even when the score is exactly zero.
Diffstat (limited to 'tests')
-rw-r--r--tests/regrtest_data/fail_on.py12
-rw-r--r--tests/regrtest_data/fail_on_info_only.py11
-rw-r--r--tests/test_self.py32
3 files changed, 55 insertions, 0 deletions
diff --git a/tests/regrtest_data/fail_on.py b/tests/regrtest_data/fail_on.py
new file mode 100644
index 000000000..6f22e5013
--- /dev/null
+++ b/tests/regrtest_data/fail_on.py
@@ -0,0 +1,12 @@
+"""
+ Pylint score: -1.67
+"""
+import nonexistent
+# pylint: disable=broad-except
+
+
+def loop():
+ count = 0
+ for _ in range(5):
+ count += 1
+ print(count)
diff --git a/tests/regrtest_data/fail_on_info_only.py b/tests/regrtest_data/fail_on_info_only.py
new file mode 100644
index 000000000..c6baffed0
--- /dev/null
+++ b/tests/regrtest_data/fail_on_info_only.py
@@ -0,0 +1,11 @@
+"""
+ Pylint score: -1.67
+"""
+# pylint: disable=broad-except
+
+def loop():
+ """Run a loop."""
+ count = 0
+ for _ in range(5):
+ count += 1
+ print(count)
diff --git a/tests/test_self.py b/tests/test_self.py
index a921248c8..ef70cdf33 100644
--- a/tests/test_self.py
+++ b/tests/test_self.py
@@ -1136,6 +1136,38 @@ class TestRunTC:
output_file = "thisdirectorydoesnotexit/output.txt"
self._runtest([path, f"--output={output_file}"], code=32)
+ @pytest.mark.parametrize("args, expected", [
+ ([], 0),
+ (["--enable=C"], 0),
+ (["--fail-on=superfluous-parens"], 0),
+ (["--fail-on=import-error"], 6),
+ (["--fail-on=unused-import"], 6),
+ (["--fail-on=unused-import", "--enable=C"], 22),
+ (["--fail-on=missing-function-docstring"], 22),
+ (["--fail-on=useless-suppression"], 6),
+ (["--fail-on=useless-suppression", "--enable=C"], 22),
+ ])
+ def test_fail_on_exit_code(self, args, expected):
+ path = join(HERE, "regrtest_data", "fail_on.py")
+ # We set fail-under to be something very low so that even with the warnings
+ # and errors that are generated they don't affect the exit code.
+ self._runtest([path, "--fail-under=-10"] + args, code=expected)
+
+ @pytest.mark.parametrize("args, expected", [
+ ([], 0),
+ (["--enable=C"], 0),
+ (["--fail-on=superfluous-parens"], 0),
+ (["--fail-on=import-error"], 0),
+ (["--fail-on=unused-import"], 0),
+ (["--fail-on=unused-import", "--enable=C"], 0),
+ (["--fail-on=missing-function-docstring"], 0),
+ (["--fail-on=useless-suppression"], 1),
+ (["--fail-on=useless-suppression", "--enable=C"], 1),
+ ])
+ def test_fail_on_info_only_exit_code(self, args, expected):
+ path = join(HERE, "regrtest_data", "fail_on_info_only.py")
+ self._runtest([path] + args, code=expected)
+
@pytest.mark.parametrize(
"output_format, expected_output",
[