Skip to content

Commit d1cdd1a

Browse files
committed
Chill down with some overzealous failure/warning catching.
Remove unused code as follow up of astropy#9582 Handle failures cased by numpy/numpy#8945
1 parent 96dafdf commit d1cdd1a

5 files changed

Lines changed: 36 additions & 52 deletions

File tree

‎astropy/coordinates/tests/test_frames.py‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Licensed under a 3-clause BSD style license - see LICENSE.rst
33

4-
54
from copy import deepcopy
65
import numpy as np
76
import pytest
@@ -15,7 +14,7 @@
1514
from astropy.coordinates.representation import REPRESENTATION_CLASSES
1615
from astropy.units import allclose
1716

18-
from .test_representation import unitphysics # this fixture is used below
17+
from .test_representation import unitphysics # this fixture is used below # noqa
1918

2019

2120
def setup_function(func):
@@ -1188,10 +1187,6 @@ def test_galactocentric_default_warning(reset_galactocentric_defaults):
11881187
from astropy.coordinates import (Galactocentric,
11891188
galactocentric_frame_defaults)
11901189

1191-
# Note: this is necessary because the doctests may alter the state of the
1192-
# class globally and simultaneously when the tests are run in parallel
1193-
# reset_galactocentric_defaults()
1194-
11951190
# Make sure a warning is thrown if the frame is created with no args
11961191
with pytest.warns(AstropyDeprecationWarning,
11971192
match=r"In v4\.1 and later versions"):
@@ -1211,9 +1206,7 @@ def test_galactocentric_references(reset_galactocentric_defaults):
12111206
# references in the "scientific paper"-sense
12121207

12131208
from astropy.coordinates import (Galactocentric,
1214-
galactocentric_frame_defaults,
1215-
BaseCoordinateFrame,
1216-
CartesianDifferential)
1209+
galactocentric_frame_defaults)
12171210

12181211
with galactocentric_frame_defaults.set('pre-v4.0'):
12191212
galcen_pre40 = Galactocentric()

‎astropy/units/tests/test_quantity_ufuncs.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -712,13 +712,13 @@ def test_onearg_test_ufuncs(self, ufunc):
712712
assert np.all(out == ufunc(q.value))
713713

714714
def test_sign(self):
715+
q = [1., np.inf, -np.inf, np.nan, -1., 0.] * u.m
716+
717+
# Ignore "invalid value encountered in sign" warning on Windows.
715718
if sys.platform.startswith('win'):
716-
ctx = pytest.warns(
717-
RuntimeWarning, match='invalid value encountered in sign')
719+
ctx = np.errstate(invalid='ignore')
718720
else:
719721
ctx = nullcontext()
720-
721-
q = [1., np.inf, -np.inf, np.nan, -1., 0.] * u.m
722722
with ctx:
723723
out = np.sign(q)
724724
assert not isinstance(out, u.Quantity)
@@ -919,14 +919,14 @@ def test_onearg_test_ufuncs_inplace(self, ufunc):
919919
assert np.all(out == ufunc(q.value))
920920

921921
def test_sign_inplace(self):
922+
q = [1., np.inf, -np.inf, np.nan, -1., 0.] * u.m
923+
check = np.empty(q.shape, q.dtype)
924+
925+
# Ignore "invalid value encountered in sign" warning on Windows.
922926
if sys.platform.startswith('win'):
923-
ctx = pytest.warns(
924-
RuntimeWarning, match='invalid value encountered in sign')
927+
ctx = np.errstate(invalid='ignore')
925928
else:
926929
ctx = nullcontext()
927-
928-
q = [1., np.inf, -np.inf, np.nan, -1., 0.] * u.m
929-
check = np.empty(q.shape, q.dtype)
930930
with ctx:
931931
np.sign(q.value, out=check)
932932

‎astropy/utils/iers/tests/test_iers.py‎

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import urllib.request
55
import warnings
6-
from urllib.error import URLError
76

87
import pytest
98
import numpy as np
@@ -252,6 +251,7 @@ def test_no_auto_download(self):
252251
assert type(t) is iers.IERS_B
253252

254253
@pytest.mark.remote_data
254+
@pytest.mark.xfail(reason='See issue 9600')
255255
def test_simple(self):
256256

257257
with iers.conf.set_temp('iers_auto_url', self.iers_a_url_1):
@@ -303,15 +303,11 @@ def test_simple(self):
303303

304304
# Look at times before and after the test file begins. This forces a new download.
305305
assert np.allclose(dat.ut1_utc(Time(50000, format='mjd').jd).value, 0.1292905)
306-
# https://github.com/astropy/astropy/issues/9600
307-
with pytest.raises(ValueError):
308-
assert np.allclose(dat.ut1_utc(Time(60000, format='mjd').jd).value, -0.3)
306+
assert np.allclose(dat.ut1_utc(Time(60000, format='mjd').jd).value, -0.3)
309307

