Skip to content

Commit 17e06e8

Browse files
ManonMarchandbsipocz
authored andcommitted
maint: remove list_fields_async
everything done with list_fields
1 parent 2ced5b3 commit 17e06e8

File tree

2 files changed

+11
-40
lines changed

2 files changed

+11
-40
lines changed

astroquery/mocserver/core.py

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def query_async(
421421
return request_payload
422422
return self._request(**params_d)
423423

424-
def list_fields(self, keyword=None, cache=True):
424+
def list_fields(self, keyword=None, *, cache=True):
425425
"""List MOC Server fields.
426426
427427
In the MOC Server, the fields are free. This means that anyone publishing there
@@ -458,7 +458,9 @@ def list_fields(self, keyword=None, cache=True):
458458
hips_publisher 14 CDS
459459
460460
"""
461-
fields_descriptions = dict(self.list_fields_async(cache=cache).json()[0])
461+
fields_descriptions = dict(
462+
self._request(method="GET", url=self.URL, timeout=self.TIMEOUT, cache=cache,
463+
params={"get": "example", "fmt": "json"}).json()[0])
462464
occurrences = [
463465
int(value.split("x")[0][1:]) for value in fields_descriptions.values()
464466
]
@@ -478,37 +480,6 @@ def list_fields(self, keyword=None, cache=True):
478480
]
479481
return list_fields
480482

481-
def list_fields_async(self, cache=True):
482-
"""List MOC Server fields asynchronously.
483-
484-
In the MOC Server, the fields are free. This means that anyone publishing there
485-
can set a new field. This results in a long set of possible fields, that are
486-
more or less frequent in the database.
487-
This method allows to retrieve all fields currently existing, with their
488-
occurrences and an example.
489-
490-
Parameters
491-
----------
492-
keyword : str, optional
493-
A keyword to filter the output for fields that have the keyword in their
494-
name. This is not case-sensitive.
495-
If you don't give a keyword, you will retrieve all existing fields.
496-
cache: bool, optional
497-
Whether the response should be cached.
498-
499-
Returns
500-
-------
501-
`~requests.models.Response`
502-
503-
"""
504-
return self._request(
505-
method="GET",
506-
url=self.URL,
507-
timeout=self.TIMEOUT,
508-
cache=cache,
509-
params={"get": "example", "fmt": "json"},
510-
)
511-
512483
def list_coordinate_systems(self):
513484
"""Return the list of coordinate systems currently available in the MOC Server.
514485

astroquery/mocserver/tests/test_mocserver.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44

55
import pytest
6+
import requests
67

78
from astropy import coordinates
89
from astropy.io.votable import parse_single_table
@@ -107,25 +108,24 @@ def _mock_list_fields(monkeypatch):
107108
# This response changes with time. To regenerate it, do:
108109
# >>> from astroquery.mocserver import MOCServer
109110
# >>> import json
110-
# >>> response = MOCServer.list_fields_async()
111+
# >>> response = MOCServer._request(method="GET", url=self.URL,
112+
# ... timeout=self.TIMEOUT, cache=cache,
113+
# ... params={"get": "example", "fmt": "json"}).json()[0]
111114
# >>> with open("list_fields.json", "w") as f:
112115
# ... json.dump(dict(response.json()[0]))
113116
class MockedListFields:
114117
def json(self):
115118
with open(Path(__file__).parent / "data" / "list_fields.json", "r") as f:
116119
return [json.load(f)]
117120

118-
monkeypatch.setattr(
119-
mocserver.MOCServerClass,
120-
"list_fields_async",
121-
lambda self, cache: MockedListFields(),
122-
)
121+
monkeypatch.setattr(requests.Session, 'send',
122+
lambda *args, **kwargs: MockedListFields())
123123

124124

125125
@pytest.mark.skipif(not HAS_MOCPY, reason="mocpy is required")
126126
@pytest.mark.usefixtures("_mock_list_fields")
127127
def test_list_fields():
128-
fields = MOCServer.list_fields("id")
128+
fields = MOCServer.list_fields("id", cache=False)
129129
assert "ID" in fields["field_name"]
130130

131131

0 commit comments

Comments
 (0)