Skip to content

Commit 07fb421

Browse files
authored
Merge pull request #2629 from bsipocz/MAINT_more_strict_flake8
MAINT: more strict flake8
2 parents e3f24d6 + 1f98ec9 commit 07fb421

File tree

111 files changed

+921
-944
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+921
-944
lines changed

astroquery/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def _get_bibtex():
2727

2828
with open(citation_file, 'r') as citation:
2929
refs = citation.read().split('@ARTICLE')[1:]
30-
if len(refs) == 0: return ''
30+
if len(refs) == 0:
31+
return ''
3132
bibtexreference = "@ARTICLE{0}".format(refs[0])
3233
return bibtexreference
3334

astroquery/alma/core.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ def _get_dataarchive_url(self):
533533

534534
def get_data_info(self, uids, *, expand_tarfiles=False,
535535
with_auxiliary=True, with_rawdata=True):
536-
537536
"""
538537
Return information about the data associated with ALMA uid(s)
539538
@@ -729,7 +728,7 @@ def download_files(self, files, *, savedir=None, cache=True,
729728
" next file".format(url=file_link))
730729
continue
731730
else:
732-
raise(ex)
731+
raise (ex)
733732

734733
try:
735734
filename = re.search("filename=(.*)",
@@ -781,7 +780,7 @@ def download_files(self, files, *, savedir=None, cache=True,
781780
" next file".format(url=file_link))
782781
continue
783782
else:
784-
raise(ex)
783+
raise (ex)
785784
elif ex.response.status_code == 403:
786785
log.error("Access denied to {url}".format(url=file_link))
787786
if 'dataPortal' in file_link and 'sso' not in file_link:

astroquery/alma/tests/test_alma.py

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ def test_gen_array_sql():
179179
# string arrays should be OR'd together
180180
common_select = "select * from ivoa.obscore WHERE "
181181
test_keywords = ["High-mass star formation", "Disks around high-mass stars"]
182-
assert _gen_sql({"spatial_resolution": "<0.1",
183-
"science_keyword": test_keywords}) == common_select + \
184-
"spatial_resolution<=0.1 AND (science_keyword='High-mass star formation' OR science_keyword='Disks around high-mass stars')"
182+
assert (_gen_sql({"spatial_resolution": "<0.1", "science_keyword": test_keywords})
183+
== common_select + ("spatial_resolution<=0.1 AND (science_keyword='High-mass star formation' "
184+
"OR science_keyword='Disks around high-mass stars')"))
185185

186186

187187
def test_gen_datetime_sql():
@@ -198,12 +198,9 @@ def test_gen_datetime_sql():
198198

199199
def test_gen_spec_res_sql():
200200
common_select = 'select * from ivoa.obscore WHERE '
201-
assert _gen_sql({'spectral_resolution': 70}) == common_select + \
202-
"em_resolution=20985472.06"
203-
assert _gen_sql({'spectral_resolution': '<70'}) == common_select + \
204-
"em_resolution>=20985472.06"
205-
assert _gen_sql({'spectral_resolution': '>70'}) == common_select + \
206-
"em_resolution<=20985472.06"
201+
assert _gen_sql({'spectral_resolution': 70}) == common_select + "em_resolution=20985472.06"
202+
assert _gen_sql({'spectral_resolution': '<70'}) == common_select + "em_resolution>=20985472.06"
203+
assert _gen_sql({'spectral_resolution': '>70'}) == common_select + "em_resolution<=20985472.06"
207204
assert _gen_sql({'spectral_resolution': '(70 .. 80)'}) == common_select + \
208205
"(23983396.64<=em_resolution AND em_resolution<=20985472.06)"
209206
assert _gen_sql({'spectral_resolution': '(70|80)'}) == common_select + \
@@ -403,9 +400,9 @@ def test_tap():
403400

404401
@pytest.mark.parametrize('data_archive_url',
405402
[
406-
('https://almascience.nrao.edu'),
407-
('https://almascience.eso.org'),
408-
('https://almascience.nao.ac.jp')
403+
('https://almascience.nrao.edu'),
404+
('https://almascience.eso.org'),
405+
('https://almascience.nao.ac.jp')
409406
])
410407
def test_tap_url(data_archive_url):
411408
_test_tap_url(data_archive_url)
@@ -420,9 +417,9 @@ def _test_tap_url(data_archive_url):
420417

421418
@pytest.mark.parametrize('data_archive_url',
422419
[
423-
('https://almascience.nrao.edu'),
424-
('https://almascience.eso.org'),
425-
('https://almascience.nao.ac.jp')
420+
('https://almascience.nrao.edu'),
421+
('https://almascience.eso.org'),
422+
('https://almascience.nao.ac.jp')
426423
])
427424
def test_sia_url(data_archive_url):
428425
_test_sia_url(data_archive_url)
@@ -437,9 +434,9 @@ def _test_sia_url(data_archive_url):
437434

438435
@pytest.mark.parametrize('data_archive_url',
439436
[
440-
('https://almascience.nrao.edu'),
441-
('https://almascience.eso.org'),
442-
('https://almascience.nao.ac.jp')
437+
('https://almascience.nrao.edu'),
438+
('https://almascience.eso.org'),
439+
('https://almascience.nao.ac.jp')
443440
])
444441
def test_datalink_url(data_archive_url):
445442
_test_datalink_url(data_archive_url)
@@ -467,13 +464,29 @@ def run_sync(self, uid):
467464
# This method will be used by the mock in test_get_data_info_expand_tarfiles to replace requests.get
468465
def _mocked_datalink_sync(*args, **kwargs):
469466
class MockResponse:
470-
adhoc_service_1_param1 = type('', (object, ), {'ID': 'standardID', 'value': 'ivo://ivoa.net/std/DataLink#links-1.0'})()
471-
adhoc_service_1_param2 = type('', (object, ), {'ID': 'accessURL', 'value': 'https://almascience.org/datalink/sync?ID=2017.1.01185.S_uid___A001_X12a3_Xe9_001_of_001.tar'})()
472-
adhoc_service_1 = type('', (object, ), {'ID': 'DataLink.2017.1.01185.S_uid___A001_X12a3_Xe9_001_of_001.tar', 'params': [adhoc_service_1_param1, adhoc_service_1_param2]})()
473-
474-
adhoc_service_2_param1 = type('', (object, ), {'ID': 'standardID', 'value': 'ivo://ivoa.net/std/DataLink#links-1.0'})()
475-
adhoc_service_2_param2 = type('', (object, ), {'ID': 'accessURL', 'value': 'https://almascience.org/datalink/sync?ID=2017.1.01185.S_uid___A001_X12a3_Xe9_auxiliary.tar'})()
476-
adhoc_service_2 = type('', (object, ), {'ID': 'DataLink.2017.1.01185.S_uid___A001_X12a3_Xe9_auxiliary.tar', 'params': [adhoc_service_1_param1, adhoc_service_1_param2]})()
467+
adhoc_service_1_param1 = type('', (object, ), {'ID': 'standardID',
468+
'value': 'ivo://ivoa.net/std/DataLink#links-1.0'})()
469+
adhoc_service_1_param2 = type(
470+
'', (object, ), {
471+
'ID': 'accessURL',
472+
'value': 'https://almascience.org/datalink/sync?ID=2017.1.01185.S_uid___A001_X12a3_Xe9_001_of_001.tar'}
473+
)()
474+
adhoc_service_1 = type(
475+
'', (object, ), {
476+
'ID': 'DataLink.2017.1.01185.S_uid___A001_X12a3_Xe9_001_of_001.tar', 'params': [
477+
adhoc_service_1_param1, adhoc_service_1_param2]})()
478+
479+
adhoc_service_2_param1 = type('', (object, ), {'ID': 'standardID',
480+
'value': 'ivo://ivoa.net/std/DataLink#links-1.0'})()
481+
adhoc_service_2_param2 = type(
482+
'', (object, ), {
483+
'ID': 'accessURL',
484+
'value': 'https://almascience.org/datalink/sync?ID=2017.1.01185.S_uid___A001_X12a3_Xe9_auxiliary.tar'}
485+
)()
486+
adhoc_service_2 = type(
487+
'', (object, ), {
488+
'ID': 'DataLink.2017.1.01185.S_uid___A001_X12a3_Xe9_auxiliary.tar', 'params': [
489+
adhoc_service_1_param1, adhoc_service_1_param2]})()
477490

478491
adhoc_services = {
479492
'DataLink.2017.1.01185.S_uid___A001_X12a3_Xe9_001_of_001.tar': adhoc_service_1,

astroquery/alma/tests/test_alma_remote.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ def test_big_download_regression(alma):
548548
@pytest.mark.remote_data
549549
def test_download_html_file(alma, tmp_path):
550550
alma.cache_location = tmp_path
551-
result = alma.download_files(['https://{}/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html'.format(download_hostname)])
551+
result = alma.download_files(
552+
['https://{}/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html'.format(download_hostname)])
552553
assert result
553554

554555

@@ -557,10 +558,13 @@ def test_verify_html_file(alma, caplog, tmp_path):
557558
alma.cache_location = tmp_path
558559

559560
# download the file
560-
result = alma.download_files(['https://{}/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html'.format(download_hostname)])
561+
result = alma.download_files(
562+
['https://{}/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html'.format(download_hostname)])
561563
assert 'member.uid___A001_X1284_X1353.qa2_report.html' in result[0]
562564

563-
result = alma.download_files(['https://{}/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html'.format(download_hostname)], verify_only=True)
565+
result = alma.download_files(
566+
['https://{}/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html'.format(download_hostname)],
567+
verify_only=True)
564568
assert 'member.uid___A001_X1284_X1353.qa2_report.html' in result[0]
565569
local_filepath = Path(result[0])
566570
expected_file_length = local_filepath.stat().st_size
@@ -573,16 +577,22 @@ def test_verify_html_file(alma, caplog, tmp_path):
573577
caplog.clear()
574578
new_file_length = expected_file_length + 10
575579
with pytest.warns(expected_warning=CorruptDataWarning,
576-
match=f"Found cached file {local_filepath} with size {new_file_length} > expected size {expected_file_length}. The download is likely corrupted."):
577-
result = alma.download_files(['https://{}/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html'.format(download_hostname)], verify_only=True)
580+
match=(f"Found cached file {local_filepath} with size {new_file_length} > expected size "
581+
f"{expected_file_length}. The download is likely corrupted.")):
582+
result = alma.download_files(
583+
['https://{}/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html'.format(download_hostname)],
584+
verify_only=True)
578585
assert 'member.uid___A001_X1284_X1353.qa2_report.html' in result[0]
579586

580587
# manipulate the file: make it small
581588
with open(local_filepath, 'wb') as fh:
582589
fh.write(b"Empty Text")
583590

584591
caplog.clear()
585-
result = alma.download_files(['https://{}/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html'.format(download_hostname)], verify_only=True)
592+
result = alma.download_files(
593+
['https://{}/dataPortal/member.uid___A001_X1284_X1353.qa2_report.html'.format(download_hostname)],
594+
verify_only=True)
586595
assert 'member.uid___A001_X1284_X1353.qa2_report.html' in result[0]
587596
existing_file_length = 10
588-
assert f"Found cached file {local_filepath} with size {existing_file_length} < expected size {expected_file_length}. The download should be continued." in caplog.text
597+
assert (f"Found cached file {local_filepath} with size {existing_file_length} < expected size "
598+
f"{expected_file_length}. The download should be continued.") in caplog.text

astroquery/alma/utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ def parse_frequency_support(frequency_support_str):
2929
supports = frequency_support_str.split('U')
3030

3131
freq_ranges = [(float(sup[0]),
32-
float(sup[1].split(',')[0].strip(string.ascii_letters))) *
33-
u.Unit(sup[1].split(',')[0].strip(string.punctuation +
34-
string.digits))
32+
float(sup[1].split(',')[0].strip(string.ascii_letters)))
33+
* u.Unit(sup[1].split(',')[0].strip(string.punctuation + string.digits))
3534
for i in supports for sup in [i.strip('[] ').split('..'), ]]
3635
return u.Quantity(freq_ranges)
3736

@@ -95,7 +94,7 @@ def approximate_primary_beam_sizes(frequency_support_str,
9594
as :math:`R = 1.22 \lambda/D`
9695
"""
9796
freq_ranges = parse_frequency_support(frequency_support_str)
98-
beam_sizes = [(first_null * fr.mean().to(u.m, u.spectral()) /
99-
(dish_diameter)).to(u.arcsec, u.dimensionless_angles())
97+
beam_sizes = [(first_null * fr.mean().to(u.m, u.spectral())
98+
/ (dish_diameter)).to(u.arcsec, u.dimensionless_angles())
10099
for fr in freq_ranges]
101100
return u.Quantity(beam_sizes)

astroquery/atomic/core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def __init__(self):
2929
super().__init__()
3030
self.__default_form_values = None
3131

32-
def query_object(self, *, wavelength_range=None, wavelength_type=None, wavelength_accuracy=None, element_spectrum=None,
32+
def query_object(self, *, wavelength_range=None, wavelength_type=None, wavelength_accuracy=None,
33+
element_spectrum=None,
3334
minimal_abundance=None, depl_factor=None, lower_level_energy_range=None,
3435
upper_level_energy_range=None, nmax=None, multiplet=None, transitions=None,
3536
show_fine_structure=None, show_auto_ionizing_transitions=None,
@@ -327,8 +328,8 @@ def _get_default_form_values(self, form):
327328
continue
328329
# check boxes: enabled boxes have the value "on" if not specified
329330
# otherwise. Found out by debugging, perhaps not documented.
330-
if (elem.get('type') == 'checkbox' and
331-
elem.get('checked') in ["", "checked"]):
331+
if (elem.get('type') == 'checkbox'
332+
and elem.get('checked') in ["", "checked"]):
332333
value = elem.get('value', 'on')
333334
# radio buttons and simple input fields
334335
if elem.get('type') == 'radio' and\

astroquery/atomic/tests/test_atomic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def test_transitions():
5959
assert isinstance(Transition.M1, MultiTransition)
6060
assert len(Transition.IC | Transition.M1) == 2
6161
# associativity
62-
assert ((Transition.IC | Transition.M1) | Transition.E1 ==
63-
Transition.IC | (Transition.M1 | Transition.E1))
62+
assert ((Transition.IC | Transition.M1) | Transition.E1
63+
== Transition.IC | (Transition.M1 | Transition.E1))
6464
# commutativity
6565
assert Transition.IC | Transition.M1 == Transition.M1 | Transition.IC
6666
assert str((Transition.IC | Transition.M1)) == 'IC,M1'

astroquery/atomic/tests/test_atomic_remote.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ def test_query_with_wavelength_params():
5252
cache=False)
5353
assert isinstance(result, Table)
5454
assert result.colnames == ['LAMBDA VAC ANG', 'SPECTRUM', 'TT',
55-
'CONFIGURATION', 'TERM', 'J J', 'A_ki',
56-
'LEVEL ENERGY CM 1']
57-
assert np.all(result['LAMBDA VAC ANG'] ==
58-
np.array([196.8874, 197.7992, 199.0122]))
55+
'CONFIGURATION', 'TERM', 'J J', 'A_ki',
56+
'LEVEL ENERGY CM 1']
57+
assert np.all(result['LAMBDA VAC ANG']
58+
== np.array([196.8874, 197.7992, 199.0122]))
5959
assert np.all(result['SPECTRUM'] == np.array(['C IV', 'C IV', 'C IV']))
6060
assert np.all(result['TT'] == np.array(['E1', 'E1', 'E1']))
6161
assert np.all(result['TERM'] == np.array(['2S-2Po', '2S-2Po', '2S-2Po']))
6262
assert np.all(result['J J'] == np.array(['1/2-*', '1/2-*', '1/2-*']))
63-
assert np.all(result['LEVEL ENERGY CM 1'] ==
64-
np.array(['0.00 - 507904.40', '0.00 - 505563.30',
65-
'0.00 - 502481.80']))
63+
assert np.all(result['LEVEL ENERGY CM 1']
64+
== np.array(['0.00 - 507904.40', '0.00 - 505563.30',
65+
'0.00 - 502481.80']))
6666

6767

6868
def test_empty_result_set():
@@ -79,5 +79,5 @@ def test_lower_upper_ranges():
7979
element_spectrum='Ne III', cache=False)
8080
assert isinstance(result, Table)
8181

