Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remote_data on all tests that require network #572

Merged
merged 11 commits into from
Dec 5, 2024
4 changes: 2 additions & 2 deletions astroplan/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ def __init__(self, min=None, max=None):
>>> from astroplan import Observer
>>> from astroplan.constraints import LocalTimeConstraint
>>> import datetime as dt
>>> subaru = Observer.at_site("Subaru", timezone="US/Hawaii")
>>> subaru = Observer.at_site("Subaru", timezone="US/Hawaii") # doctest: +REMOTE_DATA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is subaru needed here at all? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true, that variable is not used

>>> # bound times between 23:50 and 04:08 local Hawaiian time
>>> constraint = LocalTimeConstraint(min=dt.time(23,50), max=dt.time(4,8))
"""
Expand Down Expand Up @@ -821,7 +821,7 @@ def __init__(self, min=None, max=None):

>>> from astroplan import Observer
>>> from astropy.time import Time
>>> subaru = Observer.at_site("Subaru")
>>> subaru = Observer.at_site("Subaru") # doctest: +REMOTE_DATA
>>> t1 = Time("2016-03-28T12:00:00")
>>> t2 = Time("2016-03-30T12:00:00")
>>> constraint = TimeConstraint(t1,t2)
Expand Down
1 change: 1 addition & 0 deletions astroplan/plots/tests/test_sky.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_image_example():
return fig


@pytest.mark.remote_data
@pytest.mark.skipif('not HAS_MATPLOTLIB')
@pytest.mark.mpl_image_compare
def test_timezone():
Expand Down
8 changes: 4 additions & 4 deletions astroplan/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ class FixedTarget(Target):
>>> from astropy.coordinates import SkyCoord
>>> import astropy.units as u
>>> sirius_coord = SkyCoord(ra=101.28715533*u.deg, dec=16.71611586*u.deg)
>>> sirius = FixedTarget(coord=sirius_coord, name="Sirius")
>>> sirius = FixedTarget(coord=sirius_coord, name="Sirius") # doctest: +REMOTE_DATA

Create an equivalent `~astroplan.FixedTarget` object for Sirius by querying
for the coordinates of Sirius by name:

>>> from astroplan import FixedTarget
>>> sirius = FixedTarget.from_name("Sirius")
>>> sirius = FixedTarget.from_name("Sirius") # doctest: +REMOTE_DATA
"""

def __init__(self, coord, name=None, **kwargs):
Expand Down Expand Up @@ -127,7 +127,7 @@ def from_name(cls, query_name, name=None, **kwargs):
Examples
--------
>>> from astroplan import FixedTarget
>>> sirius = FixedTarget.from_name("Sirius")
>>> sirius = FixedTarget.from_name("Sirius") # doctest: +REMOTE_DATA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem with marking lines with remote data, you also need to mark all the subsequent lines derived from here onwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are some tests where I should mark also the next line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have also noticed that I was using REMOTE_DATA in some tests that don't need it. I have removed them

