|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | | -import lzma |
6 | 5 | from pathlib import Path |
7 | 6 |
|
8 | 7 | from ase.io import read |
| 8 | +from h5py import File as HDF5Open |
9 | 9 | import pytest |
10 | 10 | from typer.testing import CliRunner |
11 | 11 | import yaml |
@@ -37,7 +37,7 @@ def test_phonons(tmp_path): |
37 | 37 | with chdir(tmp_path): |
38 | 38 | results_dir = Path("janus_results") |
39 | 39 | 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" |
41 | 41 | log_path = results_dir / "NaCl-phonons-log.yml" |
42 | 42 | summary_path = results_dir / "NaCl-phonons-summary.yml" |
43 | 43 |
|
@@ -66,14 +66,12 @@ def test_phonons(tmp_path): |
66 | 66 |
|
67 | 67 | has_eigenvectors = False |
68 | 68 | 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 |
77 | 75 | assert has_eigenvectors and has_velocity |
78 | 76 |
|
79 | 77 | assert "command" in phonon_summary |
@@ -132,7 +130,7 @@ def test_bands_simple(tmp_path): |
132 | 130 | assert result.exit_code == 0 |
133 | 131 |
|
134 | 132 | assert autoband_results.exists() |
135 | | - with lzma.open(autoband_results, mode="rb") as file: |
| 133 | + with open(autoband_results, encoding="utf-8") as file: |
136 | 134 | bands = yaml.safe_load(file) |
137 | 135 | assert "eigenvector" not in bands["phonon"][0]["band"][0] |
138 | 136 | assert bands["nqpoint"] == 126 |
@@ -196,10 +194,21 @@ def test_hdf5(tmp_path): |
196 | 194 | "summary": summary_path, |
197 | 195 | } |
198 | 196 | 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.""" |
203 | 212 | file_prefix = tmp_path / "test" / "NaCl" |
204 | 213 | phonon_results = tmp_path / "test" / "NaCl-phonopy.yml" |
205 | 214 | hdf5_results = tmp_path / "test" / "NaCl-force_constants.hdf5" |
@@ -705,7 +714,7 @@ def test_paths(tmp_path): |
705 | 714 | assert result.exit_code == 0 |
706 | 715 |
|
707 | 716 | assert band_results.exists() |
708 | | - with lzma.open(band_results, mode="rb") as file: |
| 717 | + with open(band_results, encoding="utf-8") as file: |
709 | 718 | bands = yaml.safe_load(file) |
710 | 719 | assert bands["nqpoint"] == 11 |
711 | 720 | assert bands["npath"] == 1 |
|
0 commit comments