Skip to content

Commit 02e6c3c

Browse files
Migrate tmpdir fixture to new tmp_path (#615)
1 parent 36fdda5 commit 02e6c3c

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

openff/evaluator/_tests/test_properties/test_enthalpy.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from openff.toolkit.topology import Topology
88
from openff.toolkit.typing.engines.smirnoff import ForceField
99
from openff.units import unit
10-
from openff.utilities.utilities import get_data_dir_path
10+
from openff.utilities.utilities import get_data_dir_path, temporary_cd
1111
from openmm.openmm import System as OpenMMSystem
1212

1313
from openff.evaluator.datasets import PropertyPhase
@@ -77,7 +77,9 @@ class TestEnthalpyOfMixing:
7777
],
7878
)
7979
def test_mole_fractions_direct_simulation(
80-
self, input_mole_fractions, output_mole_fractions, tmpdir
80+
self,
81+
input_mole_fractions,
82+
output_mole_fractions,
8183
):
8284
"""
8385
This test *only* checks the part where mole fractions are weighted.
@@ -106,7 +108,7 @@ def test_mole_fractions_direct_simulation(
106108
)
107109

108110
physical_property = _get_dummy_enthalpy_of_mixing(substance)
109-
with tmpdir.as_cwd():
111+
with temporary_cd():
110112
here = pathlib.Path(".")
111113

112114
# generate force field and metadata
@@ -191,7 +193,7 @@ def test_mole_fractions_direct_simulation(
191193
output_mole_fractions[i] * 10,
192194
)
193195

194-
def test_expected_output_from_production_simulation(self, tmpdir):
196+
def test_expected_output_from_production_simulation(self):
195197
"""
196198
This is an integration test of sorts,
197199
constructed to test expected mole fractions. See Issue #575.
@@ -245,7 +247,7 @@ def test_expected_output_from_production_simulation(self, tmpdir):
245247
)
246248

247249
abs_path = data_directory.resolve()
248-
with tmpdir.as_cwd():
250+
with temporary_cd():
249251
tmp_path = pathlib.Path(".")
250252
# copy data files over from data_directory
251253
for path in abs_path.iterdir():

openff/evaluator/_tests/test_protocols/test_analysis.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ def test_average_free_energies_protocol():
113113
)
114114

115115

116-
def test_compute_dipole_moments(tmpdir):
116+
def test_compute_dipole_moments(tmp_path):
117117
coordinate_path = get_data_filename("test/trajectories/water.pdb")
118118
trajectory_path = get_data_filename("test/trajectories/water.dcd")
119119

120120
# Build a system object for water
121-
force_field_path = os.path.join(tmpdir, "ff.json")
121+
force_field_path = os.path.join(tmp_path, "ff.json")
122122

123123
with open(force_field_path, "w") as file:
124124
file.write(build_tip3p_smirnoff_force_field().json())
@@ -127,13 +127,13 @@ def test_compute_dipole_moments(tmpdir):
127127
assign_parameters.force_field_path = force_field_path
128128
assign_parameters.coordinate_file_path = coordinate_path
129129
assign_parameters.substance = Substance.from_components("O")
130-
assign_parameters.execute(str(tmpdir))
130+
assign_parameters.execute(str(tmp_path))
131131

132132
# TODO - test gradients when TIP3P library charges added.
133133
protocol = ComputeDipoleMoments("")
134134
protocol.parameterized_system = assign_parameters.parameterized_system
135135
protocol.trajectory_path = trajectory_path
136-
protocol.execute(str(tmpdir))
136+
protocol.execute(str(tmp_path))
137137

138138
assert len(protocol.dipole_moments) == 10
139139
assert protocol.dipole_moments.value.shape[1] == 3

openff/evaluator/_tests/test_storage/test_local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from openff.evaluator.storage import LocalFileStorage
88

99

10-
def test_root_directory(tmpdir):
11-
local_storage_path = os.path.join(tmpdir, "stored-data")
10+
def test_root_directory(tmp_path):
11+
local_storage_path = os.path.join(tmp_path, "stored-data")
1212
local_storage = LocalFileStorage(root_directory=local_storage_path)
1313

1414
assert os.path.isdir(local_storage_path)

openff/evaluator/_tests/test_utils/test_openmm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def test_system_subset_virtual_site_water(add_nonwater):
423423
@pytest.mark.parametrize(
424424
"smirks, all_zeros", [("[#6X4:1]", True), ("[#8:1]", False), (None, False)]
425425
)
426-
def test_compute_gradients(tmpdir, smirks, all_zeros):
426+
def test_compute_gradients(tmp_path, smirks, all_zeros):
427427
# Load a short trajectory.
428428
coordinate_path = get_data_filename("test/trajectories/water.pdb")
429429
trajectory_path = get_data_filename("test/trajectories/water.dcd")
@@ -505,7 +505,7 @@ def test_update_context_with_positions(box_vectors):
505505
)
506506

507507

508-
def test_update_context_with_pdb(tmpdir):
508+
def test_update_context_with_pdb(tmp_path):
509509
force_field = hydrogen_chloride_force_field(True, False, True)
510510

511511
topology: Topology = Molecule.from_mapped_smiles("[Cl:1][H:2]").to_topology()
@@ -517,7 +517,7 @@ def test_update_context_with_pdb(tmpdir):
517517

518518
positions = numpy.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]]) * openmm_unit.angstrom
519519

520-
pdb_path = os.path.join(tmpdir, "tmp.pdb")
520+
pdb_path = os.path.join(tmp_path, "tmp.pdb")
521521
topology.to_file(pdb_path, positions)
522522

523523
pdb_file = PDBFile(pdb_path)

openff/evaluator/_tests/test_utils/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_get_nested_attribute():
6464
assert get_nested_attribute(dummy_object, "object_b[b].object_b[0].object_b") == "b"
6565

6666

67-
def test_is_file_and_not_empty(tmpdir):
67+
def test_is_file_and_not_empty(tmp_path):
6868
path = "testfile"
6969
with tempfile.TemporaryDirectory():
7070
with open(path, "w") as f:

openff/evaluator/_tests/test_workflow/test_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def test_replicated_ids():
249249
)
250250

251251

252-
def test_find_relevant_gradient_keys(tmpdir):
252+
def test_find_relevant_gradient_keys(tmp_path):
253253
force_field = ForceField()
254254

255255
vdw_handler = force_field.get_parameter_handler("vdW")
@@ -287,7 +287,7 @@ def test_find_relevant_gradient_keys(tmpdir):
287287
)
288288
force_field.register_parameter_handler(vsite_handler)
289289

290-
force_field_path = os.path.join(tmpdir, "ff.json")
290+
force_field_path = os.path.join(tmp_path, "ff.json")
291291
SmirnoffForceFieldSource.from_object(force_field).json(force_field_path)
292292

293293
expected_gradient_keys = {

0 commit comments

Comments
 (0)