82-
assert np.all(result['LAMBDA VAC ANG'] ==
83-
np.array([1814.73, 3968.91, 4013.14]))
82+
assert np.all(result['LAMBDA VAC ANG']
83+
== np.array([1814.73, 3968.91, 4013.14]))

astroquery/atomic/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ def is_valid_transitions_param(transitions):
1111
is_custom_choice = isinstance(transitions, MultiTransition) and\
1212
all(t not in simple_transitions for t in transitions)
1313

14-
return (transitions is None or transitions in simple_transitions or
15-
is_custom_choice)
14+
return (transitions is None or transitions in simple_transitions
15+
or is_custom_choice)

astroquery/besancon/core.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ def _parse_args(self, glon, glat, email, smallfield=True, extinction=0.7,
223223
"""
224224
if email is None and hasattr(self, 'email'):
225225
email = self.email
226-
if (email is None or not isinstance(email, str) or
227-
not commons.validate_email(email)):
226+
if (email is None or not isinstance(email, str)
227+
or not commons.validate_email(email)):
228228
raise ValueError("Must specify a valid e-mail address.")
229229

230230
# create a new keyword dict based on inputs + defaults
@@ -274,8 +274,8 @@ def _parse_args(self, glon, glat, email, smallfield=True, extinction=0.7,
274274
# convert all array elements to arrays
275275
for dummy in range(2): # deal with nested lists
276276
for k, v in list(request_data.items()):
277-
if (isinstance(v, list) or
278-
(isinstance(v, tuple) and len(v) > 1)):
277+
if (isinstance(v, list)
278+
or (isinstance(v, tuple) and len(v) > 1)):
279279
if k in request_data:
280280
del request_data[k]
281281
for index, val in enumerate(v):
@@ -286,8 +286,7 @@ def _parse_args(self, glon, glat, email, smallfield=True, extinction=0.7,
286286

287287
return request_data
288288

289-
@prepend_docstr_nosections("\n" + _parse_args.__doc__ +
290-
_parse_result.__doc__)
289+
@prepend_docstr_nosections("\n" + _parse_args.__doc__ + _parse_result.__doc__)
291290
def query_async(self, *args, **kwargs):
292291
"""
293292
Returns

0 commit comments

Comments
 (0)