Skip to content

Commit 50ea662

Browse files
committed
Fixing more warnings and removing them from the config
1 parent b0b1a8a commit 50ea662

File tree

22 files changed

+118
-75
lines changed

22 files changed

+118
-75
lines changed

astroquery/alfalfa/tests/test_alfalfa.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def patch_get_readable_fileobj(request):
3838
@contextmanager
3939
def get_readable_fileobj_mockreturn(filename, **kwargs):
4040
file_obj = data_path(DATA_FILES['spectrum']) # TODO: add images option
41-
yield open(file_obj, 'rb') # read as bytes, assuming FITS
41+
# read as bytes, assuming FITS
42+
with open(file_obj, 'rb') as inputfile:
43+
yield inputfile
4244

4345
mp = request.getfixturevalue("monkeypatch")
4446

astroquery/besancon/tests/test_besancon.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ def get_readable_fileobj_mockreturn(filename, **kwargs):
6565
if isinstance(filename, str):
6666
if '1376235131.430670' in filename:
6767
is_binary = kwargs.get('encoding', None) == 'binary'
68-
file_obj = open(data_path('1376235131.430670.resu'),
69-
"r" + ('b' if is_binary else ''))
68+
with open(data_path('1376235131.430670.resu'), "r" + ('b' if is_binary else '')) as file_obj:
69+
yield file_obj
7070
else:
7171
file_obj = filename
72-
yield file_obj
72+
yield file_obj
7373

7474
mp = request.getfixturevalue("monkeypatch")
7575

astroquery/cadc/tests/test_cadctap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ def raise_for_status(self):
177177
class CapabilitiesResponse:
178178
def __init__(self):
179179
caps_file = data_path('tap_caps.xml')
180-
self.text = open(caps_file, 'r').read()
180+
with open(caps_file, 'r') as infile:
181+
text = infile.read()
182+
self.text = text
181183

182184
def raise_for_status(self):
183185
pass

astroquery/cadc/tests/test_cadctap_remote.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def test_query_region(self):
6666
assert len(result) == len(result2[result2['collection'] == 'CFHT'])
6767

6868
# search for a target
69-
results = cadc.query_region(SkyCoord.from_name('M31'), radius=0.016)
69+
with pytest.warns(UserWarning, match='Radius should be of '):
70+
results = cadc.query_region(SkyCoord.from_name('M31'), radius=0.016)
7071
assert len(results) > 20
7172

7273
def test_query_name(self):

astroquery/casda/tests/test_casda.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import astropy.units as u
1212
from astropy.table import Table, Column
1313
from astropy.io.votable import parse
14+
from astropy.io.votable.exceptions import W03, W50
1415
from astroquery import log
1516
import numpy as np
1617

@@ -269,7 +270,8 @@ def test_query_region_async_box(patch_get):
269270

270271

271272
def test_filter_out_unreleased():
272-
all_records = parse(data_path('partial_unreleased.xml'), verify='warn').get_first_table().to_table()
273+
with pytest.warns(W03):
274+
all_records = parse(data_path('partial_unreleased.xml'), verify='warn').get_first_table().to_table()
273275
assert all_records[0]['obs_release_date'] == '2017-08-02T03:51:19.728Z'
274276
assert all_records[1]['obs_release_date'] == '2218-01-02T16:51:00.728Z'
275277
assert all_records[2]['obs_release_date'] == ''
@@ -331,7 +333,8 @@ def test_stage_data(patch_get):
331333
casda = Casda()
332334
fake_login(casda, USERNAME, PASSWORD)
333335
casda.POLL_INTERVAL = 1
334-
urls = casda.stage_data(table, verbose=True)
336+
with pytest.warns(W50, match="Invalid unit string 'pixels'"):
337+
urls = casda.stage_data(table, verbose=True)
335338
assert urls == ['http://casda.csiro.au/download/web/111-000-111-000/askap_img.fits.checksum',
336339
'http://casda.csiro.au/download/web/111-000-111-000/askap_img.fits']
337340

@@ -348,7 +351,8 @@ def test_cutout(patch_get):
348351
casda = Casda()
349352
fake_login(casda, USERNAME, PASSWORD)
350353
casda.POLL_INTERVAL = 1
351-
urls = casda.cutout(table, coordinates=centre, radius=radius, verbose=True)
354+
with pytest.warns(W50, match="Invalid unit string 'pixels'"):
355+
urls = casda.cutout(table, coordinates=centre, radius=radius, verbose=True)
352356
assert urls == ['http://casda.csiro.au/download/web/111-000-111-000/cutout.fits.checksum',
353357
'http://casda.csiro.au/download/web/111-000-111-000/cutout.fits']
354358

@@ -363,7 +367,8 @@ def test_cutout_no_args(patch_get):
363367
casda.POLL_INTERVAL = 1
364368
with pytest.raises(ValueError,
365369
match=r"Please provide cutout parameters such as coordinates, band or channel\."):
366-
casda.cutout(table)
370+
with pytest.warns(W50, match="Invalid unit string 'pixels'"):
371+
casda.cutout(table)
367372

368373

369374
def test_cutout_unauthorised(patch_get):

astroquery/exoplanet_orbit_database/exoplanet_orbit_database.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
import json
33
import os
4+
import warnings
45

