Skip to content

Commit

Permalink
refactor: switch to public API in remote tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ManonMarchand committed Jun 20, 2024
1 parent 4e6f0ee commit 9e85f4e
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions astroquery/vizier/tests/test_vizier_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import astropy.units as u
from astropy.coordinates import SkyCoord

from astroquery import vizier
from astroquery.vizier import Vizier
from astroquery.utils import commons
from .conftest import scalar_skycoord, vector_skycoord

Expand All @@ -14,110 +14,110 @@
class TestVizierRemote:

def test_query_object(self):
result = vizier.core.Vizier.query_object(
result = Vizier.query_object(
"HD 226868", catalog=["NOMAD", "UCAC"])

assert isinstance(result, commons.TableList)

def test_query_another_object(self):
result = vizier.core.Vizier.query_region(
result = Vizier.query_region(
"AFGL 2591", radius='0d5m', catalog="B/iram/pdbi")
assert isinstance(result, commons.TableList)

def test_query_object_async(self):
response = vizier.core.Vizier.query_object_async(
response = Vizier.query_object_async(
"HD 226868", catalog=["NOMAD", "UCAC"])
assert response is not None

def test_query_region(self):
result = vizier.core.Vizier.query_region(
result = Vizier.query_region(
scalar_skycoord, radius=5 * u.deg, catalog=["HIP", "NOMAD", "UCAC"])

assert isinstance(result, commons.TableList)

def test_query_region_async(self):
response = vizier.core.Vizier.query_region_async(
response = Vizier.query_region_async(
scalar_skycoord, radius=5 * u.deg, catalog=["HIP", "NOMAD", "UCAC"])
assert response is not None

def test_query_region_async_galactic(self):
response = vizier.core.Vizier.query_region_async(
response = Vizier.query_region_async(
scalar_skycoord, radius=0.5 * u.deg, catalog="HIP", frame="galactic")
assert response is not None
payload = vizier.core.Vizier.query_region_async(
payload = Vizier.query_region_async(
scalar_skycoord, radius=0.5 * u.deg, catalog="HIP",
frame="galactic", get_query_payload=True)
assert "-c=G" in payload

def test_query_Vizier_instance(self):
with pytest.warns(UserWarning, match="xry : No such keyword"):
v = vizier.core.Vizier(
vizier = Vizier(
columns=['_RAJ2000', 'DEJ2000', 'B-V', 'Vmag', 'Plx'],
column_filters={"Vmag": ">10"}, keywords=["optical", "xry"])

result = v.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
result = vizier.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
assert isinstance(result, commons.TableList)
result = v.query_region(
result = vizier.query_region(
scalar_skycoord, width="5d0m0s", height="3d0m0s", catalog=["NOMAD", "UCAC"])
assert isinstance(result, commons.TableList)

def test_vizier_column_restriction(self):
# Check that the column restriction worked. At least some of these
# catalogs include Bmag's
v = vizier.core.Vizier(
vizier = Vizier(
columns=['_RAJ2000', 'DEJ2000', 'B-V', 'Vmag', 'Plx'],
column_filters={"Vmag": ">10"}, keywords=["optical", "X-ray"])

result = v.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
result = vizier.query_object("HD 226868", catalog=["NOMAD", "UCAC"])
for table in result:
assert 'Bmag' not in table.columns

@pytest.mark.parametrize('all', ('all', '*'))
def test_alls_withaddition(self, all):
# Check that all the expected columns are there plus the _r
# (radius from target) that we've added
v = vizier.core.Vizier(columns=[all, "+_r"], catalog="II/246")
result = v.query_region("HD 226868", radius="20s")
vizier = Vizier(columns=[all, "+_r"], catalog="II/246")
result = vizier.query_region("HD 226868", radius="20s")
table = result['II/246/out']
assert 'Jmag' in table.columns
assert '_r' in table.columns

def test_get_catalogs(self):
result = vizier.core.Vizier.get_catalogs('J/ApJ/706/83')
result = Vizier.get_catalogs('J/ApJ/706/83')
assert isinstance(result, commons.TableList)

def test_get_catalog_metadata(self):
meta = vizier.core.Vizier(catalog="I/324").get_catalog_metadata()
meta = Vizier(catalog="I/324").get_catalog_metadata()
assert meta['title'] == "The Initial Gaia Source List (IGSL)"

def test_query_two_wavelengths(self):
v = vizier.core.Vizier(
vizier = Vizier(
columns=['_RAJ2000', 'DEJ2000', 'B-V', 'Vmag', 'Plx'],
column_filters={"Vmag": ">10"}, keywords=["optical", "radio"])
v.ROW_LIMIT = 1
v.query_object('M 31')
vizier.ROW_LIMIT = 1
vizier.query_object('M 31')

def test_regressiontest_invalidtable(self):
V = vizier.core.Vizier(
vizier = Vizier(
columns=['all'], ucd='(spect.dopplerVeloc*|phys.veloc*)',
keywords=['Radio', 'IR'], row_limit=5000)
C = SkyCoord(359.61687 * u.deg, -0.242457 * u.deg, frame="galactic")
coordinate = SkyCoord(359.61687 * u.deg, -0.242457 * u.deg, frame="galactic")

# With newer versions UnitsWarning may be issued as well
with pytest.warns() as w:
V.query_region(C, radius=2 * u.arcmin)
with pytest.warns() as warnings:
vizier.query_region(coordinate, radius=2 * u.arcmin)

for i in w:
for i in warnings:
message = str(i.message)
assert ("VOTABLE parsing raised exception" in message or "not supported by the VOUnit standard" in message)

def test_multicoord(self):

# Regression test: the columns of the default should never
# be modified from default
assert vizier.core.Vizier.columns == ['*']
assert Vizier.columns == ['*']
# Coordinate selection is entirely arbitrary
result = vizier.core.Vizier.query_region(
result = Vizier.query_region(
vector_skycoord, radius=10 * u.arcsec, catalog=["HIP", "NOMAD", "UCAC"])

assert len(result) >= 5
Expand All @@ -126,31 +126,31 @@ def test_multicoord(self):
assert result['I/239/hip_main']['HIP'] == 98298

def test_findcatalog_maxcatalog(self):
V = vizier.core.Vizier()
cats = V.find_catalogs('eclipsing binary planets', max_catalogs=5000)
vizier = Vizier()
cats = vizier.find_catalogs('eclipsing binary planets', max_catalogs=5000)
assert len(cats) >= 39 # as of 2024

def test_findcatalog_ucd(self):
# this fails for VizieR 7.33.3, should work in next releases
V = vizier.core.Vizier()
ucdresult = V(ucd='phys.albedo').find_catalogs('mars', max_catalogs=5000)
result = V.find_catalogs('mars', max_catalogs=5000)
vizier = Vizier()
ucdresult = vizier(ucd='phys.albedo').find_catalogs('mars', max_catalogs=5000)
result = vizier.find_catalogs('mars', max_catalogs=5000)

assert len(ucdresult) >= 1
assert len(result) >= 11
# important part: we're testing that UCD is parsed and some catalogs are ruled out
assert len(ucdresult) < len(result)

def test_asu_tsv_return_type(self):
V = vizier.core.Vizier()
result = V.query_object("HD 226868", catalog=["NOMAD", "UCAC"], return_type='asu-tsv', cache=False)
vizier = Vizier()
result = vizier.query_object("HD 226868", catalog=["NOMAD", "UCAC"], return_type='asu-tsv', cache=False)

assert isinstance(result, list)
assert len(result) == 3

def test_query_constraints(self):
V = vizier.core.Vizier(row_limit=3)
result = V.query_constraints(catalog="I/130/main", mB2="=14.7")[0]
vizier = Vizier(row_limit=3)
result = vizier.query_constraints(catalog="I/130/main", mB2="=14.7")[0]
# row_limit is taken in account
assert len(result) == 3
# the criteria is respected
Expand Down

0 comments on commit 9e85f4e

Please sign in to comment.