Skip to content

Commit

Permalink
fix table->catalog in remote tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zoghbi-a committed Jan 6, 2025
1 parent d46fef2 commit 5ecfa95
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
18 changes: 9 additions & 9 deletions astroquery/heasarc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def query_region(self, position=None, catalog=None, radius=None, *,

# save the response in case we want to use it later
self._query_result = response
self._catalogname = catalog
self._catalog_name = catalog

Check warning on line 423 in astroquery/heasarc/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/heasarc/core.py#L422-L423

Added lines #L422 - L423 were not covered by tests

table = response.to_table()
if 'search_offset_' in table.colnames:
Expand Down Expand Up @@ -459,7 +459,7 @@ def query_object(self, object_name, mission, *,
return self.query_region(pos, catalog=mission, spatial='cone',

Check warning on line 459 in astroquery/heasarc/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/heasarc/core.py#L458-L459

Added lines #L458 - L459 were not covered by tests
get_query_payload=get_query_payload)

def get_datalinks(self, query_result=None, catalogname=None):
def get_datalinks(self, query_result=None, catalog_name=None):
"""Get links to data products
Use vo/datalinks to query the data products for some query_results.
Expand All @@ -469,7 +469,7 @@ def get_datalinks(self, query_result=None, catalogname=None):
A table that contain the search results. Typically as
returned by query_region. If None, use the table from the
most recent query_region call.
catalogname : str
catalog_name : str
The catalog name for the which the query_result belongs to.
If None, use the one from the most recent query_region call.
Expand All @@ -496,16 +496,16 @@ def get_datalinks(self, query_result=None, catalogname=None):
'query_result needs to be the output of '
'query_region or a subset.')

if catalogname is None:
catalogname = self._catalogname
if catalog_name is None:
catalog_name = self._catalog_name
if not (

Check warning on line 501 in astroquery/heasarc/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/heasarc/core.py#L499-L501

Added lines #L499 - L501 were not covered by tests
isinstance(catalogname, str)
and catalogname in self.tap.tables.keys()
isinstance(catalog_name, str)
and catalog_name in self.tap.tables.keys()
):
raise ValueError(f'Unknown catalog name: {catalogname}')
raise ValueError(f'Unknown catalog name: {catalog_name}')

Check warning on line 505 in astroquery/heasarc/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/heasarc/core.py#L505

Added line #L505 was not covered by tests

# datalink url
dlink_url = f'{self.VO_URL}/datalink/{catalogname}'
dlink_url = f'{self.VO_URL}/datalink/{catalog_name}'

Check warning on line 508 in astroquery/heasarc/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/heasarc/core.py#L508

Added line #L508 was not covered by tests

query = pyvo.dal.adhoc.DatalinkQuery(

Check warning on line 510 in astroquery/heasarc/core.py

View check run for this annotation

Codecov / codecov/patch

astroquery/heasarc/core.py#L510

Added line #L510 was not covered by tests
baseurl=dlink_url,
Expand Down
2 changes: 1 addition & 1 deletion astroquery/heasarc/tests/test_heasarc.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def test_get_datalink():
Heasarc.get_datalinks([1, 2])

with pytest.raises(ValueError, match="No __row column found"):
Heasarc.get_datalinks(Table({"id": [1, 2, 3.0]}), catalogname="xray")
Heasarc.get_datalinks(Table({"id": [1, 2, 3.0]}), catalog_name="xray")


def test_download_data__empty():
Expand Down
76 changes: 38 additions & 38 deletions astroquery/heasarc/tests/test_heasarc_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_query_region_cone(self, coordinates):
"""
result = Heasarc.query_region(
coordinates,
table="suzamaster",
catalog="suzamaster",
spatial="cone",
columns="*",
radius=1 * u.arcmin,
Expand All @@ -94,7 +94,7 @@ def test_query_columns_radius(self):
Test selection of only a few columns, and using a bigger radius
"""
result = Heasarc.query_region(
"NGC 4151", table="suzamaster", columns="ra,dec,obsid",
"NGC 4151", catalog="suzamaster", columns="ra,dec,obsid",
radius=10 * u.arcmin
)
assert len(result) == 4
Expand All @@ -104,7 +104,7 @@ def test_query_columns_radius(self):
def test_query_region_box(self):
result = Heasarc.query_region(
"182d38m08.64s 39d24m21.06s",
table="suzamaster",
catalog="suzamaster",
columns="*",
spatial="box",
width=2 * u.arcmin,
Expand All @@ -116,40 +116,40 @@ def test_query_region_polygon(self):
polygon = [(10.1, 10.1), (10.0, 10.1), (10.0, 10.0)]
with pytest.warns(Warning) as warnings:
result = Heasarc.query_region(
table="suzamaster", spatial="polygon", polygon=polygon
catalog="suzamaster", spatial="polygon", polygon=polygon
)
assert warnings[0].category == UserWarning
assert ("Polygon endpoints are being interpreted" in
warnings[0].message.args[0])
assert warnings[1].category == NoResultsWarning
assert isinstance(result, Table)

def test_list_tables(self):
tables = Heasarc.tables()
# Number of available tables may change over time, test only for
# significant drop. (at the time of writing there are 1020 tables
def test_list_catalogs(self):
catalogs = Heasarc.list_catalogs()
# Number of available catalogs may change over time, test only for
# significant drop. (at the time of writing there are 1020 catalogs
# in the list).
assert len(tables) > 1000
assert len(catalogs) > 1000

def test_list_tables__master(self):
tables = list(Heasarc.tables(master=True)["name"])
assert "numaster" in tables
assert "nicermastr" in tables
assert "xmmmaster" in tables
assert "swiftmastr" in tables
def test_list_catalogs__master(self):
catalogs = list(Heasarc.catalogs(master=True)["name"])
assert "numaster" in catalogs
assert "nicermastr" in catalogs
assert "xmmmaster" in catalogs
assert "swiftmastr" in tablcatalogses

def test_list_tables__keywords(self):
tables = list(Heasarc.tables(keywords="nustar", master=True)["name"])
assert len(tables) == 1 and "numaster" in tables
def test_list_catalogs__keywords(self):
catalogs = list(Heasarc.list_catalogs(keywords="nustar", master=True)["name"])
assert len(catalogs) == 1 and "numaster" in catalogs

tables = list(Heasarc.tables(keywords="xmm", master=True)["name"])
assert len(tables) == 1 and "xmmmaster" in tables
catalogs = list(Heasarc.list_catalogs(keywords="xmm", master=True)["name"])
assert len(catalogs) == 1 and "xmmmaster" in catalogs

tables = list(Heasarc.tables(keywords=["swift", "rosat"],
catalogs = list(Heasarc.list_catalogs(keywords=["swift", "rosat"],
master=True)["name"])
assert "swiftmastr" in tables
assert "rosmaster" in tables
assert "rassmaster" in tables
assert "swiftmastr" in catalogs
assert "rosmaster" in catalogs
assert "rassmaster" in catalogs

@pytest.mark.skipif(
Version(pyvo.__version__) < Version('1.4'),
Expand All @@ -169,19 +169,19 @@ def test_tap__maxrec(self):

@pytest.mark.parametrize("tdefault", DEFAULT_COLS)
def test__get_default_columns(self, tdefault):
table, tdef = tdefault
remote_default = list(Heasarc._get_default_columns(table))
catalog, tdef = tdefault
remote_default = list(Heasarc._get_default_columns(catalog))
assert remote_default == tdef

def test_get_datalinks__wrongtable(self):
with pytest.raises(ValueError, match="Unknown table name:"):
def test_get_datalinks__wrongcatalog(self):
with pytest.raises(ValueError, match="Unknown catalog name:"):
Heasarc.get_datalinks(
Table({"__row": [1, 2, 3.0]}), tablename="wrongtable"
Table({"__row": [1, 2, 3.0]}), catalog_name="wrongcatalog"
)

def test_get_datalinks__xmmmaster(self):
links = Heasarc.get_datalinks(
Table({"__row": [4154, 4155]}), tablename="xmmmaster"
Table({"__row": [4154, 4155]}), catalog_name="xmmmaster"
)
assert len(links) == 2
assert "access_url" in links.colnames
Expand Down Expand Up @@ -287,7 +287,7 @@ def test_custom_args(self):
heasarc = Heasarc

with pytest.warns(AstropyDeprecationWarning):
table = heasarc.query_object(
catalog = heasarc.query_object(
object_name,
mission=mission,
radius="1 degree",
Expand All @@ -296,17 +296,17 @@ def test_custom_args(self):
good_isgri=">1000",
cache=False,
)
assert len(table) > 0
assert len(catalog) > 0

def test_basic_example(self):
mission = "rosmaster"
object_name = "3c273"

heasarc = Heasarc
with pytest.warns(AstropyDeprecationWarning):
table = heasarc.query_object(object_name, mission=mission)
catalog = heasarc.query_object(object_name, mission=mission)

assert len(table) == 63
assert len(catalog) == 63

def test_mission_list(self):
heasarc = Heasarc
Expand Down Expand Up @@ -338,11 +338,11 @@ def test_query_region(self):
skycoord_3C_273 = SkyCoord("12h29m06.70s +02d03m08.7s", frame="icrs")

with pytest.warns(AstropyDeprecationWarning):
table = heasarc.query_region(
catalog = heasarc.query_region(
skycoord_3C_273, mission=mission, radius="1 degree"
)

assert len(table) == 63
assert len(catalog) == 63

def test_query_region_nohits(self):
"""
Expand All @@ -354,11 +354,11 @@ def test_query_region_nohits(self):
# This was an example coordinate that returned nothing
# Since Fermi is still active, it is possible that sometime in the
# future an event will occur here.
table = heasarc.query_region(
catalog = heasarc.query_region(
SkyCoord(0.28136 * u.deg, -0.09789 * u.deg, frame="fk5"),
mission="hitomaster",
radius=0.1 * u.deg,
)
assert warnings[0].category == AstropyDeprecationWarning
assert warnings[1].category == NoResultsWarning
assert len(table) == 0
assert len(catalog) == 0

0 comments on commit 5ecfa95

Please sign in to comment.