Commit 558acbaa authored by Tom Niget's avatar Tom Niget

Update test_runner.py

parent a7972639
# coding: utf-8
import argparse
import logging
#logging.basicConfig(level=logging.DEBUG)
from os import system, environ
from pathlib import Path
......@@ -17,12 +19,15 @@ load_dotenv()
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--compile", action="store_true")
parser.add_argument("-g", "--generate", action="store_true")
parser.add_argument("-o", "--only", nargs="+")
args = parser.parse_args()
def run_tests():
def run_tests():
for path in Path('tests').glob('*.py'):
if args.only and path.stem not in args.only:
continue
print(path.name)
if path.name.startswith('_'):
print("Skipping")
......@@ -30,6 +35,7 @@ def run_tests():
with open(path, "r", encoding="utf-8") as f:
code = f.read()
execute = "# norun" not in code
compile = "# nocompile" not in code
res = format_code(transpile(code, path.name, path))
#print(res)
name_cpp = path.with_suffix('.cpp')
......@@ -38,15 +44,13 @@ def run_tests():
print(".cpp generated")
if args.compile:
continue
if not execute:
print("Not executing", path.name)
continue
execute_str = "true" if (execute and not args.generate) else "false"
name_bin = path.with_suffix('').as_posix()
commands = [
f'bash -c "PYTHONPATH=stdlib python3 ./{path.as_posix()}"',
f'bash -c "export PYTHONPATH=stdlib; if {execute_str}; then python3 ./{path.as_posix()}; fi"',
]
if alt := environ.get("ALT_RUNNER"):
commands.append(alt.format(name_bin=name_bin, name_cpp_posix=name_cpp.as_posix()))
if compile and (alt := environ.get("ALT_RUNNER")):
commands.append(alt.format(name_bin=name_bin, name_cpp_posix=name_cpp.as_posix(), run_file=execute_str))
else:
print("no ALT_RUNNER")
for cmd in commands:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment