Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary monkeypatch.chdir calls #2141

Closed
wants to merge 15 commits into from
1 change: 0 additions & 1 deletion docs/user/recipes/recipes_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ The list of available quacc recipes is shown below. The "Req'd Extras" column sp
| ORCA ASE Relax | `#!Python @job` | [quacc.recipes.orca.core.ase_relax_job][] | |
| ORCA ASE Quasi-IRC Perturb | `#!Python @job` | [quacc.recipes.orca.core.ase_quasi_irc_perturb_job][] | |


</center>

## Psi4
Expand Down
3 changes: 1 addition & 2 deletions tests/core/calculators/espresso/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def test_read_espresso_ph_1():
assert results[5]["atoms"].symbols == ["Al"]


def test_dos_output(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_dos_output():
template = EspressoTemplate(binary="dos")
results = template.read_results(directory=Path(RUN_PATH))
assert results["dos_results"]["fermi"] == pytest.approx(5.98)
17 changes: 5 additions & 12 deletions tests/core/calculators/qchem/test_qchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def os_atoms():
return read(FILE_DIR / "OS_test.xyz")


def test_qchem_write_input_basic(tmp_path, monkeypatch, test_atoms):
monkeypatch.chdir(tmp_path)
def test_qchem_write_input_basic(test_atoms):
calc = QChem(
test_atoms,
qchem_dict_set_params={
Expand All @@ -55,8 +54,7 @@ def test_qchem_write_input_basic(tmp_path, monkeypatch, test_atoms):
calc.write_input(test_atoms)


def test_qchem_write_input_intermediate(tmp_path, monkeypatch, test_atoms):
monkeypatch.chdir(tmp_path)
def test_qchem_write_input_intermediate(test_atoms):
calc = QChem(
test_atoms,
qchem_dict_set_params={
Expand All @@ -79,8 +77,7 @@ def test_qchem_write_input_intermediate(tmp_path, monkeypatch, test_atoms):
assert qcinp.as_dict() == ref_qcinp.as_dict()


def test_qchem_write_input_advanced(tmp_path, monkeypatch, test_atoms):
monkeypatch.chdir(tmp_path)
def test_qchem_write_input_advanced(test_atoms):
calc = QChem(
test_atoms,
qchem_dict_set_params={
Expand All @@ -103,10 +100,7 @@ def test_qchem_write_input_advanced(tmp_path, monkeypatch, test_atoms):
assert qcinp.as_dict() == ref_qcinp.as_dict()


def test_qchem_write_input_open_shell_and_different_charges(
tmp_path, monkeypatch, os_atoms
):
monkeypatch.chdir(tmp_path)
def test_qchem_write_input_open_shell_and_different_charges(os_atoms):
calc = QChem(
os_atoms,
spin_multiplicity=2,
Expand Down Expand Up @@ -174,8 +168,7 @@ def test_qchem_write_input_open_shell_and_different_charges(
assert qcinp.as_dict() == ref_qcinp.as_dict()


def test_qchem_write_input_freq(tmp_path, monkeypatch, test_atoms):
monkeypatch.chdir(tmp_path)
def test_qchem_write_input_freq(test_atoms):
calc = QChem(
test_atoms,
qchem_dict_set_params={
Expand Down
4 changes: 1 addition & 3 deletions tests/core/calculators/vasp/test_vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,7 @@ def test_pmg_input_set2():


@pytest.mark.skipif(which(SETTINGS.VASP_CMD), reason="VASP is installed")
def test_run(monkeypatch, tmp_path):
monkeypatch.chdir(tmp_path)

def test_run():
atoms = bulk("Cu")
calc = Vasp(atoms, xc="PBE", use_custodian=False)
assert calc._run() > 0
Expand Down
32 changes: 9 additions & 23 deletions tests/core/recipes/dftb_recipes/test_dftb_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
from quacc.recipes.dftb.core import relax_job, static_job


def test_static_job_water(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_static_job_water():
atoms = molecule("H2O")
atoms.info = {"test": "hello"}
output = static_job(atoms)
Expand All @@ -32,9 +30,7 @@ def test_static_job_water(tmp_path, monkeypatch):
assert output["atoms"].info.get("_id")


def test_static_job_cu_supercell(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_static_job_cu_supercell():
atoms = bulk("Cu") * (3, 3, 3)
output = static_job(atoms)
assert output["nsites"] == len(atoms)
Expand All @@ -55,9 +51,7 @@ def test_static_job_cu_supercell(tmp_path, monkeypatch):
assert np.array_equal(output["atoms"].cell.array, atoms.cell.array) is True


def test_static_job_cu_kpts(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_static_job_cu_kpts():
atoms = bulk("Cu")
output = static_job(atoms, kpts=(3, 3, 3))
assert output["nsites"] == len(atoms)
Expand All @@ -78,17 +72,13 @@ def test_static_job_cu_kpts(tmp_path, monkeypatch):
assert np.array_equal(output["atoms"].cell.array, atoms.cell.array) is True


def test_static_errors(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_static_errors():
with pytest.raises(RuntimeError, match="failed with command"):
atoms = molecule("H2O")
static_job(atoms, Hamiltonian_MaxSccIterations=1)


def test_relax_job_water(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_relax_job_water():
atoms = molecule("H2O")

output = relax_job(atoms)
Expand All @@ -103,8 +93,7 @@ def test_relax_job_water(tmp_path, monkeypatch):
assert np.array_equal(output["atoms"].cell.array, atoms.cell.array) is True


def test_relax_job_cu_supercell(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_relax_job_cu_supercell():
atoms = bulk("Cu") * (2, 1, 1)
atoms[0].position += 0.1

Expand All @@ -128,8 +117,7 @@ def test_relax_job_cu_supercell(tmp_path, monkeypatch):
assert np.array_equal(output["atoms"].cell.array, atoms.cell.array) is True


def test_relax_job_cu_supercell_cell_relax(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_relax_job_cu_supercell_cell_relax():
atoms = bulk("Cu") * (2, 1, 1)
atoms[0].position += 0.1
output = relax_job(atoms, method="GFN1-xTB", kpts=(3, 3, 3), relax_cell=True)
Expand All @@ -152,16 +140,14 @@ def test_relax_job_cu_supercell_cell_relax(tmp_path, monkeypatch):
assert np.array_equal(output["atoms"].cell.array, atoms.cell.array) is False


def test_relax_job_cu_supercell_errors(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_relax_job_cu_supercell_errors():
with pytest.raises(RuntimeError, match="failed with command"):
atoms = bulk("Cu") * (2, 1, 1)
atoms[0].position += 0.5
relax_job(atoms, kpts=(3, 3, 3), MaxSteps=1, Hamiltonian_MaxSccIterations=100)


def test_child_errors(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_child_errors():
with pytest.raises(RuntimeError, match="failed with command"):
atoms = bulk("Cu")
static_job(atoms)
Expand Down
3 changes: 1 addition & 2 deletions tests/core/recipes/emt_recipes/test_emt_defect_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from quacc.recipes.emt.defects import bulk_to_defects_flow


def test_bulk_to_defects_flow(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_bulk_to_defects_flow():
atoms = bulk("Cu")
output = bulk_to_defects_flow(
atoms, job_params={"relax_job": {"opt_params": {"fmax": 5}}}
Expand Down
4 changes: 1 addition & 3 deletions tests/core/recipes/emt_recipes/test_emt_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from quacc.recipes.emt.elastic import bulk_to_deformations_flow


def test_elastic_jobs(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_elastic_jobs():
atoms = bulk("Cu")

outputs = bulk_to_deformations_flow(atoms, run_static=False)
Expand Down
12 changes: 4 additions & 8 deletions tests/core/recipes/emt_recipes/test_emt_phonons.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from quacc.recipes.emt.phonons import phonon_flow


def test_phonon_flow(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_phonon_flow():
atoms = bulk("Cu")
output = phonon_flow(atoms, min_lengths=5.0)
assert output["results"]["thermal_properties"]["temperatures"].shape == (101,)
Expand All @@ -36,8 +35,7 @@ def test_phonon_flow(tmp_path, monkeypatch):
assert "total_dos" in output["results"]


def test_phonon_flow_v2(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_phonon_flow_v2():
atoms = bulk("Cu") * (2, 2, 2)
output = phonon_flow(atoms, min_lengths=None, t_min=10, t_max=20, t_step=5)
assert output["results"]["thermal_properties"]["temperatures"].shape == (3,)
Expand All @@ -47,8 +45,7 @@ def test_phonon_flow_v2(tmp_path, monkeypatch):
assert "mesh_properties" in output["results"]


def test_phonon_flow_v3(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_phonon_flow_v3():
atoms = bulk("Cu") * (2, 2, 2)
atoms[0].position += 0.2
output = phonon_flow(atoms, run_relax=False, min_lengths=5.0)
Expand All @@ -60,8 +57,7 @@ def test_phonon_flow_v3(tmp_path, monkeypatch):
assert output["atoms"] == atoms


def test_phonon_flow_v4(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_phonon_flow_v4():
atoms = bulk("Cu") * (2, 2, 2)
atoms[0].position += 0.2
output = phonon_flow(atoms, run_relax=True, min_lengths=5.0)
Expand Down
12 changes: 3 additions & 9 deletions tests/core/recipes/emt_recipes/test_emt_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
from quacc.recipes.emt.slabs import bulk_to_slabs_flow


def test_static_job(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_static_job():
atoms = bulk("Cu") * (2, 2, 2)
atoms[0].position += [0.1, 0.1, 0.1]
atoms.info = {"test": "hello"}
Expand All @@ -32,9 +30,7 @@ def test_static_job(tmp_path, monkeypatch):
assert output["results"]["energy"] == pytest.approx(0.11074520235398744)


def test_relax_job(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_relax_job():
atoms = bulk("Cu") * (2, 2, 2)
atoms[0].position += [0.1, 0.1, 0.1]

Expand Down Expand Up @@ -87,9 +83,7 @@ def test_relax_job(tmp_path, monkeypatch):
assert output["results"]["energy"] == pytest.approx(0.04996032884581858)


def test_slab_dynamic_jobs(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_slab_dynamic_jobs():
atoms = bulk("Cu")

outputs = bulk_to_slabs_flow(atoms, run_static=False)
Expand Down
12 changes: 3 additions & 9 deletions tests/core/recipes/gaussian_recipes/test_gaussian_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
from quacc.recipes.gaussian.core import relax_job, static_job


def test_static_job(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_static_job():
atoms = molecule("H2")

output = static_job(atoms, 0, 1)
Expand Down Expand Up @@ -44,9 +42,7 @@ def test_static_job(tmp_path, monkeypatch):
assert_array_equal(output["atoms"].get_initial_magnetic_moments(), [0, 0])


def test_relax_job(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_relax_job():
atoms = molecule("H2")
atoms.set_initial_magnetic_moments([0, 0])

Expand Down Expand Up @@ -76,9 +72,7 @@ def test_relax_job(tmp_path, monkeypatch):
assert_array_equal(output["atoms"].get_initial_magnetic_moments(), [0, 0])


def test_relax_job_v2(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_relax_job_v2():
atoms = molecule("H2")
atoms.set_initial_magnetic_moments([0, 3])

Expand Down
12 changes: 3 additions & 9 deletions tests/core/recipes/gulp_recipes/test_gulp_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from quacc.recipes.gulp.core import relax_job, static_job


def test_static_job(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_static_job():
atoms = molecule("H2O")

output = static_job(atoms)
Expand Down Expand Up @@ -64,9 +62,7 @@ def test_static_job(tmp_path, monkeypatch):
assert "output cif gulp.cif" in output["parameters"]["options"]


def test_relax_job(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_relax_job():
atoms = molecule("H2O")

output = relax_job(atoms)
Expand Down Expand Up @@ -137,9 +133,7 @@ def test_relax_job(tmp_path, monkeypatch):
assert "output cif gulp.cif" in output["parameters"]["options"]


def test_envvars(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_envvars():
atoms = molecule("H2O")

with change_settings({"GULP_LIB": str(Path("/path/to/lib"))}):
Expand Down
18 changes: 5 additions & 13 deletions tests/core/recipes/lj_recipes/test_lj_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
from quacc.recipes.lj.core import freq_job, relax_job, static_job


def test_static_job(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_static_job():
with change_settings({"STORE": MemoryStore()}):
atoms = molecule("H2O")

Expand All @@ -32,24 +30,20 @@ def test_static_job(tmp_path, monkeypatch):
assert output["results"]["energy"] == pytest.approx(0.0)


def test_static_job_v2(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_static_job_v2():
atoms = bulk("Pt")
atoms[0].symbol = "Au"
assert static_job(atoms)


def test_static_job_v3(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
def test_static_job_v3():
atoms = bulk("Pt")
atoms.pbc = False
atoms[0].symbol = "Au"
assert static_job(atoms)


def test_relax_job(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_relax_job():
atoms = molecule("H2O")

output = relax_job(atoms)
Expand All @@ -71,9 +65,7 @@ def test_relax_job(tmp_path, monkeypatch):
assert np.max(np.linalg.norm(output["results"]["forces"], axis=1)) < 0.03


def test_freq_job(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)

def test_freq_job():
atoms = molecule("H2O")

output = freq_job(relax_job(atoms)["atoms"])
Expand Down
Loading
Loading