|
3 | 3 | # Provide files to test in the "./configs/"-folder. This script will test all files (including those in subfolders) |
4 | 4 | # whose names end in the ".xml"-extension. |
5 | 5 |
|
6 | | -import glob |
7 | | -import os |
| 6 | +import git |
| 7 | +import pathlib |
| 8 | +import pytest |
8 | 9 |
|
9 | 10 | from precice_config_graph import graph |
10 | 11 | from precice_config_graph import xml_processing |
11 | 12 |
|
12 | 13 |
|
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" |
16 | 17 |
|
17 | | - print(f"Testing all {len(files)} files matching {search_pattern}") |
18 | 18 |
|
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 | + ) |
26 | 24 |
|
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 | + ) |
32 | 29 |
|
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 |
0 commit comments