Skip to content

Commit 7dabcf6

Browse files
committed
Port smoketests to python
1 parent 1c2a840 commit 7dabcf6

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

tests/smoke-tests/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
configs/*
1+
external
File renamed without changes.

tests/smoke-tests/smoke_test.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,39 @@
33
# Provide files to test in the "./configs/"-folder. This script will test all files (including those in subfolders)
44
# whose names end in the ".xml"-extension.
55

6-
import glob
7-
import os
6+
import git
7+
import pathlib
8+
import pytest
89

910
from precice_config_graph import graph
1011
from precice_config_graph import xml_processing
1112

1213

13-
def test_smoke():
14-
search_pattern = os.getcwd() + "/tests/smoke-tests/configs/**/*.xml"
15-
files = glob.glob(search_pattern, recursive=True)
14+
EXTERNAL_DIR = pathlib.Path(__file__).parent / "external"
15+
PRECICE_DIR = EXTERNAL_DIR / "precice"
16+
TUTORIALS_DIR = EXTERNAL_DIR / "tutorials"
1617

17-
print(f"Testing all {len(files)} files matching {search_pattern}")
1818

19-
errors = []
20-
for file in glob.glob(search_pattern, recursive=True):
21-
try:
22-
xml = xml_processing.parse_file(file)
23-
G = graph.get_graph(xml)
24-
except Exception as e:
25-
errors.append((file, e))
19+
def get_configs():
20+
if not PRECICE_DIR.exists():
21+
git.Repo.clone_from(
22+
"https://github.com/precice/precice.git", PRECICE_DIR, depth=1
23+
)
2624

27-
if errors:
28-
for (file, error) in errors:
29-
print(f"Error in {file}:\n {error}")
30-
else:
31-
print("Graph generation did not fail on any files provided")
25+
if not TUTORIALS_DIR.exists():
26+
git.Repo.clone_from(
27+
"https://github.com/precice/tutorials.git", TUTORIALS_DIR, depth=1
28+
)
3229

33-
assert not errors, f"{len(errors)} files produced errors"
30+
return list(TUTORIALS_DIR.rglob("*/precice-config.xml")) + list(
31+
PRECICE_DIR.rglob("tests/*/precice-config.xml")
32+
)
33+
34+
35+
@pytest.mark.parametrize("config", get_configs())
36+
def test_smoke(config):
37+
print(f"Testing graph generation of {config}")
38+
xml = xml_processing.parse_file(config)
39+
assert xml is not None, "Parsing failed"
40+
G = graph.get_graph(xml)
41+
assert G

tox.ini

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22
requires =
33
tox>=4.27
44
env_list =
5-
py3,package
5+
py3
6+
package
67

78
[testenv]
89
description = run the tests with pytest
910
package = wheel
1011
wheel_build_env = .pkg
1112
deps =
13+
gitpython
1214
pytest>=6
1315
commands =
1416
pytest {tty:--color=yes} {posargs}
1517

1618
[testenv:package]
1719
description = build package
1820
package = skip
19-
wheel_build_env =
20-
deps = build
21-
commands = pyproject-build
21+
wheel_build_env =
22+
deps =
23+
build
24+
commands =
25+
pyproject-build

0 commit comments

Comments
 (0)