56
from astropy.utils.data import download_file
67
from astropy.io import ascii
@@ -30,9 +31,9 @@ def __init__(self):
3031
def param_units(self):
3132
if self._param_units is None:
3233
module_dir = os.path.dirname(os.path.abspath(__file__))
33-
units_file = open(os.path.join(module_dir, 'data',
34-
'exoplanet_orbit_database_units.json'))
35-
self._param_units = json.load(units_file)
34+
filename = os.path.join(module_dir, 'data', 'exoplanet_orbit_database_units.json')
35+
with open(filename) as units_file:
36+
self._param_units = json.load(units_file)
3637

3738
return self._param_units
3839

@@ -82,7 +83,11 @@ def get_table(self, cache=True, show_progress=True, table_path=None):
8283
except ValueError:
8384
print(f"WARNING: Unit {self.param_units[col]} not recognised")
8485

85-
self._table = QTable(exoplanets_table)
86+
# Masked quantities are not supported in older astropy, warnings are raised for <v5.0
87+
with warnings.catch_warnings():
88+
warnings.filterwarnings('ignore', message='dropping mask in Quantity column',
89+
category=UserWarning)
90+
self._table = QTable(exoplanets_table)
8691

8792
return self._table
8893

astroquery/heasarc/tests/test_heasarc_remote_isdc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44
import requests
55
from astropy.time import Time, TimeDelta
6+
import astropy.units as u
67

78
from ...heasarc import Heasarc, Conf
89
from ...utils import commons
@@ -83,7 +84,7 @@ def test_compare_time(self, patch_get):
8384

8485
heasarc = Heasarc()
8586

86-
month_ago = (Time.now() - TimeDelta(30)).isot[:10]
87+
month_ago = (Time.now() - TimeDelta(30 * u.day)).isot[:10]
8788
today = Time.now().isot[:10]
8889
T = month_ago + " .. " + today
8990

astroquery/ipac/irsa/ibe/core.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
https://irsa.ipac.caltech.edu/ibe/
99
"""
1010

11-
1211
import os
1312
import webbrowser
1413
from bs4 import BeautifulSoup
@@ -270,7 +269,7 @@ def list_missions(self, cache=True):
270269
response = self._request('GET', url, timeout=self.TIMEOUT,
271270
cache=cache)
272271

273-
root = BeautifulSoup(response.text)
272+
root = BeautifulSoup(response.text, 'html5lib')
274273
links = root.findAll('a')
275274

276275
missions = [os.path.basename(a.attrs['href'].rstrip('/'))
@@ -308,7 +307,7 @@ def list_datasets(self, mission=None, cache=True):
308307
response = self._request('GET', url, timeout=self.TIMEOUT,
309308
cache=cache)
310309

311-
root = BeautifulSoup(response.text)
310+
root = BeautifulSoup(response.text, 'html5lib')
312311
links = root.findAll('a')
313312
datasets = [a.text for a in links
314313
if a.attrs['href'].count('/') >= 4 # shown as '..'; ignore
@@ -362,7 +361,7 @@ def list_tables(self, mission=None, dataset=None, cache=True):
362361
response = self._request('GET', url, timeout=self.TIMEOUT,
363362
cache=cache)
364363

365-
root = BeautifulSoup(response.text)
364+
root = BeautifulSoup(response.text, 'html5lib')
366365
return [tr.find('td').string for tr in root.findAll('tr')[1:]]
367366

368367
# Unfortunately, the URL construction for each data set is different, and

astroquery/ipac/irsa/sha/tests/test_sha.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def data_path(filename):
2222
def get_mockreturn(url, params=None, stream=False, timeout=10, **kwargs):
2323
if stream:
2424
filename = data_path(DATA_FILES['img'])
25-
return MockResponse(open(filename, 'rb').read(),
26-
content_type='image/fits', **kwargs)
25+
with open(filename, 'rb') as infile:
26+
return MockResponse(infile.read(), content_type='image/fits', **kwargs)
2727
elif params['RA'] == 163.6136:
2828
filename = data_path(DATA_FILES['pos_t'])
2929
elif params['NAIFID'] == 2003226:

astroquery/ipac/ned/tests/test_ned.py

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

33
import os
4+
from contextlib import contextmanager
45

56
from numpy import testing as npt
67
import pytest
@@ -47,12 +48,14 @@ def patch_get(request):
4748

4849
@pytest.fixture
4950
def patch_get_readable_fileobj(request):
51+
@contextmanager
5052
def get_readable_fileobj_mockreturn(filename, cache=True, encoding=None,
5153
show_progress=True):
5254
# Need to read FITS files with binary encoding: should raise error
5355
# otherwise
5456
assert encoding == 'binary'
55-
return open(data_path(DATA_FILES['image']), 'rb')
57+
with open(data_path(DATA_FILES['image']), 'rb') as infile:
58+
yield infile
5659

5760
mp = request.getfixturevalue("monkeypatch")
5861

@@ -138,7 +141,8 @@ def test_photometry(patch_get):
138141

139142

140143
def test_extract_image_urls():
141-
html_in = open(data_path(DATA_FILES['extract_urls']), 'r').read()
144+
with open(data_path(DATA_FILES['extract_urls']), 'r') as infile:
145+
html_in = infile.read()
142146
url_list = ned.core.Ned._extract_image_urls(html_in)
143147
assert len(url_list) == 5
144148
for url in url_list:

0 commit comments

Comments
 (0)