Skip to content

Commit 752ca38

Browse files
authored
Merge pull request #96 from daavid00/fixTests
Make possible to run tests independently
2 parents cd6ec3c + 3ae93ef commit 752ca38

File tree

7 files changed

+57
-39
lines changed

7 files changed

+57
-39
lines changed

tests/test_0_spe11a.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
"""Test the spe11a case"""
55

66
import os
7+
import pathlib
78
import subprocess
89

10+
dirname: pathlib.Path = pathlib.Path(__file__).parent
11+
912

1013
def test_spe11a():
1114
"""See configs/spe11a_data_format.txt"""
12-
cwd = os.getcwd()
13-
os.chdir(f"{cwd}/tests/configs")
15+
os.chdir(f"{dirname}/configs")
1416
subprocess.run(
1517
[
1618
"pyopmspe11",
@@ -33,5 +35,4 @@ def test_spe11a():
3335
],
3436
check=True,
3537
)
36-
assert os.path.exists(f"{cwd}/tests/configs/spe11a/data/spe11a_time_series.csv")
37-
os.chdir(cwd)
38+
assert os.path.exists(f"{dirname}/configs/spe11a/data/spe11a_time_series.csv")

tests/test_1_spe11b.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
"""Test the spe11b case"""
55

66
import os
7+
import pathlib
78
from pyopmspe11.core.pyopmspe11 import main
89

10+
dirname: pathlib.Path = pathlib.Path(__file__).parent
11+
912

1013
def test_spe11b():
1114
"""See configs/input.txt"""
12-
cwd = os.getcwd()
13-
os.chdir(f"{os.getcwd()}/tests/configs")
15+
os.chdir(f"{dirname}/configs")
1416
main()
15-
os.chdir(cwd)
16-
assert os.path.exists(f"{cwd}/tests/configs/output/flow/OUTPUT.UNRST")
17+
assert os.path.exists(f"{dirname}/configs/output/flow/OUTPUT.UNRST")

tests/test_2_spe11c.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44
"""Test the spe11c case"""
55

66
import os
7+
import pathlib
78
import subprocess
89

10+
dirname: pathlib.Path = pathlib.Path(__file__).parent
11+
912

1013
def test_spe11c():
1114
"""See configs/spe11c.txt"""
12-
cwd = os.getcwd()
13-
os.chdir(f"{os.getcwd()}/tests/configs")
15+
os.chdir(f"{dirname}/configs")
1416
subprocess.run(
1517
[
1618
"pyopmspe11",
17-
"-i",
18-
"spe11c.txt",
1919
"-o",
2020
"spe11c",
21+
"-i",
22+
"spe11c.txt",
2123
"-m",
2224
"all",
2325
"-g",
@@ -29,5 +31,4 @@ def test_spe11c():
2931
],
3032
check=True,
3133
)
32-
assert os.path.exists(f"{cwd}/tests/configs/spe11c/figures/spe11c_temp_2Dmaps.png")
33-
os.chdir(cwd)
34+
assert os.path.exists(f"{dirname}/configs/spe11c/figures/spe11c_temp_2Dmaps.png")

tests/test_3_data.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
"""Test the scrip to write the data as required in the benchmark"""
55

66
import os
7+
import pathlib
78
from pyopmspe11.visualization.data import main
89

10+
dirname: pathlib.Path = pathlib.Path(__file__).parent
11+
912

1013
def test_data():
1114
"""See visualization/data.py"""
12-
cwd = os.getcwd()
13-
os.mkdir(f"{cwd}/tests/configs/output/data")
14-
os.chdir(f"{cwd}/tests/configs")
15+
message = "Please run first test_1_spe11b"
16+
assert os.path.exists(f"{dirname}/configs/output"), message
17+
os.mkdir(f"{dirname}/configs/output/data")
18+
os.chdir(f"{dirname}/configs")
1519
main()
16-
assert os.path.exists(f"{cwd}/tests/configs/output/data/spe11b_time_series.csv")
17-
os.chdir(cwd)
20+
assert os.path.exists(f"{dirname}/configs/output/data/spe11b_time_series.csv")

tests/test_4_plot.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44
"""Test the scrip to plot the data"""
55

66
import os
7+
import pathlib
78
from pyopmspe11.visualization.plotting import main
89

10+
dirname: pathlib.Path = pathlib.Path(__file__).parent
11+
912

