Python: iter str/seq query gives non-useful results with tests

This commit is contained in:
Rasmus Wriedt Larsen
2020-04-07 11:26:56 +02:00
parent 46ecbef8f2
commit 94ccc16f85
2 changed files with 21 additions and 0 deletions

View File

@@ -1 +1,3 @@
| statements_test.py:21:5:21:19 | For | Iteration over $@, of class list, may also iterate over $@. | statements_test.py:20:13:20:33 | ControlFlowNode for List | sequence | statements_test.py:18:13:18:26 | ControlFlowNode for Str | string |
| supress_uses_from_tests.py:6:5:6:20 | For | Iteration over $@, of class list, may also iterate over $@. | supress_uses_from_tests.py:9:5:9:26 | ControlFlowNode for List | sequence | supress_uses_from_tests.py:19:17:19:27 | ControlFlowNode for Str | string |
| supress_uses_from_tests.py:6:5:6:20 | For | Iteration over $@, of class list, may also iterate over $@. | supress_uses_from_tests.py:15:13:15:34 | ControlFlowNode for List | sequence | supress_uses_from_tests.py:19:17:19:27 | ControlFlowNode for Str | string |

View File

@@ -0,0 +1,19 @@
# This example illustrates that all valid results are not useful.
# The alert in this file should be suppressed (TODO).
# see https://github.com/Semmle/ql/issues/3207
def foo(l):
for (k, v) in l:
print(k, v)
foo([('a', 42), ('b', 43)])
import unittest
class FooTest(unittest.TestCase):
def test_valid(self):
foo([('a', 42), ('b', 43)])
def test_not_valid(self):
with six.assertRaises(self, ValueError):
foo("not valid")