Skip to content

Commit

Permalink
👌 Add option to specify path for local comparison
Browse files Browse the repository at this point in the history
Using the environment variable COMPARE_RESULTS_LOCAL which can be set in tox.ini a local path can be specified to look for the results folder to use as a reference in lieu of the (gold standard) comparison-results branch in the pyglotaran-examples repository

Added some comments about which tolerances are used and their origin.
  • Loading branch information
s-weigand authored and jsnel committed Sep 3, 2021
1 parent 50abefd commit 92dc411
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
38 changes: 33 additions & 5 deletions .github/test_result_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from collections import defaultdict
from functools import lru_cache
from pathlib import Path
from textwrap import dedent
from typing import TYPE_CHECKING
from typing import Protocol
from warnings import warn
Expand Down Expand Up @@ -170,13 +171,13 @@ def data_var_test(
current_values = current_data

eps = np.finfo(np.float32).eps
rtol = 1e-5
rtol = 1e-5 # default value of allclose
if expected_var_name.endswith("residual"): # type:ignore[operator]
eps = expected_result["data"].values.max() * 1e-8

if "singular_vectors" in expected_var_name: # type:ignore[operator]
rtol = 1e-4
eps = 1e-5
rtol = 1e-4 # instead of 1e-5
eps = 1e-5 # instead of ~1.2e-7
pre_fix = SVD_PATTERN.match(expected_var_name).group( # type:ignore[operator]
"pre_fix"
)
Expand Down Expand Up @@ -224,7 +225,34 @@ def data_var_test(
def map_result_files(file_glob_pattern: str) -> dict[str, list[tuple[Path, Path]]]:
"""Load all datasets and map them in a dict."""
result_map = defaultdict(list)
compare_results_path = get_compare_results_path()
if os.getenv("COMPARE_RESULTS_LOCAL"):
compare_results_path = Path(os.getenv(key="COMPARE_RESULTS_LOCAL"))
warn(
dedent(
f"""
Using Path in environment variable COMPARE_RESULTS_LOCAL:
{compare_results_path.as_posix()}
"""
)
)
try:
if not compare_results_path.exists():
raise FileNotFoundError(
dedent(
f"""
Path in COMPARE_RESULTS_LOCAL not valid:
{compare_results_path} <- does not exist
"""
)
)
except OSError as exception:
if str(compare_results_path).startswith(('"', "'")):
raise Exception(
"Path in COMPARE_RESULTS_LOCAL should not start with ' or \""
) from exception
raise exception
else:
compare_results_path = get_compare_results_path()
current_result_path = get_current_result_path()
for expected_result_file in compare_results_path.rglob(file_glob_pattern):
key = (
Expand Down Expand Up @@ -334,7 +362,7 @@ def test_result_attr_consistency(
), f"Missing result attribute: {expected_attr_name!r} in {file_name!r}"

assert allclose(
expected_attr_value, current.attrs[expected_attr_name], rtol=1e-5, print_fail=20
expected_attr_value, current.attrs[expected_attr_name], print_fail=20
), f"Result attr value mismatch: {expected_attr_name!r} in {file_name!r}"


Expand Down
8 changes: 7 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ envlist = py{38}, pre-commit, docs, docs-notebooks, docs-links
[pytest]
; Uncomment the following lines to deactivate pyglotaran all plugins
; env =
; DEACTIVATE_GTA_PLUGINS=1
; DEACTIVATE_GTA_PLUGINS=1
; Uncomment "env =" and "COMPARE_RESULTS_LOCAL" and set it to a local folder
; with results to use as a reference in lieu of the comparison-results branch
; in the pyglotaran-examples git repository
; COMPARE_RESULTS_LOCAL=~/local_results/ ; On *nix
; COMPARE_RESULTS_LOCAL=%USERPROFILE%/local_results/ ; On Windows
; Uncomment to ignore deprecation warnings coming from pyglotaran
; (this helps to see the warnings from dependencies)
; filterwarnings =
; ignore:.+glotaran:GlotaranApiDeprecationWarning


[flake8]
extend-ignore = E231, E203
max-line-length = 99
Expand Down

0 comments on commit 92dc411

Please sign in to comment.