>>> sirius.coord # doctest: +FLOAT_CMP
<SkyCoord (ICRS): (ra, dec) in deg
( 101.28715533, -16.71611586)>
Expand All @@ -149,7 +149,7 @@ def __repr__(self):
>>> from astroplan import FixedTarget
>>> from astropy.coordinates import SkyCoord
>>> vega_coord = SkyCoord(ra='279.23473479d', dec='38.78368896d')
>>> vega = FixedTarget(coord=vega_coord, name="Vega")
>>> vega = FixedTarget(coord=vega_coord, name="Vega") # doctest: +REMOTE_DATA
>>> print(vega) # doctest: +FLOAT_CMP
<FixedTarget "Vega" at SkyCoord (ICRS): (ra, dec) in deg ( 279.23473479, 38.78368894)>
"""
Expand Down
17 changes: 17 additions & 0 deletions astroplan/tests/test_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
dec=89.26410897*u.deg), name="Polaris")


@pytest.mark.remote_data
def test_at_night_basic():
subaru = Observer.at_site("Subaru")
time_ranges = [Time(['2001-02-03 04:05:06', '2001-02-04 04:05:06']), # 1 day
Expand All @@ -55,6 +56,7 @@ def test_at_night_basic():
len(targets)*[observer_is_night_all])


@pytest.mark.remote_data
def test_observability_table():
subaru = Observer.at_site("Subaru")
# time_ranges = [Time(['2001-02-03 04:05:06', '2001-02-04 04:05:06']), # 1 day
Expand Down Expand Up @@ -98,6 +100,7 @@ def test_observability_table():
assert 'time observable' in stab.colnames


@pytest.mark.remote_data
def test_altitude_constraint():
subaru = Observer.at_site("Subaru")
time = Time('2001-02-03 15:35:00')
Expand All @@ -109,6 +112,7 @@ def test_altitude_constraint():
assert np.all([results != 0][0] == [False, False, True, True, False, False])


@pytest.mark.remote_data
def test_compare_altitude_constraint_and_observer():
time = Time('2001-02-03 04:05:06')
time_ranges = [Time([time, time+1*u.hour]) + offset
Expand All @@ -130,6 +134,7 @@ def test_compare_altitude_constraint_and_observer():
assert all(always_from_observer == always_from_constraint)


@pytest.mark.remote_data
def test_compare_airmass_constraint_and_observer():
time = Time('2001-02-03 04:05:06')
time_ranges = [Time([time, time+1*u.hour]) + offset
Expand All @@ -151,6 +156,7 @@ def test_compare_airmass_constraint_and_observer():
assert all(always_from_observer == always_from_constraint)


@pytest.mark.remote_data
def test_galactic_plane_separation():
time = Time('2003-04-05 06:07:08')
apo = Observer.at_site("APO")
Expand All @@ -176,6 +182,7 @@ def test_galactic_plane_separation():

# in astropy before v1.0.4, a recursion error is triggered by this test
@pytest.mark.skipif('APY_LT104')
@pytest.mark.remote_data
def test_sun_separation():
time = Time('2003-04-05 06:07:08')
apo = Observer.at_site("APO")
Expand All @@ -200,6 +207,7 @@ def test_sun_separation():
assert np.all(is_constraint_met == [False, True, True])


@pytest.mark.remote_data
def test_moon_separation():
time = Time('2003-04-05 06:07:08')
apo = Observer.at_site("APO")
Expand Down Expand Up @@ -228,6 +236,7 @@ def test_moon_separation():
assert np.all(is_constraint_met == [False, True, True])


@pytest.mark.remote_data
def test_moon_illumination():
times = Time(["2015-08-28 03:30", "2015-08-28 12:00",
"2015-09-05 10:30", "2015-09-15 18:35"])
Expand Down Expand Up @@ -266,6 +275,7 @@ def test_moon_illumination():
assert np.all(is_constraint_met == [True, False, False, False])


@pytest.mark.remote_data
def test_local_time_constraint_utc():
time = Time('2001-02-03 04:05:06')
subaru = Observer.at_site("Subaru")
Expand All @@ -282,6 +292,7 @@ def test_local_time_constraint_utc():
assert is_constraint_met is np.bool_(True)


@pytest.mark.remote_data
def test_local_time_constraint_hawaii_tz():
# Define timezone in Observer.timezone
time = Time('2001-02-03 04:05:06')
Expand All @@ -299,6 +310,7 @@ def test_local_time_constraint_hawaii_tz():
assert is_constraint_met is np.bool_(True)


@pytest.mark.remote_data
def test_docs_example():
# Test the example in astroplan/docs/tutorials/constraints.rst
target_table_string = """# name ra_degrees dec_degrees
Expand Down Expand Up @@ -362,6 +374,7 @@ def compute_constraint(self, times, observer, targets):
assert all(observability == [False, False, True, False, False, False])


