summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniël van Noord <13665637+DanielNoord@users.noreply.github.com>2021-12-13 15:59:04 +0100
committerGitHub <noreply@github.com>2021-12-13 15:59:04 +0100
commitbf5217819adbb71bc2c873efa2efb298d12f4731 (patch)
treeeda923fed6483fbae0149ecfc1f61d2543c8f024
parente5cb38f991bf1e9ff5aa7c7f4c81880b6ea08f26 (diff)
downloadpylint-git-bf5217819adbb71bc2c873efa2efb298d12f4731.tar.gz
Move tests from ``TestComparison`` to functional tests (#5520)
* Remove some redundant tests
-rw-r--r--tests/checkers/unittest_base.py112
-rw-r--r--tests/functional/n/nan_comparison_check.py9
-rw-r--r--tests/functional/n/nan_comparison_check.txt26
-rw-r--r--tests/functional/s/singleton_comparison.py2
-rw-r--r--tests/functional/s/singleton_comparison.txt16
5 files changed, 31 insertions, 134 deletions
diff --git a/tests/checkers/unittest_base.py b/tests/checkers/unittest_base.py
index 24e17a0a5..bbe2be2fa 100644
--- a/tests/checkers/unittest_base.py
+++ b/tests/checkers/unittest_base.py
@@ -181,118 +181,6 @@ class TestMultiNamingStyle(CheckerTestCase):
self.checker.leave_module(func.root)
-class TestComparison(CheckerTestCase):
- CHECKER_CLASS = base.ComparisonChecker
-
- def test_comparison(self) -> None:
- node = astroid.extract_node("foo == True")
- message = MessageTest(
- "singleton-comparison",
- node=node,
- args=(
- "'foo == True'",
- "'foo is True' if checking for the singleton value True, or 'bool(foo)' if testing for truthiness",
- ),
- )
- with self.assertAddsMessages(message):
- self.checker.visit_compare(node)
-
- node = astroid.extract_node("foo == False")
- message = MessageTest(
- "singleton-comparison",
- node=node,
- args=(
- "'foo == False'",
- "'foo is False' if checking for the singleton value False, or 'not foo' if testing for falsiness",
- ),
- )
- with self.assertAddsMessages(message):
- self.checker.visit_compare(node)
-
- node = astroid.extract_node("foo == None")
- message = MessageTest(
- "singleton-comparison", node=node, args=("'foo == None'", "'foo is None'")
- )
- with self.assertAddsMessages(message):
- self.checker.visit_compare(node)
-
- node = astroid.extract_node("foo is float('nan')")
- message = MessageTest(
- "nan-comparison",
- node=node,
- args=("'foo is float('nan')'", "'math.isnan(foo)'"),
- )
- with self.assertAddsMessages(message):
- self.checker.visit_compare(node)
-
- node = astroid.extract_node(
- """
- import numpy
- foo != numpy.NaN
- """
- )
- message = MessageTest(
- "nan-comparison",
- node=node,
- args=("'foo != numpy.NaN'", "'not math.isnan(foo)'"),
- )
- with self.assertAddsMessages(message):
- self.checker.visit_compare(node)
-
- node = astroid.extract_node(
- """
- import numpy as nmp
- foo is not nmp.NaN
- """
- )
- message = MessageTest(
- "nan-comparison",
- node=node,
- args=("'foo is not nmp.NaN'", "'not math.isnan(foo)'"),
- )
- with self.assertAddsMessages(message):
- self.checker.visit_compare(node)
-
- node = astroid.extract_node("True == foo")
- messages = (
- MessageTest(
- "singleton-comparison",
- node=node,
- args=(
- "'True == foo'",
- "'True is foo' if checking for the singleton value True, or 'bool(foo)' if testing for truthiness",
- ),
- ),
- )
- with self.assertAddsMessages(*messages):
- self.checker.visit_compare(node)
-
- node = astroid.extract_node("False == foo")
- messages = (
- MessageTest(
- "singleton-comparison",
- node=node,
- args=(
- "'False == foo'",
- "'False is foo' if checking for the singleton value False, or 'not foo' if testing for falsiness",
- ),
- ),
- )
- with self.assertAddsMessages(*messages):
- self.checker.visit_compare(node)
-
- node = astroid.extract_node("None == foo")
- messages = (
- MessageTest(
- "singleton-comparison",
- node=node,
- args=("'None == foo'", "'None is foo'"),
- ),
- )
- with self.assertAddsMessages(*messages):
- self.checker.visit_compare(node)
-
-
class TestNamePresets(unittest.TestCase):
SNAKE_CASE_NAMES = {"tést_snake_case", "test_snake_case11", "test_https_200"}
CAMEL_CASE_NAMES = {"téstCamelCase", "testCamelCase11", "testHTTP200"}
diff --git a/tests/functional/n/nan_comparison_check.py b/tests/functional/n/nan_comparison_check.py
index b9a720b9a..99b921cde 100644
--- a/tests/functional/n/nan_comparison_check.py
+++ b/tests/functional/n/nan_comparison_check.py
@@ -2,10 +2,12 @@
# pylint: disable=literal-comparison,comparison-with-itself, import-error
"""Test detection of NaN value comparison."""
import numpy
+
x = 42
a = x is numpy.NaN # [nan-comparison]
b = x == numpy.NaN # [nan-comparison]
-c = x == float('nan') # [nan-comparison]
+c = x == float("nan") # [nan-comparison]
+d = x is float("nan") # [nan-comparison]
e = numpy.NaN == numpy.NaN # [nan-comparison]
f = x is 1
g = 123 is "123"
@@ -13,9 +15,10 @@ h = numpy.NaN is not x # [nan-comparison]
i = numpy.NaN != x # [nan-comparison]
j = x != numpy.NaN # [nan-comparison]
-j1 = x != float('nan') # [nan-comparison]
+j1 = x != float("nan") # [nan-comparison]
+k = x is not numpy.NaN # [nan-comparison]
assert x == numpy.NaN # [nan-comparison]
-assert x is not float('nan') # [nan-comparison]
+assert x is not float("nan") # [nan-comparison]
if x == numpy.NaN: # [nan-comparison]
pass
z = bool(x is numpy.NaN) # [nan-comparison]
diff --git a/tests/functional/n/nan_comparison_check.txt b/tests/functional/n/nan_comparison_check.txt
index 162b2c378..7c15fc952 100644
--- a/tests/functional/n/nan_comparison_check.txt
+++ b/tests/functional/n/nan_comparison_check.txt
@@ -1,12 +1,14 @@
-nan-comparison:6:4:6:18::Comparison 'x is numpy.NaN' should be 'math.isnan(x)':UNDEFINED
-nan-comparison:7:4:7:18::Comparison 'x == numpy.NaN' should be 'math.isnan(x)':UNDEFINED
-nan-comparison:8:4:8:21::Comparison 'x == float('nan')' should be 'math.isnan(x)':UNDEFINED
-nan-comparison:9:4:9:26::Comparison 'numpy.NaN == numpy.NaN' should be 'math.isnan(numpy.NaN)':UNDEFINED
-nan-comparison:12:4:12:22::Comparison 'numpy.NaN is not x' should be 'not math.isnan(x)':UNDEFINED
-nan-comparison:13:4:13:18::Comparison 'numpy.NaN != x' should be 'not math.isnan(x)':UNDEFINED
-nan-comparison:15:4:15:18::Comparison 'x != numpy.NaN' should be 'not math.isnan(x)':UNDEFINED
-nan-comparison:16:5:16:22::Comparison 'x != float('nan')' should be 'not math.isnan(x)':UNDEFINED
-nan-comparison:17:7:17:21::Comparison 'x == numpy.NaN' should be 'math.isnan(x)':UNDEFINED
-nan-comparison:18:7:18:28::Comparison 'x is not float('nan')' should be 'not math.isnan(x)':UNDEFINED
-nan-comparison:19:3:19:17::Comparison 'x == numpy.NaN' should be 'math.isnan(x)':UNDEFINED
-nan-comparison:21:9:21:23::Comparison 'x is numpy.NaN' should be 'math.isnan(x)':UNDEFINED
+nan-comparison:7:4:7:18::Comparison 'x is numpy.NaN' should be 'math.isnan(x)':UNDEFINED
+nan-comparison:8:4:8:18::Comparison 'x == numpy.NaN' should be 'math.isnan(x)':UNDEFINED
+nan-comparison:9:4:9:21::Comparison 'x == float('nan')' should be 'math.isnan(x)':UNDEFINED
+nan-comparison:10:4:10:21::Comparison 'x is float('nan')' should be 'math.isnan(x)':UNDEFINED
+nan-comparison:11:4:11:26::Comparison 'numpy.NaN == numpy.NaN' should be 'math.isnan(numpy.NaN)':UNDEFINED
+nan-comparison:14:4:14:22::Comparison 'numpy.NaN is not x' should be 'not math.isnan(x)':UNDEFINED
+nan-comparison:15:4:15:18::Comparison 'numpy.NaN != x' should be 'not math.isnan(x)':UNDEFINED
+nan-comparison:17:4:17:18::Comparison 'x != numpy.NaN' should be 'not math.isnan(x)':UNDEFINED
+nan-comparison:18:5:18:22::Comparison 'x != float('nan')' should be 'not math.isnan(x)':UNDEFINED
+nan-comparison:19:4:19:22::Comparison 'x is not numpy.NaN' should be 'not math.isnan(x)':UNDEFINED
+nan-comparison:20:7:20:21::Comparison 'x == numpy.NaN' should be 'math.isnan(x)':UNDEFINED
+nan-comparison:21:7:21:28::Comparison 'x is not float('nan')' should be 'not math.isnan(x)':UNDEFINED
+nan-comparison:22:3:22:17::Comparison 'x == numpy.NaN' should be 'math.isnan(x)':UNDEFINED
+nan-comparison:24:9:24:23::Comparison 'x is numpy.NaN' should be 'math.isnan(x)':UNDEFINED
diff --git a/tests/functional/s/singleton_comparison.py b/tests/functional/s/singleton_comparison.py
index 771a1d3cb..8bfd0e887 100644
--- a/tests/functional/s/singleton_comparison.py
+++ b/tests/functional/s/singleton_comparison.py
@@ -9,6 +9,8 @@ f = x is 1
g = 123 is "123"
h = None is x
i = None == x # [singleton-comparison]
+i1 = True == x # [singleton-comparison]
+i2 = False == x # [singleton-comparison]
j = x != True # [singleton-comparison]
j1 = x != False # [singleton-comparison]
diff --git a/tests/functional/s/singleton_comparison.txt b/tests/functional/s/singleton_comparison.txt
index 12d341430..d095331de 100644
--- a/tests/functional/s/singleton_comparison.txt
+++ b/tests/functional/s/singleton_comparison.txt
@@ -3,10 +3,12 @@ singleton-comparison:5:4:5:13::Comparison 'x == True' should be 'x is True' if c
singleton-comparison:6:4:6:14::Comparison 'x == False' should be 'x is False' if checking for the singleton value False, or 'not x' if testing for falsiness:UNDEFINED
singleton-comparison:7:4:7:16::Comparison 'True == True' should be 'True is True' if checking for the singleton value True, or 'bool(True)' if testing for truthiness:UNDEFINED
singleton-comparison:11:4:11:13::Comparison 'None == x' should be 'None is x':UNDEFINED
-singleton-comparison:13:4:13:13::Comparison 'x != True' should be 'x is not True' if checking for the singleton value True, or 'not x' if testing for falsiness:UNDEFINED
-singleton-comparison:14:5:14:15::Comparison 'x != False' should be 'x is not False' if checking for the singleton value False, or 'bool(x)' if testing for truthiness:UNDEFINED
-singleton-comparison:15:5:15:14::Comparison 'x != None' should be 'x is not None':UNDEFINED
-singleton-comparison:16:7:16:16::Comparison 'x == True' should be 'x is True' if checking for the singleton value True, or 'x' if testing for truthiness:UNDEFINED
-singleton-comparison:17:7:17:17::Comparison 'x != False' should be 'x is not False' if checking for the singleton value False, or 'x' if testing for truthiness:UNDEFINED
-singleton-comparison:18:3:18:12::Comparison 'x == True' should be 'x is True' if checking for the singleton value True, or 'x' if testing for truthiness:UNDEFINED
-singleton-comparison:20:9:20:18::Comparison 'x == True' should be 'x is True' if checking for the singleton value True, or 'x' if testing for truthiness:UNDEFINED
+singleton-comparison:12:5:12:14::Comparison 'True == x' should be 'True is x' if checking for the singleton value True, or 'bool(x)' if testing for truthiness:UNDEFINED
+singleton-comparison:13:5:13:15::Comparison 'False == x' should be 'False is x' if checking for the singleton value False, or 'not x' if testing for falsiness:UNDEFINED
+singleton-comparison:15:4:15:13::Comparison 'x != True' should be 'x is not True' if checking for the singleton value True, or 'not x' if testing for falsiness:UNDEFINED
+singleton-comparison:16:5:16:15::Comparison 'x != False' should be 'x is not False' if checking for the singleton value False, or 'bool(x)' if testing for truthiness:UNDEFINED
+singleton-comparison:17:5:17:14::Comparison 'x != None' should be 'x is not None':UNDEFINED
+singleton-comparison:18:7:18:16::Comparison 'x == True' should be 'x is True' if checking for the singleton value True, or 'x' if testing for truthiness:UNDEFINED
+singleton-comparison:19:7:19:17::Comparison 'x != False' should be 'x is not False' if checking for the singleton value False, or 'x' if testing for truthiness:UNDEFINED
+singleton-comparison:20:3:20:12::Comparison 'x == True' should be 'x is True' if checking for the singleton value True, or 'x' if testing for truthiness:UNDEFINED
+singleton-comparison:22:9:22:18::Comparison 'x == True' should be 'x is True' if checking for the singleton value True, or 'x' if testing for truthiness:UNDEFINED