Skip to content

Commit 6a0fa4a

Browse files
Remove deletion of files in testing (#599)
1 parent abc3858 commit 6a0fa4a

14 files changed

+377
-549
lines changed

tests/test_descriptors_cli.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
from pathlib import Path
6-
import shutil
76

87
from ase.io import read
98
import pytest
@@ -13,6 +12,7 @@
1312
from janus_core.cli.janus import app
1413
from tests.utils import (
1514
assert_log_contains,
15+
chdir,
1616
check_output_files,
1717
clear_log_handlers,
1818
strip_ansi_codes,
@@ -31,16 +31,14 @@ def test_help():
3131
assert "Usage: janus descriptors [OPTIONS]" in strip_ansi_codes(result.stdout)
3232

3333

34-
def test_descriptors():
34+
def test_descriptors(tmp_path):
3535
"""Test calculating MLIP descriptors."""
36-
results_dir = Path("./janus_results")
37-
out_path = results_dir / "NaCl-descriptors.extxyz"
38-
log_path = results_dir / "NaCl-descriptors-log.yml"
39-
summary_path = results_dir / "NaCl-descriptors-summary.yml"
36+
with chdir(tmp_path):
37+
results_dir = Path("janus_results")
38+
out_path = results_dir / "NaCl-descriptors.extxyz"
39+
log_path = results_dir / "NaCl-descriptors-log.yml"
40+
summary_path = results_dir / "NaCl-descriptors-summary.yml"
4041

41-
assert not results_dir.exists()
42-
43-
try:
4442
result = runner.invoke(
4543
app,
4644
[
@@ -99,8 +97,6 @@ def test_descriptors():
9997
}
10098
check_output_files(descriptors_summary, output_files)
10199

102-
finally:
103-
shutil.rmtree(results_dir, ignore_errors=True)
104100
clear_log_handlers()
105101

106102

tests/test_eos_cli.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
from pathlib import Path
6-
import shutil
76

87
from ase.io import read
98
import pytest
@@ -13,6 +12,7 @@
1312
from janus_core.cli.janus import app
1413
from tests.utils import (
1514
assert_log_contains,
15+
chdir,
1616
check_output_files,
1717
clear_log_handlers,
1818
strip_ansi_codes,
@@ -31,17 +31,15 @@ def test_help():
3131
assert "Usage: janus eos [OPTIONS]" in strip_ansi_codes(result.stdout)
3232

3333

34-
def test_eos():
34+
def test_eos(tmp_path):
3535
"""Test calculating the equation of state."""
36-
results_dir = Path("./janus_results")
37-
eos_raw_path = results_dir / "NaCl-eos-raw.dat"
38-
eos_fit_path = results_dir / "NaCl-eos-fit.dat"
39-
log_path = results_dir / "NaCl-eos-log.yml"
40-
summary_path = results_dir / "NaCl-eos-summary.yml"
36+
with chdir(tmp_path):
37+
results_dir = Path("./janus_results")
38+
eos_raw_path = results_dir / "NaCl-eos-raw.dat"
39+
eos_fit_path = results_dir / "NaCl-eos-fit.dat"
40+
log_path = results_dir / "NaCl-eos-log.yml"
41+
summary_path = results_dir / "NaCl-eos-summary.yml"
4142

42-
assert not results_dir.exists()
43-
44-
try:
4543
result = runner.invoke(
4644
app,
4745
[
@@ -110,8 +108,6 @@ def test_eos():
110108
}
111109
check_output_files(eos_summary, output_files)
112110

113-
finally:
114-
shutil.rmtree(results_dir, ignore_errors=True)
115111
clear_log_handlers()
116112

117113

tests/test_geomopt_cli.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
from pathlib import Path
6-
import shutil
76

87
from ase import Atoms
98
from ase.io import read
@@ -14,6 +13,7 @@
1413
from janus_core.cli.janus import app
1514
from tests.utils import (
1615
assert_log_contains,
16+
chdir,
1717
check_output_files,
1818
clear_log_handlers,
1919
read_atoms,
@@ -33,16 +33,14 @@ def test_help():
3333
assert "Usage: janus geomopt [OPTIONS]" in strip_ansi_codes(result.stdout)
3434

3535

36-
def test_geomopt():
36+
def test_geomopt(tmp_path):
3737
"""Test geomopt calculation."""
38-
results_dir = Path("./janus_results")
39-
results_path = results_dir / "NaCl-opt.extxyz"
40-
log_path = results_dir / "NaCl-geomopt-log.yml"
41-
summary_path = results_dir / "NaCl-geomopt-summary.yml"
38+
with chdir(tmp_path):
39+
results_dir = Path("janus_results")
40+
results_path = results_dir / "NaCl-opt.extxyz"
41+
log_path = results_dir / "NaCl-geomopt-log.yml"
42+
summary_path = results_dir / "NaCl-geomopt-summary.yml"
4243

43-
assert not results_dir.exists()
44-
45-
try:
4644
result = runner.invoke(
4745
app,
4846
[
@@ -62,9 +60,6 @@ def test_geomopt():
6260
assert summary_path.exists()
6361
read_atoms(results_path)
6462

65-
finally:
66-
# Ensure files deleted if command fails
67-
shutil.rmtree(results_dir, ignore_errors=True)
6863
clear_log_handlers()
6964

7065

0 commit comments

Comments
 (0)