Skip to content

Introduce global test tolerance #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions tests/conftest_result_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import shutil
import subprocess
from pathlib import Path
from typing import Any, Callable, Optional
from typing import Any, Callable

import numpy as np
import pytest
Expand All @@ -37,6 +37,10 @@
from beamme.core.mesh import Mesh
from beamme.four_c.input_file import InputFile

# GLOBAL DEFAULT TEST TOLERANCES
RELATIVE_TOLERANCE = 1e-13
ABSOLUTE_TOLERANCE = 1e-13


@pytest.fixture(scope="function")
def assert_results_equal(tmp_path, current_test_name) -> Callable:
Expand All @@ -56,8 +60,8 @@ def assert_results_equal(tmp_path, current_test_name) -> Callable:
def _assert_results_equal(
reference: Path | str | dict | list | np.ndarray | InputFile | Mesh,
result: Path | str | dict | list | np.ndarray | InputFile | Mesh,
rtol: float = 1e-05,
atol: float = 1e-08,
rtol: float = RELATIVE_TOLERANCE,
atol: float = ABSOLUTE_TOLERANCE,
) -> None:
"""Comparison between reference and result with relative or absolute
tolerance.
Expand Down Expand Up @@ -103,16 +107,14 @@ def _assert_results_equal(
return _assert_results_equal


def compare_vtk_files(
reference: Path, result: Path, rtol: Optional[float], atol: Optional[float]
) -> None:
def compare_vtk_files(reference: Path, result: Path, rtol: float, atol: float) -> None:
"""Compare two VTK files for equality within a given tolerance.

Args:
reference: The path to the reference VTK file.
result: The path to the result VTK file to be compared.
rtol: The relative tolerance parameter.
atol: The absolute tolerance parameter.
rtol: The relative tolerance.
atol: The absolute tolerance.
"""

def get_vtk(path: Path) -> vtk.vtkDataObject:
Expand Down
Loading