diff --git a/src/cpp/tests/python/ops_features_support.py b/src/cpp/tests/python/ops_features_support.py index 4e8449be..2c9e3162 100644 --- a/src/cpp/tests/python/ops_features_support.py +++ b/src/cpp/tests/python/ops_features_support.py @@ -13,7 +13,7 @@ from __future__ import annotations import textwrap -from ref import close, golden +from ref import GEOMETRY_REL, close, golden import simplecadapi._cpp as port @@ -72,7 +72,7 @@ def run_port(snippet: str): return namespace["result"] -def compare(name: str, *parts: str, rel: float = 1e-6, abs_: float = 1e-7): +def compare(name: str, *parts: str, rel: float = GEOMETRY_REL, abs_: float = 1e-7): snippet = "\n".join(textwrap.dedent(part) for part in parts) expected = golden("ops_features_" + name, PRELUDE + snippet) actual = run_port(snippet) diff --git a/src/cpp/tests/python/ops_geometry_support.py b/src/cpp/tests/python/ops_geometry_support.py index 10b05bcf..539eacc9 100644 --- a/src/cpp/tests/python/ops_geometry_support.py +++ b/src/cpp/tests/python/ops_geometry_support.py @@ -19,7 +19,7 @@ import textwrap import simplecadapi._cpp as native from simplecadapi._cpp import _native -from ref import close, golden +from ref import GEOMETRY_REL, close, golden # ---- the two sides of describe() --------------------------------------------------------- @@ -124,7 +124,7 @@ def run_native(source: str): return json.loads(json.dumps(namespace["result"], default=float)) -def mismatches(actual, expected, path="result", rel=1e-6, abs_=1e-9): +def mismatches(actual, expected, path="result", rel=GEOMETRY_REL, abs_=1e-9): """Where `actual` and `expected` differ, one line each (empty when they agree).""" if isinstance(actual, dict) and isinstance(expected, dict): out = [] @@ -145,7 +145,7 @@ def mismatches(actual, expected, path="result", rel=1e-6, abs_=1e-9): return [f"{path}: native {actual!r} != reference {expected!r}"] -def parity(name: str, source: str, rel: float = 1e-6, abs_: float = 1e-9, prelude: str = ""): +def parity(name: str, source: str, rel: float = GEOMETRY_REL, abs_: float = 1e-9, prelude: str = ""): """Run `source` on both sides and assert that `result` agrees. `prelude` is more shared helper code.""" source = textwrap.dedent(prelude) + textwrap.dedent(source) expected = golden(f"ops_geometry_{name}", REFERENCE_SIDE + "\n" + source) diff --git a/src/cpp/tests/python/product_support.py b/src/cpp/tests/python/product_support.py index 649ff3a5..4c99774e 100644 --- a/src/cpp/tests/python/product_support.py +++ b/src/cpp/tests/python/product_support.py @@ -32,7 +32,7 @@ class _Native: native = _Native() -from ref import close, golden +from ref import GEOMETRY_REL, close, golden _PRELUDE = ''' import math @@ -116,7 +116,7 @@ def solved_summary(solved): ''' -def mismatches(actual, expected, path="result", rel=1e-6, abs_=1e-9): +def mismatches(actual, expected, path="result", rel=GEOMETRY_REL, abs_=1e-9): """Where `actual` and `expected` differ, one line each (empty when they agree).""" if isinstance(actual, dict) and isinstance(expected, dict): out = [] @@ -138,7 +138,7 @@ def run_native(source: str): return json.loads(json.dumps(namespace["result"], default=float)) -def parity(name: str, source: str, rel: float = 1e-6, abs_: float = 1e-9, ignore=()): +def parity(name: str, source: str, rel: float = GEOMETRY_REL, abs_: float = 1e-9, ignore=()): """Run `source` on both sides and assert that `result` agrees; keys in `ignore` are dropped first.""" source = textwrap.dedent(source) expected = golden(f"product_{name}", _PRELUDE + "\n" + source) diff --git a/src/cpp/tests/python/ref.py b/src/cpp/tests/python/ref.py index f4d736e3..6e4c0cef 100644 --- a/src/cpp/tests/python/ref.py +++ b/src/cpp/tests/python/ref.py @@ -74,7 +74,14 @@ def golden(name: str, snippet: str) -> Any: _GENERIC_DETAIL = "The underlying validation failed; use the structured guidance above to repair the operation." -def close(a: Any, b: Any, rel: float = 1e-6, abs_: float = 1e-9) -> bool: +# Geometric measurements (areas, volumes, bounding boxes, centres) come out of OpenCASCADE's numerical integration and +# optimisation, which differ between OCCT builds (the reference's, Homebrew's, the static one of the wheels) at the 1e-5 +# level and, for a bounding box found by a heuristic optimiser, more. A real error in the geometry is orders of magnitude +# larger, so the parity tests hold geometry to this and everything exact (counts, names, ids, strings) exactly. +GEOMETRY_REL = 1e-4 + + +def close(a: Any, b: Any, rel: float = GEOMETRY_REL, abs_: float = 1e-9) -> bool: """Recursive approximate equality for golden comparisons.""" if isinstance(b, str) and isinstance(a, str) and b.endswith(_GENERIC_DETAIL) and a != b: return a.split(": ", 1)[0] == b.split(": ", 1)[0] and a.isascii() diff --git a/src/cpp/tests/python/std_support.py b/src/cpp/tests/python/std_support.py index 52839dc2..12dbc096 100644 --- a/src/cpp/tests/python/std_support.py +++ b/src/cpp/tests/python/std_support.py @@ -13,7 +13,7 @@ import textwrap from ops_features_support import PRELUDE as _BASE_PRELUDE from ops_features_support import _diff -from ref import close, golden +from ref import GEOMETRY_REL, close, golden import simplecadapi._cpp as port @@ -52,14 +52,7 @@ def run_port(snippet: str): return namespace["result"] -# The areas of modeled-thread surfaces come from OpenCASCADE's numerical integration over B-spline faces, which differs -# between OCCT builds (the static OCCT of the Linux wheels against the reference's) at the 1e-5 level: same geometry, the -# integral's rounding differs. Everything else is held to 1e-6. -_THREAD_AREA_TOLERANCE = {"bolt_modeled_partial": 1e-4, "bolt_modeled_full_phase": 1e-4, "nut_modeled": 1e-4, "nut_phase": 1e-4} - - -def compare(name: str, *parts: str, rel: float = 1e-6, abs_: float = 1e-7): - rel = max(rel, _THREAD_AREA_TOLERANCE.get(name, rel)) +def compare(name: str, *parts: str, rel: float = GEOMETRY_REL, abs_: float = 1e-7): snippet = "\n".join(textwrap.dedent(part) for part in parts) expected = golden("std_" + name, PRELUDE + snippet) actual = run_port(snippet) diff --git a/src/cpp/tests/python/surface_support.py b/src/cpp/tests/python/surface_support.py index 4d8b9587..759e315e 100644 --- a/src/cpp/tests/python/surface_support.py +++ b/src/cpp/tests/python/surface_support.py @@ -109,7 +109,7 @@ def circle(center, radius): return T.circle(center, radius) -def close_to(got, expected, rel=1e-6, abs_=1e-6): +def close_to(got, expected, rel=1e-4, abs_=1e-6): """Recursive approximate equality; bbox corners are compared with an absolute floor.""" from ref import close diff --git a/src/cpp/tests/python/test_surface_faces.py b/src/cpp/tests/python/test_surface_faces.py index e0bffcd4..51579bf1 100644 --- a/src/cpp/tests/python/test_surface_faces.py +++ b/src/cpp/tests/python/test_surface_faces.py @@ -9,7 +9,7 @@ from ref import golden from surface_support import REF_PRELUDE, arc, circle, close_to, line, measure, rectangle, spline # noqa: F401 -def compare(name, ref_body, native_result, rel=1e-6): +def compare(name, ref_body, native_result, rel=1e-4): expected = golden(name, REF_PRELUDE + ref_body) assert close_to(native_result, expected, rel=rel), f"{name}:\nnative {native_result}\nreference {expected}"