From 5806ff5203342364a967e35135eeead493674eea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Eertmans?= Date: Mon, 8 Jan 2024 11:12:22 +0100 Subject: [PATCH] fix(test): typecheck dataclasses --- tests/geometry/test_triangle_mesh.py | 35 ++++++++++++++++++++++++++++ tests/geometry/test_utils.py | 3 ++- tests/rt/test_image_method.py | 3 ++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/tests/geometry/test_triangle_mesh.py b/tests/geometry/test_triangle_mesh.py index 45025dae..d5cb9fee 100644 --- a/tests/geometry/test_triangle_mesh.py +++ b/tests/geometry/test_triangle_mesh.py @@ -1,16 +1,21 @@ from collections.abc import Iterator +from contextlib import AbstractContextManager +from contextlib import nullcontext as does_not_raise from pathlib import Path import chex import jax.numpy as jnp import jaxtyping import pytest +from chex import Array from differt.geometry.triangle_mesh import ( TriangleMesh, triangles_contain_vertices_assuming_inside_same_plane, ) +from ..utils import random_inputs + @pytest.fixture(scope="module") def two_buildings_obj_file() -> Iterator[Path]: @@ -33,6 +38,36 @@ def sphere() -> Iterator[TriangleMesh]: yield TriangleMesh(vertices=vertices, triangles=triangles) +@pytest.mark.parametrize( + ("triangle_vertices,vertices,expectation"), + [ + ((20, 10, 3, 3), (20, 10, 3), does_not_raise()), + ((10, 3, 3), (10, 3), does_not_raise()), + ((3, 3), (3,), does_not_raise()), + ( + (3, 3), + (4,), + pytest.raises(TypeError), + ), + ( + (10, 3, 3), + (12, 3), + pytest.raises(TypeError), + ), + ], +) +@random_inputs("triangle_vertices", "vertices") +def test_triangles_contain_vertices_assuming_inside_same_planes_random_inputs( + triangle_vertices: Array, + vertices: Array, + expectation: AbstractContextManager[Exception], +) -> None: + with expectation: + _ = triangles_contain_vertices_assuming_inside_same_plane( + triangle_vertices, vertices + ) + + def test_triangles_contain_vertices_assuming_inside_same_planes() -> None: triangle_vertices = jnp.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]) vertices = jnp.array( diff --git a/tests/geometry/test_utils.py b/tests/geometry/test_utils.py index f383ebc8..15191e60 100644 --- a/tests/geometry/test_utils.py +++ b/tests/geometry/test_utils.py @@ -7,7 +7,8 @@ from chex import Array from differt.geometry.utils import pairwise_cross -from tests.utils import random_inputs + +from ..utils import random_inputs def test_pairwise_cross() -> None: diff --git a/tests/rt/test_image_method.py b/tests/rt/test_image_method.py index 871fe7a1..2fd4f3ed 100644 --- a/tests/rt/test_image_method.py +++ b/tests/rt/test_image_method.py @@ -13,7 +13,8 @@ image_of_vertices_with_respect_to_mirrors, intersection_of_line_segments_with_planes, ) -from tests.utils import random_inputs + +from ..utils import random_inputs def test_image_of_vertices_with_respect_to_mirrors() -> None: