Files
codeql/python/ql/test/experimental/dataflow/validTest.py
Rasmus Wriedt Larsen 93c9f59e86 Python: Extract version specific coverage/classes.py tests
Since we can analyze operator.py from Python3, but not in Python 2
(since it's implemented in C), we get a difference for the index tests.

note: `operator.length_hint` is only available in Python 3.4 and later,
so would always fail under Python 2.
2023-03-20 15:39:20 +01:00

81 lines
2.4 KiB
Python

import sys
def check_output(outtext, f):
if outtext == "OK\n":
pass
else:
raise RuntimeError("Function failed", outtext, f.__name__)
def check_test_function(f):
from io import StringIO
import sys
capturer = StringIO()
old_stdout = sys.stdout
sys.stdout = capturer
f()
sys.stdout = old_stdout
check_output(capturer.getvalue(), f)
def check_async_test_function(f):
from io import StringIO
import sys
import asyncio
capturer = StringIO()
old_stdout = sys.stdout
sys.stdout = capturer
asyncio.run(f())
sys.stdout = old_stdout
check_output(capturer.getvalue(), f)
def check_tests_valid(testFile):
import importlib
tests = importlib.import_module(testFile)
for i in dir(tests):
# print("Considering", i)
if i.startswith("test_"):
item = getattr(tests, i)
if callable(item):
print("Checking", testFile, item.__name__)
check_test_function(item)
elif i.startswith("atest_"):
item = getattr(tests, i)
if callable(item):
print("Checking", testFile, item.__name__)
check_async_test_function(item)
def check_tests_valid_after_version(testFile, version):
if sys.version_info[:2] >= version:
print("INFO: Will run tests in", testFile, "since we're running Python", version, "or newer")
check_tests_valid(testFile)
else:
print("WARN: Will not run tests in", testFile, "since we're running Python", sys.version_info[:2], "and need", version, "or newer")
if __name__ == "__main__":
check_tests_valid("coverage.classes")
check_tests_valid("coverage.test")
check_tests_valid("coverage.argumentPassing")
check_tests_valid("coverage.datamodel")
check_tests_valid("coverage-py2.classes")
check_tests_valid("coverage-py3.classes")
check_tests_valid("variable-capture.in")
check_tests_valid("variable-capture.nonlocal")
check_tests_valid("variable-capture.dict")
check_tests_valid("module-initialization.multiphase")
check_tests_valid("fieldflow.test")
check_tests_valid_after_version("match.test", (3, 10))
check_tests_valid("exceptions.test")
check_tests_valid_after_version("exceptions.test_group", (3, 11))
# The below fails when trying to import modules
# check_tests_valid("module-initialization.test")
# check_tests_valid("module-initialization.testOnce")