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
12 changes: 7 additions & 5 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ jobs:

- name: Windows - Python 3.11 with all optional dependencies
os: windows-latest
python: 3.11
python: '3.11'
toxenv: py11-test-alldeps
toxargs: -v

- name: Python 3.11 with remote data, all dependencies, and coverage
os: ubuntu-latest
python: 3.11
python: '3.11'
toxenv: py11-test-alldeps-cov
toxposargs: --remote-data
toxargs: -v
posargs: --remote-data=any

- name: Python 3.11 with latest dev versions of key dependencies
os: ubuntu-latest
python: 3.11
python: '3.11'
toxenv: py11-test-devdeps

- name: Test building of Sphinx docs
Expand All @@ -79,4 +81,4 @@ jobs:
run: sudo apt-get -y install graphviz
- name: Test with tox
run: |
tox -e ${{ matrix.toxenv }}
python -m tox -e ${{ matrix.toxenv }} ${{ matrix.toxargs }} -- ${{ matrix.posargs }}
16 changes: 7 additions & 9 deletions astroplan/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,9 @@ def __init__(self, min=None, max=None):
Constrain the observations to targets that are observable between
23:50 and 04:08 local time:

>>> from astroplan import Observer
>>> from astroplan.constraints import LocalTimeConstraint
>>> import datetime as dt
>>> subaru = Observer.at_site("Subaru", timezone="US/Hawaii")
>>> # bound times between 23:50 and 04:08 local Hawaiian time
>>> constraint = LocalTimeConstraint(min=dt.time(23,50), max=dt.time(4,8))
>>> from astroplan.constraints import LocalTimeConstraint
>>> constraint = LocalTimeConstraint(min=dt.time(23, 50), max=dt.time(4, 8))
"""

self.min = min
Expand Down Expand Up @@ -816,12 +813,11 @@ def __init__(self, min=None, max=None):
Constrain the observations to targets that are observable between
2016-03-28 and 2016-03-30:

>>> from astroplan import Observer
>>> from astropy.time import Time
>>> subaru = Observer.at_site("Subaru")
>>> from astroplan.constraints import TimeConstraint
>>> t1 = Time("2016-03-28T12:00:00")
>>> t2 = Time("2016-03-30T12:00:00")
>>> constraint = TimeConstraint(t1,t2)
>>> constraint = TimeConstraint(t1, t2)
"""
self.min = min
self.max = max
Expand Down Expand Up @@ -907,7 +903,8 @@ def __init__(self, periodic_event, min=None, max=None):

Examples
--------
To constrain observations on orbital phases between 0.4 and 0.6,
To constrain observations on orbital phases between 0.4 and 0.6:

>>> from astroplan import PeriodicEvent
>>> from astropy.time import Time
>>> import astropy.units as u
Expand All @@ -917,6 +914,7 @@ def __init__(self, periodic_event, min=None, max=None):
The minimum and maximum phase must be described on the interval [0, 1).
To constrain observations on orbital phases between 0.6 and 1.2, for
example, you should subtract one from the second number:

>>> constraint = PhaseConstraint(binary, min=0.6, max=0.2)
"""
self.periodic_event = periodic_event
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 @@ -22,6 +22,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
6 changes: 3 additions & 3 deletions astroplan/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class FixedTarget(Target):
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 @@ -125,8 +125,8 @@ def from_name(cls, query_name, name=None, **kwargs):
Examples
--------
>>> from astroplan import FixedTarget
>>> sirius = FixedTarget.from_name("Sirius")
>>> sirius.coord # doctest: +FLOAT_CMP
>>> 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 +REMOTE_DATA
<SkyCoord (ICRS): (ra, dec) in deg
( 101.28715533, -16.71611586)>
"""
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 @@ -33,6 +33,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 @@ -53,6 +54,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 @@ -96,6 +98,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 @@ -107,6 +110,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 @@ -128,6 +132,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 @@ -149,6 +154,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 @@ -174,6 +180,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
# astropy.coordinates.errors.NonRotationTransformationWarning
@pytest.mark.filterwarnings("ignore")
def test_sun_separation():
Expand All @@ -200,6 +207,7 @@ def test_sun_separation():
assert np.all(is_constraint_met == [False, True, True])


@pytest.mark.remote_data
# astropy.coordinates.errors.NonRotationTransformationWarning
@pytest.mark.filterwarnings("ignore")
def test_moon_separation():
Expand Down Expand Up @@ -230,6 +238,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 @@ -268,6 +277,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 @@ -284,6 +294,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 @@ -301,6 +312,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 @@ -364,6 +376,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 @@ -426,6 +439,7 @@ def test_rescale_minmax():
]


@pytest.mark.remote_data
@pytest.mark.parametrize('constraint', constraint_tests)
# astropy.coordinates.errors.NonRotationTransformationWarning
@pytest.mark.filterwarnings("ignore")
Expand All @@ -443,6 +457,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 @@ -455,6 +470,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 @@ -476,6 +492,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 @@ -1092,6 +1092,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 @@ -1222,6 +1223,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 @@ -1349,6 +1351,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 @@ -1358,6 +1361,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 @@ -1371,6 +1375,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 @@ -4,6 +4,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 @@ -21,7 +22,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 @@ -205,6 +207,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 @@ -222,6 +225,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 @@ -240,6 +244,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 @@ -12,6 +12,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 @@ -28,6 +29,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 @@ -44,6 +46,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: 6 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ envlist =
build_docs
linkcheck
codestyle
requires =
setuptools >= 30.3.0
pip >= 19.3.1
isolated_build = true
indexserver =
NIGHTLY = https://pypi.anaconda.org/scientific-python-nightly-wheels/simple

[testenv]

# Suppress display of matplotlib plots generated during docs build
setenv = MPLBACKEND=agg
setenv =
MPLBACKEND=agg
devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/astropy/simple https://pypi.anaconda.org/scientific-python-nightly-wheels/simple

# Pass through the following environment variables which may be needed for the CI
passenv = HOME, WINDIR, LC_ALL, LC_CTYPE, CC, CI, TRAVIS
passenv = HOME,WINDIR,LC_ALL,LC_CTYPE,CC,CI

# Run the tests in a temporary directory to make sure that we don't import
# this package from the source tree
Expand Down Expand Up @@ -63,7 +60,7 @@ deps =
astropy42: astropy==4.2.*

devdeps: numpy>=0.0.dev0
devdeps: git+https://github.com/astropy/astropy.git#egg=astropy
devdeps: astropy>=0.0.dev0

# The following indicates which extras_require from setup.cfg will be installed
extras =
Expand Down
Loading