@pytest.mark.remote_data
def test_regression_airmass_141():
subaru = Observer.at_site("Subaru")
time = Time('2001-1-1 12:00')
Expand Down Expand Up @@ -424,6 +437,7 @@ def test_rescale_minmax():
]


@pytest.mark.remote_data
@pytest.mark.parametrize('constraint', constraint_tests)
def test_regression_shapes(constraint):
times = Time(["2015-08-28 03:30", "2015-09-05 10:30", "2015-09-15 18:35"])
Expand All @@ -439,6 +453,7 @@ def test_regression_shapes(constraint):
constraint(lapalma, targets, times)


@pytest.mark.remote_data
def test_caches_shapes():
times = Time([2457884.43350526, 2457884.5029497, 2457884.57239415], format='jd')
m31 = SkyCoord(10.6847929*u.deg, 41.269065*u.deg)
Expand All @@ -451,6 +466,7 @@ def test_caches_shapes():
assert ac(observer, targets, times, grid_times_targets=False).shape == (3,)


@pytest.mark.remote_data
def test_eclipses():
subaru = Observer.at_site("Subaru")

Expand All @@ -472,6 +488,7 @@ def test_eclipses():
assert np.all(np.array([False, True, False]) == pc(subaru, None, times))


@pytest.mark.remote_data
def test_event_observable():

epoch = Time(2452826.628514, format='jd')
Expand Down
5 changes: 5 additions & 0 deletions astroplan/tests/test_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,7 @@ def test_timezone_convenience_methods():
assert all(naive_dts == times_dt_ndarray - datetime.timedelta(hours=4))


@pytest.mark.remote_data
def test_is_night():
lco = Observer(location=EarthLocation.of_site('lco')) # Las Campanas
aao = Observer(location=EarthLocation.of_site('aao')) # Sydney, Australia
Expand Down Expand Up @@ -1224,6 +1225,7 @@ def test_hour_angle():
assert_quantity_allclose(hour_angle, lst, atol=0.001*u.deg)


@pytest.mark.remote_data
def test_tonight():
obs = Observer.at_site('Subaru')
obs.height = 0 * u.m
Expand Down Expand Up @@ -1351,6 +1353,7 @@ def test_sun_set_vs_mmto_almanac(mmto_sunset):
assert abs(mmto_sunset - astroplan_sunset) < 1 * u.min


@pytest.mark.remote_data
def test_observer_lon_lat_el():
"""Test that astropy.EarthLocation conversion to longitude,
latitude, and elevation works correctly.
Expand All @@ -1360,6 +1363,7 @@ def test_observer_lon_lat_el():
assert hasattr(obs, attr)


@pytest.mark.remote_data
def test_hash_observer():
"""Test that Observer objects are hashable."""
obs1 = Observer.at_site('Subaru')
Expand All @@ -1373,6 +1377,7 @@ def test_hash_observer():
assert hash(obs3) == hash(obs4)


@pytest.mark.remote_data
def test_eq_observer():
"""Test that Observer objects are comparable."""
obs1 = Observer.at_site('Subaru')
Expand Down
7 changes: 6 additions & 1 deletion astroplan/tests/test_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from astropy.time import Time
import astropy.units as u
from astropy.coordinates import SkyCoord, EarthLocation
import pytest

from ..utils import time_grid_from_range
from ..observer import Observer
Expand All @@ -23,7 +24,8 @@
polaris = FixedTarget(coord=SkyCoord(ra=37.95456067 * u.deg,
dec=89.26410897 * u.deg), name="Polaris")

apo = Observer(EarthLocation.of_site('apo'), name='APO')
apo = Observer(EarthLocation(-1463969.30185172, -5166673.34223433, 3434985.71204565, unit='m'),
name='APO')
targets = [vega, polaris, rigel]
default_time = Time('2016-02-06 03:00:00')
only_at_night = [AtNightConstraint()]
Expand Down Expand Up @@ -207,6 +209,7 @@ def test_sequential_scheduler():
scheduler(blocks, schedule)


@pytest.mark.remote_data
def test_scheduling_target_down():
lco = Observer.at_site('lco')
block = [ObservingBlock(FixedTarget.from_name('polaris'), 1 * u.min, 0)]
Expand All @@ -224,6 +227,7 @@ def test_scheduling_target_down():
assert len(schedule2.observing_blocks) == 0


@pytest.mark.remote_data
def test_scheduling_during_day():
block = [ObservingBlock(FixedTarget.from_name('polaris'), 1 * u.min, 0)]
day = Time('2016-02-06 03:00:00')
Expand All @@ -242,6 +246,7 @@ def test_scheduling_during_day():
# bring this back when MoonIlluminationConstraint is working properly


@pytest.mark.remote_data
def test_scheduling_moon_up():
block = [ObservingBlock(FixedTarget.from_name('polaris'), 30 * u.min, 0)]
# on february 23 the moon was up between the start/end times defined below
Expand Down
3 changes: 3 additions & 0 deletions astroplan/tests/test_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from ..observer import Observer


@pytest.mark.remote_data
def test_FixedTarget_from_name():
"""
Check that resolving target names with the `SkyCoord.from_name` constructor
Expand All @@ -30,6 +31,7 @@ def test_FixedTarget_from_name():
assert polaris_from_name.coord.separation(polaris_from_SIMBAD) < 1*u.arcsec


