Skip to content

Commit

Permalink
Applied pytest to coordinates validation, issue #70
Browse files Browse the repository at this point in the history
  • Loading branch information
rapoliveira committed Jan 18, 2024
1 parent b555ac0 commit 50e9b4e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
3 changes: 1 addition & 2 deletions source/MulensModel/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import warnings

from astropy.coordinates import SkyCoord, ICRS, FK4, FK5
from astropy.coordinates import GeocentricTrueEcliptic
from astropy import units as u

from MulensModel.utils import Utils
Expand Down Expand Up @@ -142,7 +143,6 @@ def ecliptic_lon(self):
ecliptic longitude calculated from (RA, Dec)
"""
from astropy.coordinates import GeocentricTrueEcliptic
return SkyCoord(self).transform_to(GeocentricTrueEcliptic).lon

@property
Expand All @@ -152,7 +152,6 @@ def ecliptic_lat(self):
ecliptic latitude calculated from (RA, Dec)
"""
from astropy.coordinates import GeocentricTrueEcliptic
return SkyCoord(self).transform_to(GeocentricTrueEcliptic).lat

@property
Expand Down
43 changes: 26 additions & 17 deletions source/MulensModel/tests/test_Coords.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import unittest
import numpy as np
import pytest
from astropy.coordinates import SkyCoord, ICRS, FK4, FK5, Galactic
import astropy.units as u

Expand Down Expand Up @@ -50,23 +51,31 @@ def test_event_coords():
assert event_3.model.coords.to_string('hmsdms') == new_coord_str


def test_coord_validation():

c_test = '18h00m00s -30d00m00s'
tests = [mm.Coordinates(c_test),
mm.Coordinates(c_test, frame='fk4'),
mm.Coordinates(SkyCoord(c_test, frame='fk5')),
mm.Coordinates(ICRS(*c_test.split())),
mm.Coordinates(FK4(*c_test.split())),
mm.Coordinates(FK5(*c_test.split()))]
t_errors = [(c_test, 'galactic'),
(SkyCoord(c_test, frame='galactic'), None),
(Galactic(*c_test.split()), None)]
for test in tests:
assert test.to_string('hmsdms') == c_test
for error in t_errors:
with unittest.TestCase().assertRaises(ValueError):
mm.Coordinates(error[0], frame=error[1])
cval = '18h00m00s -30d00m00s'
tested_cs = [(cval, None), (cval, 'fk4'),
(SkyCoord(cval, frame='fk5'), None), (ICRS(*cval.split()), None),
(FK4(*cval.split()), None), (FK5(*cval.split()), None)]
tested_cs2 = [(cval, 'galactic'), (SkyCoord(cval, frame='galactic'), None),
(Galactic(*cval.split()), None)]


@pytest.mark.parametrize("coord_test", tested_cs)
def test_coord_validation(coord_test):
"""
Test Coordinates input to accept frames than icrs, fk4 and fk5.
"""
coord_instance = mm.Coordinates(coord_test[0], frame=coord_test[1])
assert coord_instance.to_string('hmsdms') == cval


@pytest.mark.parametrize("coord_test2", tested_cs2)
def test_coord_validation_error(coord_test2):
"""
Test Coordinates input to reject frames different than icrs, fk4 and fk5.
"""
with unittest.TestCase().assertRaises(ValueError):
mm.Coordinates(coord_test2[0], frame=coord_test2[1])


def check_event_coords(event, ra, dec):
"""
Expand Down
2 changes: 1 addition & 1 deletion source/MulensModel/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.19.3"
__version__ = "2.19.4"

0 comments on commit 50e9b4e

Please sign in to comment.