Skip to content

Commit ed9c785

Browse files
tweak abinit test to allow for small differences in floating point precision
1 parent 7e35d90 commit ed9c785

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tests/abinit/conftest.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,21 @@ def check_run_abi(ref_path: str | Path):
130130
ref_str = file.read()
131131
ref = AbinitInputFile.from_string(ref_str)
132132
# Ignore the pseudos as the directory depends on the pseudo root directory
133-
diffs = user.get_differences(ref, ignore_vars=["pseudos"])
133+
# The `get_differences` method doesn't take into account floating point
134+
# precision - this check might fail, e.g., (real CI example):
135+
# ```
136+
# The variable 'tsmear' is different in the two files:
137+
# - this file: '0.0036749322175665 Ha'
138+
# - other file: '0.0036749322175655 Ha'`
139+
# ```
140+
diffs = user.get_differences(ref, ignore_vars=["pseudos", "tsmear"])
134141
# TODO: should we still add some check on the pseudos here ?
135142
assert diffs == [], f"'run.abi' is different from reference:\n{diffs}"
136143

144+
for fp_key in ("tsmear",):
145+
if (ref_val := ref.datasets[0].get(fp_key)) is not None:
146+
assert user.datasets[0].get(fp_key) == pytest.approx(ref_val)
147+
137148

138149
def check_abinit_input_json(ref_path: str | Path):
139150
from abipy.abio.inputs import AbinitInput

0 commit comments

Comments
 (0)