Skip to content

Commit

Permalink
str -> float
Browse files Browse the repository at this point in the history
  • Loading branch information
jmmshn committed Jan 21, 2025
1 parent 7e0dfa6 commit 8ca3834
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tests/abinit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,23 @@ def _get_differences_tol(
f"{', '.join([str(k) for k in other_only_keys])}"
)
for k in common_keys:
val1 = self_dataset_dict[k]
val2 = other_dataset_dict[k]
matched = False
if isinstance(self_dataset_dict[k], float):
matched = (
pytest.approx(self_dataset_dict[k], rel=rtol, abs=atol)
== other_dataset_dict[k]
)
if isinstance(val1, str):
if val1.endswith(" Ha"):
val1 = val1.replace(" Ha", "")
if val1.count(".") <= 1 and val1.replace(".", "").isdecimal():
val1 = float(val1)

if isinstance(val2, str):
if val2.endswith(" Ha"):
val2 = val2.replace(" Ha", "")
if val2.count(".") <= 1 and val2.replace(".", "").isdecimal():
val2 = float(val2)

if isinstance(val1, float):
matched = pytest.approx(val1, rel=rtol, abs=atol) == val2
else:
matched = self_dataset_dict[k] == other_dataset_dict[k]

Expand Down

0 comments on commit 8ca3834

Please sign in to comment.