Skip to content

Commit 4f47a28

Browse files
committed
xfail for netcdf4 in ubuntu CI
1 parent 2d33219 commit 4f47a28

File tree

1 file changed

+18
-35
lines changed

1 file changed

+18
-35
lines changed

tests/io/abinit/test_netcdf.py

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import os
4+
import sys
45
import tarfile
56

67
import numpy as np
@@ -60,7 +61,6 @@ def test_read_si2(self):
6061
for varname, float_ref in ref_float_values.items():
6162
value = data.read_value(varname)
6263
assert_allclose(value, float_ref)
63-
# assert 0
6464

6565
# Reading non-existent variables or dims should raise
6666
# a subclass of NetcdReaderError
@@ -83,48 +83,31 @@ def test_read_si2(self):
8383
# xc = data.read_abinit_xcfunc()
8484
# assert xc == "LDA"
8585

86-
@pytest.mark.skipif(netCDF4 is None, reason="Requires Netcdf4")
87-
def test_read_fe(self):
88-
import h5py
89-
90-
print("\n=== netCDF4 / HDF5 diagnostic info ===")
91-
print(f"netCDF4 version: {netCDF4.__version__}")
92-
print(f"h5py version: {h5py.__version__}")
93-
print(f"HDF5 C library version: {h5py.version.hdf5_version}")
94-
print(f"NumPy version: {np.__version__}")
95-
print(f"Current working directory: {os.getcwd()}")
96-
print(f"Files in cwd: {os.listdir('.')}")
97-
print("======================================\n")
98-
99-
with tarfile.open(f"{TEST_DIR}/Fe_magmoms_collinear_GSR.tar.xz", mode="r:xz") as t:
100-
for member in t.getmembers():
101-
if member.name.endswith(".nc"):
102-
with t.extractfile(member) as src, open(os.path.basename(member.name), "wb") as dst:
103-
dst.write(src.read())
104-
105-
print(f"Files in cwd after extraction: {os.listdir('.')}")
106-
107-
ref_magmom_collinear = [-0.5069359730980665]
108-
path = os.path.join(".", "Fe_magmoms_collinear_GSR.nc")
109-
110-
# TODO: PR4128, EtsfReader would fail in Ubuntu CI with netCDF4 > 1.6.5
111-
# Need someone with knowledge in netCDF4 to fix it
112-
with EtsfReader(path) as data:
113-
structure = data.read_structure()
114-
assert structure.site_properties["magmom"] == ref_magmom_collinear
115-
116-
with tarfile.open(f"{TEST_DIR}/Fe_magmoms_noncollinear_GSR.tar.xz", mode="r:xz") as t:
86+
@pytest.mark.skipif(netCDF4 is None, reason="Requires NetCDF4")
87+
@pytest.mark.xfail(
88+
sys.platform.startswith("linux") and os.getenv("CI") and netCDF4.__version__ >= "1.6.5",
89+
reason="Fails with netCDF4 >= 1.6.5 on Ubuntu CI",
90+
)
91+
@pytest.mark.parametrize(
92+
("tarname", "expected"),
93+
[
94+
("Fe_magmoms_collinear_GSR.tar.xz", [-0.5069359730980665]),
95+
("Fe_magmoms_noncollinear_GSR.tar.xz", [[0.357939487, 0.357939487, 0]]),
96+
],
97+
)
98+
def test_read_fe(self, tarname, expected):
99+
with tarfile.open(os.path.join(TEST_DIR, tarname), mode="r:xz") as t:
117100
# TODO: remove attr check after only 3.12+
118101
if hasattr(tarfile, "data_filter"):
119102
t.extractall(".", filter="data")
120103
else:
121104
t.extractall(".") # noqa: S202
122-
ref_magmom_noncollinear = [[0.357939487, 0.357939487, 0]]
123-
path = os.path.join(".", "Fe_magmoms_noncollinear_GSR.nc")
105+
106+
path = os.path.basename(tarname).replace(".tar.xz", ".nc")
124107

125108
with EtsfReader(path) as data:
126109
structure = data.read_structure()
127-
assert structure.site_properties["magmom"] == ref_magmom_noncollinear
110+
assert structure.site_properties["magmom"] == expected
128111

129112

130113
class TestAbinitHeader(MatSciTest):

0 commit comments

Comments
 (0)