1013
def test_plot():
1114
"""See visualization/plotting.py"""
12-
cwd = os.getcwd()
13-
os.chdir(f"{cwd}/tests/configs")
14-
os.mkdir(f"{cwd}/tests/configs/output/figures")
15+
message = "Please run first test_1_spe11b"
16+
assert os.path.exists(f"{dirname}/configs/output"), message
17+
message = "Please run first test_3_data"
18+
assert os.path.exists(f"{dirname}/configs/output/data"), message
19+
os.chdir(f"{dirname}/configs")
20+
os.mkdir(f"{dirname}/configs/output/figures")
1521
main()
16-
assert os.path.exists(f"{cwd}/tests/configs/output/figures/spe11b_sparse_data.png")
17-
os.chdir(cwd)
22+
assert os.path.exists(f"{dirname}/configs/output/figures/spe11b_sparse_data.png")

tests/test_5_compare.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,30 @@
44
"""Test the scrip to compare the data for different runs"""
55

66
import os
7+
import pathlib
8+
9+
dirname: pathlib.Path = pathlib.Path(__file__).parent
710

811

912
def test_comparison():
1013
"""See visualization/plot.py"""
11-
cwd = os.getcwd()
12-
os.system(f"mkdir {cwd}/tests/configs/test_compare")
13-
os.system(f"mkdir {cwd}/tests/configs/test_compare/spe11c_ens1")
14-
os.system(f"mkdir {cwd}/tests/configs/test_compare/spe11c_ens2")
14+
message = "Please run first test_2_spe11c"
15+
assert os.path.exists(f"{dirname}/configs/spe11c"), message
16+
os.system(f"mkdir {dirname}/configs/test_compare")
17+
os.system(f"mkdir {dirname}/configs/test_compare/spe11c_ens1")
18+
os.system(f"mkdir {dirname}/configs/test_compare/spe11c_ens2")
1519
os.system(
16-
f"cp -R {cwd}/tests/configs/spe11c/. {cwd}/tests/configs/test_compare/spe11c_ens1"
20+
f"cp -R {dirname}/configs/spe11c/. {dirname}/configs/test_compare/spe11c_ens1"
1721
)
1822
os.system(
19-
f"cp -R {cwd}/tests/configs/spe11c/. {cwd}/tests/configs/test_compare/spe11c_ens2"
23+
f"cp -R {dirname}/configs/spe11c/. {dirname}/configs/test_compare/spe11c_ens2"
2024
)
21-
os.chdir(f"{cwd}/tests/configs/test_compare")
25+
os.chdir(f"{dirname}/configs/test_compare")
2226
os.system("pyopmspe11 -c spe11c -m performance")
23-
os.chdir(f"{cwd}/tests/configs")
27+
os.chdir(f"{dirname}/configs")
2428
assert os.path.exists(
25-
f"{cwd}/tests/configs/test_compare/compare/spe11c_performance_detailed.png"
29+
f"{dirname}/configs/test_compare/compare/spe11c_performance_detailed.png"
2630
)
2731
assert os.path.exists(
28-
f"{cwd}/tests/configs/test_compare/compare/spe11c_performance.png"
32+
f"{dirname}/configs/test_compare/compare/spe11c_performance.png"
2933
)
30-
os.chdir(cwd)

tests/test_6_data_format.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,21 @@
44
"""Test the format of the generated data for the three cases"""
55

66
import os
7+
import pathlib
78
import subprocess
89
from subprocess import PIPE, Popen
910

11+
dirname: pathlib.Path = pathlib.Path(__file__).parent
12+
1013

1114
def test_format():
1215
"""See https://github.com/Simulation-Benchmarks/11thSPE-CSP/blob/
1316
main/evaluation/check_format.py"""
14-
cwd = os.getcwd()
15-
os.chdir(f"{cwd}/tests/configs")
16-
os.system("rm -rf spe11c")
17+
message = "Please run first test_0_spe11a"
18+
assert os.path.exists(f"{dirname}/configs/spe11a"), message
19+
os.chdir(f"{dirname}/configs")
20+
if os.path.exists(f"{dirname}/configs/spe11c"):
21+
os.system(f"rm -rf {dirname}/configs/spe11c")
1722
subprocess.run(
1823
[
1924
"pyopmspe11",
@@ -84,4 +89,3 @@ def test_format():
8489
) as process:
8590
check = str(process.communicate()[0])[4:-3]
8691
assert check.count("Successfully") == 2
87-
os.chdir(cwd)

0 commit comments

Comments
 (0)