@pytest.mark.remote_data
def test_FixedTarget_ra_dec():
"""
Confirm that FixedTarget.ra and FixedTarget.dec are the same as the
Expand All @@ -46,6 +48,7 @@ def test_FixedTarget_ra_dec():
'SkyCoord')


@pytest.mark.remote_data
def test_get_skycoord():
m31 = SkyCoord(10.6847083*u.deg, 41.26875*u.deg)
m31_with_distance = SkyCoord(10.6847083*u.deg, 41.26875*u.deg, 780*u.kpc)
Expand Down
15 changes: 9 additions & 6 deletions tox.ini
pllim marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tox]
envlist =
py{37,38,39}-test{,-alldeps,-devdeps}{,-cov}
py{37,38,39}-test-numpy{117,118,119}
py{37,38,39}-test-astropy{lts,41,42}
py{310,311,312}-test{,-alldeps,-devdeps}{,-cov}{,-remote}
py{310,311,312}-test-numpy{123,124,125}{,-remote}
py{310,311,312}-test-astropy{lts,53,60}{,-remote}
build_docs
linkcheck
codestyle
Expand All @@ -15,7 +15,9 @@ indexserver =

[testenv]
# Suppress display of matplotlib plots generated during docs build
setenv = MPLBACKEND=agg
setenv =
MPLBACKEND=agg
remote: PYTEST_REMOTE_DATA=any

# Pass through the following environment variables which may be needed for the CI
passenv = HOME, WINDIR, LC_ALL, LC_CTYPE, CC, CI, TRAVIS
Expand All @@ -38,6 +40,7 @@ description =
devdeps: with the latest developer version of key dependencies
oldestdeps: with the oldest supported version of key dependencies
cov: and test coverage
remote: with remote data
numpy116: with numpy 1.16.*
numpy117: with numpy 1.17.*
numpy118: with numpy 1.18.*
Expand Down Expand Up @@ -72,8 +75,8 @@ extras =

commands =
pip freeze
!cov: pytest --pyargs astroplan {toxinidir}/docs {posargs}
cov: pytest --pyargs astroplan {toxinidir}/docs --cov astroplan --cov-config={toxinidir}/setup.cfg {posargs}
!cov: pytest --remote-data={env:PYTEST_REMOTE_DATA:none} --pyargs astroplan {toxinidir}/docs {posargs}
cov: pytest --remote-data={env:PYTEST_REMOTE_DATA:none} --pyargs astroplan {toxinidir}/docs --cov astroplan --cov-config={toxinidir}/setup.cfg {posargs}
cov: coverage xml -o {toxinidir}/coverage.xml

[testenv:build_docs]
Expand Down