Skip to content

Commit 6f20415

Browse files
committed
de-flake
1 parent 1a11d8f commit 6f20415

File tree

2 files changed

+32
-70
lines changed

2 files changed

+32
-70
lines changed

astroquery/noirlab/core.py

+5-34
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
44
This does DB access through web-services.
55
"""
6-
import json
76
import astropy.io.fits as pyfits
87
import astropy.table
98
from ..query import BaseQuery
109
from ..utils import async_to_sync
1110
from ..utils.class_or_instance import class_or_instance
1211
from . import conf
13-
#!import requests
1412

1513

1614
__all__ = ['Noirlab', 'NoirlabClass'] # specifies what to import
@@ -32,7 +30,7 @@ def __init__(self, which='file'):
3230
"""
3331
self._api_version = None
3432
self._adsurl = f'{self.NAT_URL}/api/adv_search'
35-
33+
3634
if which == 'hdu':
3735
self.siaurl = f'{self.NAT_URL}/api/sia/vohdu'
3836
self._adss_url = f'{self._adsurl}/hasearch'
@@ -79,7 +77,7 @@ def service_metadata(self, cache=True):
7977
url = f'{self.siaurl}?FORMAT=METADATA&format=json'
8078
response = self._request('GET', url, timeout=self.TIMEOUT, cache=cache)
8179
return response.json()[0]
82-
80+
8381
@class_or_instance
8482
def query_region(self, coordinate, radius=0.1, cache=True):
8583
"""Query for NOIRLab observations by region of the sky.
@@ -111,7 +109,6 @@ def query_region(self, coordinate, radius=0.1, cache=True):
111109
response.raise_for_status()
112110
return astropy.table.Table(data=response.json())
113111

114-
115112
def core_fields(self, cache=True):
116113
"""List the available CORE fields. CORE fields are faster to search
117114
than AUX fields.."""
@@ -121,7 +118,6 @@ def core_fields(self, cache=True):
121118
response.raise_for_status()
122119
return response.json()
123120

124-
125121
def aux_fields(self, instrument, proctype, cache=True):
126122
"""List the available AUX fields. AUX fields are ANY fields in the
127123
Archive FITS files that are not core DB fields. These are generally
@@ -145,19 +141,6 @@ def categoricals(self, cache=True):
145141
response.raise_for_status()
146142
return response.json()
147143

148-
#! @class_or_instance
149-
#! def _query_ads(self, jdata, limit=1000):
150-
#! print(f'DBG-0: ADS jdata={jdata}')
151-
#! adsurl = f'{self.adsurl}/?limit={limit}'
152-
#! print(f'DBG-0: adsurl = {adsurl}')
153-
#! # Following fails
154-
#! # #! response = self._request('POST',adsurl, data=json.dumps(jdata))
155-
#! response = requests.post(adsurl, json=jdata)
156-
#! print(f'DBG-0: ADS response={response}')
157-
#! print(f'DBG-0: ADS response.content={response.content}')
158-
#! print(f'DBG-0: ADS response.json()={response.json()}')
159-
#! return astropy.table.Table(data=response.json())
160-
161144
@class_or_instance
162145
def query_metadata(self, qspec, limit=1000, cache=True):
163146
self._validate_version()
@@ -168,22 +151,9 @@ def query_metadata(self, qspec, limit=1000, cache=True):
168151
else:
169152
jdata = qspec
170153

171-
print(f'DBG-0: query_metadata.url = {url}')
172-
# headers = {'accept': 'application/json'}
173-
# headers = {'Content-Type': 'application/json'}
174-
175-
# Following fails:
176-
response = self._request('POST', url, json=jdata, timeout=self.TIMEOUT,)
177-
178-
#! response = requests.post(url,
179-
#! timeout=self.TIMEOUT,
180-
#! json=jdata)
154+
response = self._request('POST', url, json=jdata, timeout=self.TIMEOUT)
181155
response.raise_for_status()
182-
# #!print(f'DBG-0: ADS response={response}')
183-
# #!print(f'DBG-0: ADS response.content={response.content}')
184-
# #!print(f'DBG-0: ADS response.json()={response.json()}')
185156
return astropy.table.Table(rows=response.json())
186-
#return response.json() #@@@ Should return table
187157

188158
def retrieve(self, fileid, cache=True):
189159
url = f'{self.NAT_URL}/api/retrieve/{fileid}/'
@@ -203,5 +173,6 @@ def get_token(self, email, password, cache=True):
203173
timeout=self.TIMEOUT)
204174
response.raise_for_status()
205175
return response.json()
206-
176+
177+
207178
Noirlab = NoirlabClass()

astroquery/noirlab/tests/test_noirlab_remote.py

+27-36
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
from astropy import units as u
66
from astropy.coordinates import SkyCoord
77
from astropy.tests.helper import remote_data
8-
import astropy.io.fits as pyfits
98
# Local packages
109
from .. import Noirlab
1110
from . import expected as exp
12-
# #!import pytest
1311

1412
# performs similar tests as test_module.py, but performs
1513
# the actual HTTP request rather than monkeypatching them.
@@ -20,9 +18,9 @@
2018
@remote_data
2119
class TestNoirlabClass(object):
2220

