Skip to content

Commit bf52178

Browse files
authored
Move tests from TestComparison to functional tests (#5520)
* Remove some redundant tests
1 parent e5cb38f commit bf52178

File tree

5 files changed

+31
-134
lines changed

5 files changed

+31
-134
lines changed

tests/checkers/unittest_base.py

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -181,118 +181,6 @@ def UPPER(): #@
181181
self.checker.leave_module(func.root)
182182

183183

184-
class TestComparison(CheckerTestCase):
185-
CHECKER_CLASS = base.ComparisonChecker
186-
187-
def test_comparison(self) -> None:
188-
node = astroid.extract_node("foo == True")
189-
message = MessageTest(
190-
"singleton-comparison",
191-
node=node,
192-
args=(
193-
"'foo == True'",
194-
"'foo is True' if checking for the singleton value True, or 'bool(foo)' if testing for truthiness",
195-
),
196-
)
197-
with self.assertAddsMessages(message):
198-
self.checker.visit_compare(node)
199-
200-
node = astroid.extract_node("foo == False")
201-
message = MessageTest(
202-
"singleton-comparison",
203-
node=node,
204-
args=(
205-
"'foo == False'",
206-
"'foo is False' if checking for the singleton value False, or 'not foo' if testing for falsiness",
207-
),
208-
)
209-
with self.assertAddsMessages(message):
210-
self.checker.visit_compare(node)
211-
212-
node = astroid.extract_node("foo == None")
213-
message = MessageTest(
214-
"singleton-comparison", node=node, args=("'foo == None'", "'foo is None'")
215-
)
216-
with self.assertAddsMessages(message):
217-
self.checker.visit_compare(node)
218-
219-
node = astroid.extract_node("foo is float('nan')")
220-
message = MessageTest(
221-
"nan-comparison",
222-
node=node,
223-
args=("'foo is float('nan')'", "'math.isnan(foo)'"),
224-
)
225-
with self.assertAddsMessages(message):
226-
self.checker.visit_compare(node)
227-
228-
node = astroid.extract_node(
229-
"""
230-
import numpy
231-
foo != numpy.NaN
232-
"""
233-
)
234-
message = MessageTest(
235-
"nan-comparison",
236-
node=node,
237-
args=("'foo != numpy.NaN'", "'not math.isnan(foo)'"),
238-
)
239-
with self.assertAddsMessages(message):
240-
self.checker.visit_compare(node)
241-
242-
node = astroid.extract_node(
243-
"""
244-
import numpy as nmp
245-
foo is not nmp.NaN
246-
"""
247-
)
248-
message = MessageTest(
249-
"nan-comparison",
250-
node=node,
251-
args=("'foo is not nmp.NaN'", "'not math.isnan(foo)'"),
252-
)
253-
with self.assertAddsMessages(message):
254-
self.checker.visit_compare(node)
255-
256-
node = astroid.extract_node("True == foo")
257-
messages = (
258-
MessageTest(
259-
"singleton-comparison",
260-
node=node,
261-
args=(
262-
"'True == foo'",
263-
"'True is foo' if checking for the singleton value True, or 'bool(foo)' if testing for truthiness",
264-
),
265-
),
266-
)
267-
with self.assertAddsMessages(*messages):
268-
self.checker.visit_compare(node)
269-
270-
node = astroid.extract_node("False == foo")
271-
messages = (
272-
MessageTest(
273-
"singleton-comparison",
274-
node=node,
275-
args=(
276-
"'False == foo'",
277-
"'False is foo' if checking for the singleton value False, or 'not foo' if testing for falsiness",
278-
),
279-
),
280-
)
281-
with self.assertAddsMessages(*messages):
282-
self.checker.visit_compare(node)
283-
284-
node = astroid.extract_node("None == foo")
285-
messages = (
286-
MessageTest(
287-
"singleton-comparison",
288-
node=node,
289-
args=("'None == foo'", "'None is foo'"),
290-
),
291-
)
292-
with self.assertAddsMessages(*messages):
293-
self.checker.visit_compare(node)
294-
295-
296184
class TestNamePresets(unittest.TestCase):
297185
SNAKE_CASE_NAMES = {"tést_snake_case", "test_snake_case11", "test_https_200"}
298186
CAMEL_CASE_NAMES = {"téstCamelCase", "testCamelCase11", "testHTTP200"}

tests/functional/n/nan_comparison_check.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@
22
# pylint: disable=literal-comparison,comparison-with-itself, import-error
33
"""Test detection of NaN value comparison."""
44
import numpy
5+
56
x = 42
67
a = x is numpy.NaN # [nan-comparison]
78
b = x == numpy.NaN # [nan-comparison]
8-
c = x == float('nan') # [nan-comparison]
9+
c = x == float("nan") # [nan-comparison]
10+
d = x is float("nan") # [nan-comparison]
911
e = numpy.NaN == numpy.NaN # [nan-comparison]
1012
f = x is 1
1113
g = 123 is "123"
1214
h = numpy.NaN is not x # [nan-comparison]
1315
i = numpy.NaN != x # [nan-comparison]
1416

1517
j = x != numpy.NaN # [nan-comparison]
16-
j1 = x != float('nan') # [nan-comparison]
18+
j1 = x != float("nan") # [nan-comparison]
19+
k = x is not numpy.NaN # [nan-comparison]
1720
assert x == numpy.NaN # [nan-comparison]
18-
assert x is not float('nan') # [nan-comparison]
21+
assert x is not float("nan") # [nan-comparison]
1922
if x == numpy.NaN: # [nan-comparison]
2023
pass
2124
z = bool(x is numpy.NaN) # [nan-comparison]
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
nan-comparison:6:4:6:18::Comparison 'x is numpy.NaN' should be 'math.isnan(x)':UNDEFINED
2-
nan-comparison:7:4:7:18::Comparison 'x == numpy.NaN' should be 'math.isnan(x)':UNDEFINED
3-
nan-comparison:8:4:8:21::Comparison 'x == float('nan')' should be 'math.isnan(x)':UNDEFINED
4-
nan-comparison:9:4:9:26::Comparison 'numpy.NaN == numpy.NaN' should be 'math.isnan(numpy.NaN)':UNDEFINED
5-
nan-comparison:12:4:12:22::Comparison 'numpy.NaN is not x' should be 'not math.isnan(x)':UNDEFINED
6-
nan-comparison:13:4:13:18::Comparison 'numpy.NaN != x' should be 'not math.isnan(x)':UNDEFINED
7-
nan-comparison:15:4:15:18::Comparison 'x != numpy.NaN' should be 'not math.isnan(x)':UNDEFINED
8-
nan-comparison:16:5:16:22::Comparison 'x != float('nan')' should be 'not math.isnan(x)':UNDEFINED
9-
nan-comparison:17:7:17:21::Comparison 'x == numpy.NaN' should be 'math.isnan(x)':UNDEFINED
10-
nan-comparison:18:7:18:28::Comparison 'x is not float('nan')' should be 'not math.isnan(x)':UNDEFINED
11-
nan-comparison:19:3:19:17::Comparison 'x == numpy.NaN' should be 'math.isnan(x)':UNDEFINED
12-
nan-comparison:21:9:21:23::Comparison 'x is numpy.NaN' should be 'math.isnan(x)':UNDEFINED
1+
nan-comparison:7:4:7:18::Comparison 'x is numpy.NaN' should be 'math.isnan(x)':UNDEFINED
2+
nan-comparison:8:4:8:18::Comparison 'x == numpy.NaN' should be 'math.isnan(x)':UNDEFINED
3+
nan-comparison:9:4:9:21::Comparison 'x == float('nan')' should be 'math.isnan(x)':UNDEFINED
4+
nan-comparison:10:4:10:21::Comparison 'x is float('nan')' should be 'math.isnan(x)':UNDEFINED
5+
nan-comparison:11:4:11:26::Comparison 'numpy.NaN == numpy.NaN' should be 'math.isnan(numpy.NaN)':UNDEFINED
6+
nan-comparison:14:4:14:22::Comparison 'numpy.NaN is not x' should be 'not math.isnan(x)':UNDEFINED
7+
nan-comparison:15:4:15:18::Comparison 'numpy.NaN != x' should be 'not math.isnan(x)':UNDEFINED
8+
nan-comparison:17:4:17:18::Comparison 'x != numpy.NaN' should be 'not math.isnan(x)':UNDEFINED
9+
nan-comparison:18:5:18:22::Comparison 'x != float('nan')' should be 'not math.isnan(x)':UNDEFINED
10+
nan-comparison:19:4:19:22::Comparison 'x is not numpy.NaN' should be 'not math.isnan(x)':UNDEFINED
11+
nan-comparison:20:7:20:21::Comparison 'x == numpy.NaN' should be 'math.isnan(x)':UNDEFINED
12+
nan-comparison:21:7:21:28::Comparison 'x is not float('nan')' should be 'not math.isnan(x)':UNDEFINED
13+
nan-comparison:22:3:22:17::Comparison 'x == numpy.NaN' should be 'math.isnan(x)':UNDEFINED
14+
nan-comparison:24:9:24:23::Comparison 'x is numpy.NaN' should be 'math.isnan(x)':UNDEFINED

tests/functional/s/singleton_comparison.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
g = 123 is "123"
1010
h = None is x
1111
i = None == x # [singleton-comparison]
12+
i1 = True == x # [singleton-comparison]
13+
i2 = False == x # [singleton-comparison]
1214

1315
j = x != True # [singleton-comparison]
1416
j1 = x != False # [singleton-comparison]

tests/functional/s/singleton_comparison.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ singleton-comparison:5:4:5:13::Comparison 'x == True' should be 'x is True' if c
33
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
44
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
55
singleton-comparison:11:4:11:13::Comparison 'None == x' should be 'None is x':UNDEFINED
6-
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
7-
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
8-
singleton-comparison:15:5:15:14::Comparison 'x != None' should be 'x is not None':UNDEFINED
9-
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
10-
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
11-
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
12-
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
6+
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
7+
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
8+
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
9+
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
10+
singleton-comparison:17:5:17:14::Comparison 'x != None' should be 'x is not None':UNDEFINED
11+
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
12+
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
13+
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
14+
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

0 commit comments

Comments
 (0)