310308
# Now the time range should be different.
311309
assert dat['MJD'][0] == 57359.0 * u.d
312-
# https://github.com/astropy/astropy/issues/9600 -- 60 becomes 48?
313-
with pytest.raises(AssertionError):
314-
assert dat['MJD'][-1] == (57539.0 + 60) * u.d
310+
assert dat['MJD'][-1] == (57539.0 + 60) * u.d
315311

316312

317313
@pytest.mark.remote_data
@@ -335,16 +331,22 @@ def test_IERS_B_parameters_loading_into_IERS_Auto():
335331
"correctly to IERS Auto".format(name)))
336332

337333

334+
# Issue with FTP, rework test into previous one when it's fixed
335+
@pytest.mark.xfail('TRAVIS')
338336
@pytest.mark.remote_data
339-
@pytest.mark.parametrize('url', (iers.IERS_A_URL, iers.IERS_A_URL_MIRROR))
340-
def test_iers_a_dl(url):
337+
def test_iers_a_dl():
338+
iersa_tab = iers.IERS_A.open(iers.IERS_A_URL, cache=False)
341339
try:
342-
iersa_tab = iers.IERS_A.open(url, cache=False)
343-
except URLError:
344-
if os.environ.get('TRAVIS') and url == iers.IERS_A_URL:
345-
pytest.xfail('FTP timed out on Travis CI')
346-
else:
347-
raise
340+
# some basic checks to ensure the format makes sense
341+
assert len(iersa_tab) > 0
342+
assert 'UT1_UTC_A' in iersa_tab.colnames
343+
finally:
344+
iers.IERS_A.close()
345+
346+
347+
@pytest.mark.remote_data
348+
def test_iers_a_dl_mirror():
349+
iersa_tab = iers.IERS_A.open(iers.IERS_A_URL_MIRROR, cache=False)
348350
try:
349351
# some basic checks to ensure the format makes sense
350352
assert len(iersa_tab) > 0

‎astropy/wcs/tests/test_pickle.py‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
import os
44
import pickle
5-
import sys
65

76
import numpy as np
87
import pytest
98
from numpy.testing import assert_array_almost_equal
109

11-
from astropy.utils.compat.context import nullcontext
1210
from astropy.utils.data import get_pkg_data_contents, get_pkg_data_fileobj
1311
from astropy.utils.exceptions import AstropyDeprecationWarning
1412
from astropy.utils.misc import NumpyRNGContext
@@ -84,17 +82,13 @@ def test_sip2():
8482
assert_array_almost_equal(world1, world2)
8583

8684

85+
# Ignore "PV2_2 = 0.209028857410973 invalid keyvalue" warning seen on Windows.
86+
@pytest.mark.filterwarnings(r'ignore:PV2_2')
8787
def test_wcs():
8888
header = get_pkg_data_contents(
8989
os.path.join("data", "outside_sky.hdr"), encoding='binary')
9090

91-
if sys.platform.startswith('win'):
92-
ctx = pytest.warns(FITSFixedWarning, match='invalid keyvalue')
93-
else:
94-
ctx = nullcontext()
95-
96-
with ctx:
97-
wcs1 = wcs.WCS(header)
91+
wcs1 = wcs.WCS(header)
9892
s = pickle.dumps(wcs1)
9993
with pytest.warns(FITSFixedWarning):
10094
wcs2 = pickle.loads(s)

‎astropy/wcs/tests/test_wcs.py‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,15 @@ def run():
115115
assert 'm/s' in str(item.message)
116116

117117

118+
# Ignore "PV2_2 = 0.209028857410973 invalid keyvalue" warning seen on Windows.
119+
@pytest.mark.filterwarnings(r'ignore:PV2_2')
118120
def test_outside_sky():
119121
"""
120122
From github issue #107
121123
"""
122-
if sys.platform.startswith('win'):
123-
ctx = pytest.warns(FITSFixedWarning, match='invalid keyvalue')
124-
else:
125-
ctx = nullcontext()
126-
127124
header = get_pkg_data_contents(
128125
'data/outside_sky.hdr', encoding='binary')
129-
with ctx:
130-
w = wcs.WCS(header)
126+
w = wcs.WCS(header)
131127

132128
assert np.all(np.isnan(w.wcs_pix2world([[100., 500.]], 0))) # outside sky
133129
assert np.all(np.isnan(w.wcs_pix2world([[200., 200.]], 0))) # outside sky
@@ -1222,12 +1218,11 @@ def test_footprint_contains():
12221218
hasCoord = test_wcs.footprint_contains(SkyCoord(240, 2, unit='deg'))
12231219
assert not hasCoord
12241220

1221+
# Ignore "invalid value encountered in less" warning on Windows.
12251222
if sys.platform.startswith('win'):
1226-
ctx = pytest.warns(
1227-
RuntimeWarning, match='invalid value encountered in less')
1223+
ctx = np.errstate(invalid='ignore')
12281224
else:
12291225
ctx = nullcontext()
1230-
12311226
with ctx:
12321227
hasCoord = test_wcs.footprint_contains(SkyCoord(24, 2, unit='deg'))
12331228
assert not hasCoord

0 commit comments

Comments
 (0)