diff --git a/src/test/test_aladin.py b/src/test/test_aladin.py index 46edd038..d584053a 100644 --- a/src/test/test_aladin.py +++ b/src/test/test_aladin.py @@ -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*", @@ -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 @@ -44,7 +56,6 @@ 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 @@ -52,7 +63,7 @@ def test_aladin_string_target_set(target: str) -> None: @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 @@ -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 @@ -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 @@ -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