Skip to content
Snippets Groups Projects
Commit ae40963c authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Add fixture for sample config modules. Add test cases for CLI.

parent 722779b7
No related branches found
No related tags found
1 merge request!2Refactor Configuration System & Extend Documentation
Pipeline #70675 failed
import pytest
from os import path
@pytest.fixture(autouse=True)
......@@ -9,3 +10,11 @@ def prepare_composer(doctest_namespace):
sfg = SfgComposer(SfgContext())
doctest_namespace["sfg"] = sfg
DATA_DIR = path.join(path.split(__file__)[0], "tests/data")
@pytest.fixture
def sample_config_module():
return path.join(DATA_DIR, "project_config.py")
......@@ -3,6 +3,6 @@ testpaths = src/pystencilssfg tests/
python_files = "test_*.py"
# Need to ignore the generator scripts, otherwise they would be executed
# during test collection
addopts = --doctest-modules --ignore=tests/generator_scripts/scripts
addopts = --doctest-modules --ignore=tests/generator_scripts/scripts --ignore=--ignore=tests/data
doctest_optionflags = NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL
......@@ -316,6 +316,7 @@ class CommandLineParameters:
h_ext = None
src_ext = None
extensions = tuple(ext.strip() for ext in extensions)
extensions = tuple((ext[1:] if ext[0] == "." else ext) for ext in extensions)
HEADER_FILE_EXTENSIONS = {"h", "hpp", "hxx", "h++", "cuh"}
......
......@@ -9,9 +9,6 @@ from pystencilssfg.config import (
)
DATA_DIR = path.join(path.split(__file__)[0], "data")
def test_defaults():
cfg = SfgConfig()
......@@ -57,7 +54,7 @@ def test_override():
assert cfg1.clang_format.binary == "bogus"
def test_from_commandline():
def test_from_commandline(sample_config_module):
from argparse import ArgumentParser
parser = ArgumentParser()
......@@ -74,9 +71,8 @@ def test_from_commandline():
assert cfg.extensions.header == "h++"
assert cfg.extensions.impl == "c++"
config_module = path.join(DATA_DIR, "project_config.py")
args = parser.parse_args(
["--sfg-output-dir", "gen_sources", "--sfg-config-module", config_module]
["--sfg-output-dir", "gen_sources", "--sfg-config-module", sample_config_module]
)
cli_args = CommandLineParameters(args)
cfg = cli_args.get_config()
......@@ -95,16 +91,15 @@ def test_from_commandline():
assert cli_args.configuration_module.magic_number == 0xCAFE
def test_generator_config(monkeypatch, tmp_path):
def test_generator_config(monkeypatch, tmp_path, sample_config_module):
import sys
config_module = path.join(DATA_DIR, "project_config.py")
args = [
"genscript.py",
"--sfg-file-extensions",
".c++,.h++",
"--sfg-config-module",
config_module,
sample_config_module,
"test1",
"test2",
]
......
import sympy as sp
from pystencils import TypedSymbol, fields, kernel
from pystencilssfg import SourceFileGenerator, SfgConfiguration
from pystencilssfg import SourceFileGenerator
with SourceFileGenerator() as sfg:
α = TypedSymbol("alpha", "float32")
......
import subprocess
def test_list_files():
output_dir = "/my/output/directory"
args = [
"sfg-cli",
"list-files",
"--sfg-output-dir",
output_dir,
"--sfg-file-extensions",
"cu, cuh",
"genscript.py",
]
result = subprocess.run(args, capture_output=True, text=True)
assert result.returncode == 0
assert (
result.stdout
== "/my/output/directory/genscript.cuh /my/output/directory/genscript.cu\n"
)
def test_list_files_headeronly():
output_dir = "/my/output/directory"
args = [
"sfg-cli",
"list-files",
"--sfg-output-dir",
output_dir,
"--sfg-output-mode",
"header-only",
"genscript.py",
]
result = subprocess.run(args, capture_output=True, text=True)
assert result.returncode == 0
assert result.stdout == "/my/output/directory/genscript.hpp\n"
def test_list_files_with_config_module(sample_config_module):
args = [
"sfg-cli",
"list-files",
"--sfg-config-module",
sample_config_module,
"genscript.py",
]
result = subprocess.run(args, capture_output=True, text=True)
assert result.returncode == 0
assert (
result.stdout
== "generated_sources/genscript.hpp generated_sources/genscript.cpp\n"
)
def test_make_find_module(tmp_path):
args = ["sfg-cli", "cmake", "make-find-module"]
result = subprocess.run(args, cwd=str(tmp_path))
assert result.returncode == 0
expected_path = tmp_path / "FindPystencilsSfg.cmake"
assert expected_path.exists()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment