Skip to content

Commit

Permalink
Fixing more warnings and removing them from the config
Browse files Browse the repository at this point in the history
  • Loading branch information
bsipocz committed Sep 11, 2022
1 parent 6c79576 commit 6eb4d9d
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 36 deletions.
4 changes: 3 additions & 1 deletion astroquery/alfalfa/tests/test_alfalfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def patch_get_readable_fileobj(request):
@contextmanager
def get_readable_fileobj_mockreturn(filename, **kwargs):
file_obj = data_path(DATA_FILES['spectrum']) # TODO: add images option
yield open(file_obj, 'rb') # read as bytes, assuming FITS
# read as bytes, assuming FITS
with open(file_obj, 'rb') as inputfile:
yield inputfile

mp = request.getfixturevalue("monkeypatch")

Expand Down
6 changes: 3 additions & 3 deletions astroquery/besancon/tests/test_besancon.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ def get_readable_fileobj_mockreturn(filename, **kwargs):
if isinstance(filename, str):
if '1376235131.430670' in filename:
is_binary = kwargs.get('encoding', None) == 'binary'
file_obj = open(data_path('1376235131.430670.resu'),
"r" + ('b' if is_binary else ''))
with open(data_path('1376235131.430670.resu'), "r" + ('b' if is_binary else '')) as file_obj:
yield file_obj
else:
file_obj = filename
yield file_obj
yield file_obj

mp = request.getfixturevalue("monkeypatch")

Expand Down
13 changes: 9 additions & 4 deletions astroquery/casda/tests/test_casda.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import astropy.units as u
from astropy.table import Table, Column
from astropy.io.votable import parse
from astropy.io.votable.exceptions import W03, W50
from astroquery import log
import numpy as np

Expand Down Expand Up @@ -269,7 +270,8 @@ def test_query_region_async_box(patch_get):


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

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

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


def test_cutout_unauthorised(patch_get):
Expand Down
7 changes: 3 additions & 4 deletions astroquery/ipac/irsa/ibe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
https://irsa.ipac.caltech.edu/ibe/
"""


import os
import webbrowser
from bs4 import BeautifulSoup
Expand Down Expand Up @@ -270,7 +269,7 @@ def list_missions(self, cache=True):
response = self._request('GET', url, timeout=self.TIMEOUT,
cache=cache)

root = BeautifulSoup(response.text)
root = BeautifulSoup(response.text, 'html5lib')
links = root.findAll('a')

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

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

root = BeautifulSoup(response.text)
root = BeautifulSoup(response.text, 'html5lib')
return [tr.find('td').string for tr in root.findAll('tr')[1:]]

# Unfortunately, the URL construction for each data set is different, and
Expand Down
8 changes: 6 additions & 2 deletions astroquery/ipac/ned/tests/test_ned.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import os
from contextlib import contextmanager

from numpy import testing as npt
import pytest
Expand Down Expand Up @@ -47,12 +48,14 @@ def patch_get(request):

@pytest.fixture
def patch_get_readable_fileobj(request):
@contextmanager
def get_readable_fileobj_mockreturn(filename, cache=True, encoding=None,
show_progress=True):
# Need to read FITS files with binary encoding: should raise error
# otherwise
assert encoding == 'binary'
return open(data_path(DATA_FILES['image']), 'rb')
with open(data_path(DATA_FILES['image']), 'rb') as infile:
yield infile

mp = request.getfixturevalue("monkeypatch")

Expand Down Expand Up @@ -138,7 +141,8 @@ def test_photometry(patch_get):


def test_extract_image_urls():
html_in = open(data_path(DATA_FILES['extract_urls']), 'r').read()
with open(data_path(DATA_FILES['extract_urls']), 'r') as infile:
html_in = infile.read()
url_list = ned.core.Ned._extract_image_urls(html_in)
assert len(url_list) == 5
for url in url_list:
Expand Down
2 changes: 1 addition & 1 deletion astroquery/mast/tests/test_mast.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ def test_catalogs_query_criteria(patch_post):
assert isinstance(result, Table)

with pytest.raises(InvalidQueryError) as invalid_query:
mast.Catalogs.query_criteria(catalog="Tic", objectName="M10")
mast.Catalogs.query_criteria(catalog="Tic", objectname="M10")
assert "non-positional" in str(invalid_query.value)


Expand Down
11 changes: 6 additions & 5 deletions astroquery/nvas/tests/test_nvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ def patch_get_readable_fileobj(request):
def get_readable_fileobj_mockreturn(filename, **kwargs):
encoding = kwargs.get('encoding', None)
if encoding == 'binary':
file_obj = open(data_path(DATA_FILES["image"]), 'rb')
with open(data_path(DATA_FILES["image"]), 'rb') as file_obj:
yield file_obj
else:
file_obj = open(data_path(DATA_FILES["image"]),
"r", encoding=encoding)
yield file_obj
with open(data_path(DATA_FILES["image"]), "r", encoding=encoding) as file_obj:
yield file_obj

mp = request.getfixturevalue("monkeypatch")

Expand Down Expand Up @@ -95,7 +95,8 @@ def test_parse_coordinates(coordinates):


def test_extract_image_urls():
html_in = open(data_path(DATA_FILES['image_search']), 'r').read()
with open(data_path(DATA_FILES['image_search']), 'r') as infile:
html_in = infile.read()
image_list = nvas.core.Nvas.extract_image_urls(html_in)
assert len(image_list) == 2

Expand Down
7 changes: 5 additions & 2 deletions astroquery/ogle/tests/test_ogle.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import pytest
from astropy.coordinates import SkyCoord
from astropy import units as u
from astropy.utils.exceptions import AstropyDeprecationWarning

from astroquery.utils.mocks import MockResponse


DATA_FILES = {'gal_0_3': 'gal_0_3.txt'}


Expand Down Expand Up @@ -49,11 +52,11 @@ def test_ogle_list(patch_post):
co_list = [co, co, co]
ogle.core.Ogle.query_region(coord=co_list)


def test_ogle_list_values(patch_post):
"""
Test multiple pointings using a nested-list of decimal degree Galactic
coordinates
"""
co_list = [[0, 0, 0], [3, 3, 3]]
ogle.core.Ogle.query_region(coord=co_list)
with pytest.warns(AstropyDeprecationWarning):
ogle.core.Ogle.query_region(coord=co_list)
2 changes: 1 addition & 1 deletion astroquery/vamdc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__doctest_skip__ = ['VamdcClass.*']


@deprecated('0.4.2', 'the module relies on an unmaintained library and is'
@deprecated('0.4.2', 'the vamdc astroquery module relies on an unmaintained library and is'
'considered deprecated until completely refactored or upstream'
'is stablised.')
@async_to_sync
Expand Down
25 changes: 12 additions & 13 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,25 @@ filterwarnings =
ignore: Experimental:UserWarning:
# This is a temporary measure, all of these should be fixed:
ignore:distutils Version classes are deprecated:DeprecationWarning
ignore::pytest.PytestUnraisableExceptionWarning
ignore::numpy.VisibleDeprecationWarning
ignore:unclosed <ssl.SSLSocket:ResourceWarning
ignore::UserWarning
ignore::astroquery.exceptions.InputWarning
ignore::astropy.utils.exceptions.AstropyDeprecationWarning
ignore::astropy.io.votable.exceptions.W03
ignore::astropy.io.votable.exceptions.W06
ignore::astropy.io.votable.exceptions.W15
# Various VO warnings from vo_conesearch
ignore::astropy.io.votable.exceptions.W21
ignore::astropy.io.votable.exceptions.W22
ignore::astropy.io.votable.exceptions.W42
ignore::astropy.io.votable.exceptions.W49
ignore::astropy.io.votable.exceptions.W50
ignore:leap-second auto-update failed:astropy.utils.exceptions.AstropyWarning
ignore:numpy.ndarray size changed:RuntimeWarning
ignore:OverflowError converting::astropy
# Upstream, remove when fixed, PRs have been opened
ignore::DeprecationWarning:pyvo
ignore::DeprecationWarning:regions
# utils.commons.FileContainer needs a refactor
ignore:FITS files must be read as binaries:astroquery.exceptions.InputWarning
# utils.commons.parse_coordinates, we should remove its usage:
ignore:Coordinate string is being interpreted as an ICRS coordinate:astroquery.exceptions.InputWarning
ignore:Coordinate string is being interpreted as an ICRS coordinate:UserWarning
# Warnings from deprecated or known-to-be-broken modules
ignore:The legacy NRAO archive this module uses has been retired:UserWarning
ignore:vamdclib could not be imported; the vamdc astroquery module will not work:UserWarning
ignore:the vamdc astroquery module:astropy.utils.exceptions.AstropyDeprecationWarning
# Leap second update related warning
ignore:leap-second auto-update failed:astropy.utils.exceptions.AstropyWarning
# Should ignore these for astropy<5.0
ignore:getName|currentThread:DeprecationWarning:astropy
# This should be cleared once we requre astropy>=4.1
Expand Down

0 comments on commit 6eb4d9d

Please sign in to comment.