Skip to content

Commit

Permalink
fix: use fixture for Sesame (tests run in 1.19 seconds versus 108.45 …
Browse files Browse the repository at this point in the history
…before)
  • Loading branch information
ManonMarchand committed Jul 11, 2024
1 parent 6503775 commit 24c8185
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/test/test_aladin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
from astropy.coordinates import Angle, SkyCoord
import pytest
from astropy.coordinates import Angle
from typing import Callable

from ipyaladin import Aladin
from ipyaladin.coordinate_parser import parse_coordinate_string

aladin = Aladin()


# monkeypatched sesame call to avoid remote access during tests
@pytest.fixture
def mock_sesame(monkeypatch: Callable) -> None:
"""Sesame calls mocked."""
monkeypatch.setattr(SkyCoord, "from_name", lambda _: SkyCoord(0, 0, unit="deg"))


test_aladin_string_target = [
"M 31",
"sgr a*",
Expand Down Expand Up @@ -31,11 +42,12 @@
"G90 0",
"B60 30",
"B120 -45",
"Galactic Center",
]


@pytest.mark.parametrize("target", test_aladin_string_target)
def test_aladin_string_target_set(target: str) -> None:
def test_aladin_string_target_set(target: str, mock_sesame: Callable) -> None: # noqa: ARG001
"""Test setting the target of an Aladin object with a string or a SkyCoord object.
Parameters
Expand All @@ -44,15 +56,14 @@ def test_aladin_string_target_set(target: str) -> None:
The target string.
"""
aladin = Aladin()
aladin.target = target
parsed_target = parse_coordinate_string(target)
assert aladin.target.icrs.ra.deg == parsed_target.icrs.ra.deg
assert aladin.target.icrs.dec.deg == parsed_target.icrs.dec.deg


@pytest.mark.parametrize("target", test_aladin_string_target)
def test_aladin_sky_coord_target_set(target: str) -> None:
def test_aladin_sky_coord_target_set(target: str, mock_sesame: Callable) -> None: # noqa: ARG001
"""Test setting and getting the target of an Aladin object with a SkyCoord object.
Parameters
Expand All @@ -62,7 +73,6 @@ def test_aladin_sky_coord_target_set(target: str) -> None:
"""
sc_target = parse_coordinate_string(target)
aladin = Aladin()
aladin.target = sc_target
assert aladin.target.icrs.ra.deg == sc_target.icrs.ra.deg
assert aladin.target.icrs.dec.deg == sc_target.icrs.dec.deg
Expand All @@ -87,7 +97,6 @@ def test_aladin_float_fov_set(angle: float) -> None:
The angle to set.
"""
aladin = Aladin()
aladin.fov = angle
assert aladin.fov.deg == angle

Expand All @@ -103,6 +112,5 @@ def test_aladin_angle_fov_set(angle: float) -> None:
"""
angle_fov = Angle(angle, unit="deg")
aladin = Aladin()
aladin.fov = angle_fov
assert aladin.fov.deg == angle_fov.deg

0 comments on commit 24c8185

Please sign in to comment.