diff --git a/conftest.py b/conftest.py index e1d0cdda1b64ec9eff93367589fe3a08d975deb7..1c85902fdb05c4799fd18c2b4ac1710fca3ae933 100644 --- a/conftest.py +++ b/conftest.py @@ -1,4 +1,5 @@ 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") diff --git a/pytest.ini b/pytest.ini index 94a3a6c5cd76967b094d0e26bab983291057461d..5d05ec3d7d2227a533d336ab67e403e5b208b8a8 100644 --- a/pytest.ini +++ b/pytest.ini @@ -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 diff --git a/src/pystencilssfg/config.py b/src/pystencilssfg/config.py index 9cbb5c5cd1c634ea156b253aea1b5d913dd60b5f..8562e0ef9ebf1a396ee35bfadeefe4c2e3dc67fd 100644 --- a/src/pystencilssfg/config.py +++ b/src/pystencilssfg/config.py @@ -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"} diff --git a/tests/generator/data/project_config.py b/tests/data/project_config.py similarity index 100% rename from tests/generator/data/project_config.py rename to tests/data/project_config.py diff --git a/tests/generator/test_config.py b/tests/generator/test_config.py index 66b0a9f75bf8bc997e8dca04b2be9f8e454604ca..a696d7ba2ed533fcf651f9d8875650d14af94f76 100644 --- a/tests/generator/test_config.py +++ b/tests/generator/test_config.py @@ -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", ] diff --git a/tests/generator_scripts/scripts/Variables.py b/tests/generator_scripts/scripts/Variables.py index 9fd4e0027104451738abea72e15084047cf4465e..bcc85e4cba1b75364b500628b8b10fdb24a7470c 100644 --- a/tests/generator_scripts/scripts/Variables.py +++ b/tests/generator_scripts/scripts/Variables.py @@ -1,7 +1,6 @@ -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") diff --git a/tests/integration/test_cli.py b/tests/integration/test_cli.py new file mode 100644 index 0000000000000000000000000000000000000000..485c43e856e04b5182ce84f2bfaf8ec51fafdaf2 --- /dev/null +++ b/tests/integration/test_cli.py @@ -0,0 +1,68 @@ +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()