Skip to content

Commit e83d80b

Browse files
committed
make tests pass
1 parent 236b94f commit e83d80b

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

tests/test_phonons.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def test_force_consts_to_hdf5_deprecation():
4444
"""Test deprecation of force-consts-to-hdf5."""
4545
struct = read(DATA_PATH / "NaCl.cif")
4646
struct.calc = choose_calculator(arch="mace_mp", model=MODEL_PATH)
47-
with pytest.warns(FutureWarning, match="--force_consts_to_hdf5 is deprecated."):
47+
with pytest.warns(
48+
FutureWarning, match="`force_consts_to_hdf5` has been deprecated."
49+
):
4850
phonons = Phonons(
4951
struct=struct,
5052
force_consts_to_hdf5=True,

tests/test_phonons_cli.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from __future__ import annotations
44

5-
import lzma
65
from pathlib import Path
76

87
from ase.io import read
8+
from h5py import File as HDF5Open
99
import pytest
1010
from typer.testing import CliRunner
1111
import yaml
@@ -37,7 +37,7 @@ def test_phonons(tmp_path):
3737
with chdir(tmp_path):
3838
results_dir = Path("janus_results")
3939
phonopy_path = results_dir / "NaCl-phonopy.yml"
40-
bands_path = results_dir / "NaCl-auto_bands.hdf5"
40+
bands_path = results_dir / "NaCl-auto_bands.yml"
4141
log_path = results_dir / "NaCl-phonons-log.yml"
4242
summary_path = results_dir / "NaCl-phonons-summary.yml"
4343

@@ -66,14 +66,12 @@ def test_phonons(tmp_path):
6666

6767
has_eigenvectors = False
6868
has_velocity = False
69-
with open(bands_path) as file:
70-
for line in file:
71-
if "eigenvector" in line:
72-
has_eigenvectors = True
73-
if "group_velocity" in line:
74-
has_velocity = True
75-
if has_eigenvectors and has_velocity:
76-
break
69+
with open(bands_path, encoding="utf8") as file:
70+
bands = yaml.safe_load(file)
71+
if "eigenvector" in bands["phonon"][0]["band"][0]:
72+
has_eigenvectors = True
73+
if "group_velocity" in bands["phonon"][0]["band"][0]:
74+
has_velocity = True
7775
assert has_eigenvectors and has_velocity
7876

7977
assert "command" in phonon_summary
@@ -132,7 +130,7 @@ def test_bands_simple(tmp_path):
132130
assert result.exit_code == 0
133131

134132
assert autoband_results.exists()
135-
with lzma.open(autoband_results, mode="rb") as file:
133+
with open(autoband_results, encoding="utf-8") as file:
136134
bands = yaml.safe_load(file)
137135
assert "eigenvector" not in bands["phonon"][0]["band"][0]
138136
assert bands["nqpoint"] == 126
@@ -196,10 +194,21 @@ def test_hdf5(tmp_path):
196194
"summary": summary_path,
197195
}
198196
check_output_files(summary=phonon_summary, output_files=output_files)
199-
200-
201-
def test_hdf5_deprecated(tmp_path):
202-
"""Test saving force constants to HDF5 in new directory."""
197+
has_eigenvectors = False
198+
has_velocity = False
199+
nqpoints = 0
200+
with HDF5Open(bands_results, "r") as bands:
201+
if "eigenvector" in bands:
202+
has_eigenvectors = True
203+
if "group_velocity" in bands:
204+
has_velocity = True
205+
nqpoints = bands["nqpoint"][0]
206+
assert has_eigenvectors and has_velocity
207+
assert nqpoints == 306
208+
209+
210+
def test_force_consts_to_hdf5_deprecated(tmp_path):
211+
"""Test saving force constants to HDF5 deprecated."""
203212
file_prefix = tmp_path / "test" / "NaCl"
204213
phonon_results = tmp_path / "test" / "NaCl-phonopy.yml"
205214
hdf5_results = tmp_path / "test" / "NaCl-force_constants.hdf5"
@@ -705,7 +714,7 @@ def test_paths(tmp_path):
705714
assert result.exit_code == 0
706715

707716
assert band_results.exists()
708-
with lzma.open(band_results, mode="rb") as file:
717+
with open(band_results, encoding="utf-8") as file:
709718
bands = yaml.safe_load(file)
710719
assert bands["nqpoint"] == 11
711720
assert bands["npath"] == 1

0 commit comments

Comments
 (0)