23-
###############################################################
24-
### (2) SIA; /api/sia/
25-
###
21+
# ###############################################################
22+
# ### (2) SIA; /api/sia/
23+
# ###
2624
# voimg, vohdu
2725

2826
def test_service_metadata(self):
@@ -32,7 +30,7 @@ def test_service_metadata(self):
3230
print(f'DBG: test_service_metadata={actual}')
3331
expected = exp.service_metadata
3432
assert actual == expected
35-
33+
3634
def test_query_region_0(self):
3735
"""Search FILES using default type (which) selector"""
3836

@@ -64,19 +62,19 @@ def test_query_region_2(self):
6462
expected = exp.query_region_2
6563
assert expected.issubset(actual)
6664

67-
###############################################################
68-
### (7) Advanced Search; /api/adv_search/
69-
###
65+
# ###############################################################
66+
# ### (7) Advanced Search; /api/adv_search/
67+
# ###
7068
#
7169
# (2) aux_{file,hdu}_fields/<instrument>/<proctype>
7270
# (2) core_{file,hdu}_fields/
7371
# [(2) {f,h}adoc JUST LINK to these]
7472
# (2) {f,h}asearch
7573
# cat_list
7674

77-
##
78-
## File (default type)
79-
##
75+
# ##
76+
# ## File (default type)
77+
# ##
8078

8179
def test_aux_file_fields(self):
8280
"""List the available AUX FILE fields."""
@@ -89,36 +87,35 @@ def test_aux_file_fields(self):
8987
def test_core_file_fields(self):
9088
"""List the available CORE FILE fields."""
9189
r = Noirlab().core_fields()
92-
actual = r # set(list(r['md5sum']))
90+
actual = r
9391
print(f'DBG: test_core_file_fields={actual}')
9492
expected = exp.core_file_fields
9593
assert actual == expected
9694

9795
def test_query_file_metadata(self):
9896
"""Search FILE metadata."""
9997
qspec = {
100-
"outfields" : [
98+
"outfields": [
10199
"md5sum",
102100
"archive_filename",
103101
"original_filename",
104102
"instrument",
105103
"proc_type"
106104
],
107-
"search" : [
105+
"search": [
108106
['original_filename', 'c4d_', 'contains']
109107
]
110108
}
111109

112110
r = Noirlab().query_metadata(qspec, limit=3)
113-
actual = r # set(list(r['md5sum']))
111+
actual = r
114112
print(f'DBG: test_query_file_metadata={actual.pformat_all()}')
115113
expected = exp.query_file_metadata
116114
assert actual.pformat_all() == expected
117115

118-
119-
##
120-
## HDU
121-
##
116+
# ##
117+
# ## HDU
118+
# ##
122119

123120
def test_aux_hdu_fields(self):
124121
"""List the available AUX HDU fields."""
@@ -131,50 +128,48 @@ def test_aux_hdu_fields(self):
131128
def test_core_hdu_fields(self):
132129
"""List the available CORE HDU fields."""
133130
r = Noirlab(which='hdu').core_fields()
134-
actual = r # set(list(r['md5sum']))
131+
actual = r
135132
print(f'DBG: test_core_hdu_fields={actual}')
136133
expected = exp.core_hdu_fields
137134
assert actual == expected
138135

139136
def test_query_hdu_metadata(self):
140137
"""Search HDU metadata."""
141138
qspec = {
142-
"outfields" : [
139+
"outfields": [
143140
"fitsfile__archive_filename",
144141
"fitsfile__caldat",
145142
"fitsfile__instrument",
146143
"fitsfile__proc_type",
147144
"AIRMASS" # AUX field. Slows search
148145
],
149-
"search" : [
146+
"search": [
150147
["fitsfile__caldat", "2017-08-14", "2017-08-16"],
151148
["fitsfile__instrument", "decam"],
152149
["fitsfile__proc_type", "raw"]
153150
]
154151
}
155152

156153
r = Noirlab(which='hdu').query_metadata(qspec, limit=3)
157-
actual = r # set(list(r['md5sum']))
154+
actual = r
158155
print(f'DBG: test_query_hdu_metadata={actual.pformat_all()}')
159156
expected = exp.query_hdu_metadata
160157
assert actual.pformat_all() == expected
161158

162-
##
163-
## Agnostic
164-
##
159+
# ##
160+
# ## Agnostic
161+
# ##
165162

166163
def test_categoricals(self):
167164
"""List categories."""
168165
r = Noirlab().categoricals()
169-
actual = r # set(list(r['md5sum']))
166+
actual = r
170167
print(f'DBG: test_categoricals={actual}')
171168
expected = exp.categoricals
172169
assert actual == expected
173170

174-
175-
176-
###############################################################
177-
### (3) Other
171+
# ##############################################################
172+
# ### (3) Other
178173
# get_token
179174
# retrieve/<md5>
180175
# version
@@ -186,7 +181,6 @@ def test_retrieve(self):
186181
expected = exp.retrieve
187182
assert actual == expected
188183

189-
190184
def test_version(self):
191185
r = Noirlab().version()
192186
assert r < 3.0
@@ -197,6 +191,3 @@ def test_get_token(self):
197191
'No active account found with the given credentials'}
198192
print(f'DBG: test_get_token={actual}')
199193
assert actual == expected
200-
201-
202-

0 commit comments

Comments
 (0)