Templates: Updates template generator scripts
"""
Tests for QCFractals CLI
"""
+import ast
import os
import time
@@ -8,8 +9,6 @@ import pytest
from qcfractal import testing
-from tempfile import TemporaryDirectory
-
# def _run_tests()
_options = {"coverage": True, "dump_stdout": True}
@@ -75,11 +74,13 @@ def test_manager_fireworks_config_boot(active_server):
assert testing.run_process(args, **_options)
+@testing.mark_slow
@pytest.mark.parametrize("adapter", [
"dask",
"parsl",
- pytest.param("fireworks", marks=pytest.mark.xfail),
- pytest.param("executor", marks=pytest.mark.xfail)])
+ # pytest.param("fireworks", marks=pytest.mark.xfail),
+ # pytest.param("executor", marks=pytest.mark.xfail)
+])
@pytest.mark.parametrize("scheduler", [
"slurm",
"pbs",
@@ -87,43 +88,16 @@ def test_manager_fireworks_config_boot(active_server):
"lsf",
pytest.param("garbage", marks=pytest.mark.xfail)
])
-def test_cli_template_generator(adapter, scheduler):
-
- def ensure_test_is_set_and_exit_head(text: str):
- match_string = "TEST_RUN = True"
- split_lines = text.splitlines()
- for counter, line in enumerate(split_lines):
- if match_string in line:
- # This exits early, before imports and will ensure at least basic syntax is correct
- base = "\n".join(split_lines[:counter+1])
- base += "\nimport sys\nsys.exit()\n"
- base += "\n".join(split_lines[counter:])
- return base
- # Should only reach this if no line found
- raise AssertionError('String "{}" not found in file'.format(match_string))
-
- def parse_template(path):
- with open(path, 'r') as throwaway:
- new_throw = ensure_test_is_set_and_exit_head(throwaway.read())
- return new_throw
-
- with TemporaryDirectory() as td:
- throwaway_path = os.path.join(td, "throwaway.py")
- args = ["qcfractal-template", adapter, scheduler, "--test", "-o", throwaway_path]
- try:
- testing.run_process(args, **_options)
- except ValueError:
- return # Certain not implemented items
- # Ensure bottom of file is valid
- # Known bad combos
+def test_cli_template_generator(adapter, scheduler, tmp_path):
if adapter == "parsl" and scheduler == "lsf":
pytest.xfail("Parsl has no LSF implementation")
- with pytest.raises(FileNotFoundError):
- new_throw = parse_template(throwaway_path)
- else:
- new_throw = parse_template(throwaway_path)
- new_throw_path = os.path.join(td, "new_throw.py")
- with open(new_throw_path, 'w') as f:
- f.write(new_throw)
- new_args = ["python", new_throw_path]
- assert testing.run_process(new_args, **_options)
+
+ tmpl_path = tmp_path / "tmp_template.py"
+ args = ["qcfractal-template", adapter, scheduler, "--test", "-o", str(tmpl_path)]
+ testing.run_process(args)
+
+ with open(tmpl_path, 'r') as handle:
+ data = handle.read()
+
+ # Will throw a syntax error if incorrect
+ c = ast.parse(data)
