Skip to content

Commit

Permalink
fix(tests): download scenes in top conf. and add thread Lock
Browse files Browse the repository at this point in the history
  • Loading branch information
jeertmans committed Apr 22, 2024
1 parent 4f69a83 commit 7b422a0
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
23 changes: 14 additions & 9 deletions python/differt/plotting/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
from collections.abc import MutableMapping
from contextlib import AbstractContextManager, contextmanager
from functools import wraps
from threading import Lock
from typing import TYPE_CHECKING, Any, Callable, Generic, Protocol, TypeVar

BACKEND_LOCK = Lock()
"""A Lock to avoid modifying backend (and defaults) in multiple threads at the same time (e.g., with Pytest."""

DEFAULT_BACKEND = "vispy"
SUPPORTED_BACKENDS = ("vispy", "matplotlib", "plotly")

Expand Down Expand Up @@ -93,15 +97,16 @@ def set_defaults(backend: str | None = None, **kwargs: Any) -> str:
f"We currently support: {', '.join(SUPPORTED_BACKENDS)}."
)

try:
importlib.import_module(f"{backend}")
DEFAULT_BACKEND = backend
DEFAULT_KWARGS = kwargs
return backend
except ImportError:
raise ImportError(
f"Could not load backend '{backend}', did you install it?"
) from None
with BACKEND_LOCK:
try:
importlib.import_module(f"{backend}")
DEFAULT_BACKEND = backend
DEFAULT_KWARGS = kwargs
return backend
except ImportError:
raise ImportError(
f"Could not load backend '{backend}', did you install it?"
) from None


@contextmanager
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import pytest

from differt.scene.sionna import download_sionna_scenes


def pytest_sessionstart(session: pytest.Session) -> None:
download_sionna_scenes()


@pytest.fixture(scope="session")
def test_dir() -> Path:
Expand Down
10 changes: 6 additions & 4 deletions tests/rt/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ def test_insert_from_and_to_nodes(self) -> None:
assert from_ == 9
assert to == 10

with pytest.raises(TypeError) as exc:
with pytest.raises(
TypeError, match="takes 0 positional arguments but 1 was given"
):
_ = graph.insert_from_and_to_nodes(True) # type: ignore
assert "takes 0 positional arguments but 1 was given" in str(exc)

def test_from_graph(self) -> None:
graph = CompleteGraph(10)
Expand All @@ -32,9 +33,10 @@ def test_from_graph(self) -> None:
def test_all_keyword_only_parameters(self) -> None:
graph = DiGraph.from_complete_graph(CompleteGraph(5))

with pytest.raises(TypeError) as exc:
with pytest.raises(
TypeError, match="takes 3 positional arguments but 4 were given"
):
_ = graph.all_paths(0, 1, 0, True) # type: ignore
assert "takes 3 positional arguments but 4 were given" in str(exc)

@pytest.mark.parametrize(
"num_nodes,depth",
Expand Down
7 changes: 0 additions & 7 deletions tests/scene/conftest.py

This file was deleted.

4 changes: 1 addition & 3 deletions tests/scene/test_sionna.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@

@pytest.mark.parametrize("scene_name", ("foo", "bar"))
def test_get_unexisting_sionna_scene(scene_name: str) -> None:
with pytest.raises(ValueError) as exc:
with pytest.raises(ValueError, match="Cannot find scene_name"):
_ = get_sionna_scene(scene_name)

assert "Cannot find scene_name" in str(exc)


class TestSionnaScene:
@pytest.mark.parametrize("scene_name", list_sionna_scenes())
Expand Down

0 comments on commit 7b422a0

Please sign in to comment.