Python: Add 2/3 specific query tests.

This commit is contained in:
Mark Shannon
2019-02-08 15:04:44 +00:00
parent 0558b58193
commit 52ddd79cab
152 changed files with 919 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
| test.py:5:11:5:11 | x | x may have a different value in Python 3, as the $@ will not be in scope. | test.py:4:12:4:12 | x | list comprehension variable |
| test.py:10:11:10:11 | y | y may have a different value in Python 3, as the $@ will not be in scope. | test.py:9:12:9:12 | y | list comprehension variable |

View File

@@ -0,0 +1 @@
Variables/LeakingListComprehension.ql

View File

@@ -0,0 +1,49 @@
from __future__ import print_function
def undefined_in_3():
[x for x in range(3)]
print(x)
def different_in_3():
y = 10
[y for y in range(3)]
print(y)
def ok():
[z for z in range(4)]
#FP observed in sembuild
def use_in_loop(seq):
[x for x in range(3)]
for x in seq:
use(x) #x redefined -- fine in 2 and 3.
def test_6395(dev):
ret = {}
res = foo(dev)
if not res:
return False
for line in res.splitlines(): # pylint: disable=no-member
line = line.strip()
if not line:
continue
key, val = [val.strip() for val in bar(line)]
if not (key and val):
continue
mval = None
if ' ' in val:
rval, mval = [val.strip() for val in bar(val)]
mval = mval[1:-1]
else:
rval = val
return ret
def test_6441(seq):
for var in seq:
foo(var)
[var for var in bar()]

View File

@@ -0,0 +1,4 @@
| UndefinedExport.py:3:18:3:20 | Str | The name 'y' is exported by __all__ but is not defined. |
| UndefinedExport.py:3:23:3:25 | Str | The name 'z' is exported by __all__ but is not defined. |
| UndefinedExport.py:3:28:3:35 | Str | The name 'module' is exported by __all__ but is not defined. |
| package/__init__.py:1:23:1:34 | Str | The name 'not_exists' is exported by __all__ but is not defined. |

View File

@@ -0,0 +1,9 @@
__all__ = [ "x", "y", "z", "module" ]
x = 1
if 0:
y = 2
import package.module

View File

@@ -0,0 +1 @@
Variables/UndefinedExport.ql

View File

@@ -0,0 +1 @@
Variables/UndefinedGlobal.ql

View File

@@ -0,0 +1,12 @@
def const_xrange():
for i in xrange(4):
x = i
return x
def rec1(a):
if a > 0:
rec1(a - 1)
def rec2(b):
[rec2(b - 1) for c in range(b)]

View File

@@ -0,0 +1 @@
Variables/UninitializedLocal.ql

View File

@@ -0,0 +1 @@
semmle-extractor-options: --max-import-depth=2

View File

@@ -0,0 +1 @@
__all__ = [ "module", "not_exists" ]

View File

@@ -0,0 +1,8 @@
from other import setup
execfile('x/_version.py')
setup(
name='x',
version=__version__
)