Skip to content

Commit

Permalink
Only monkeypatch for affected astropy version
Browse files Browse the repository at this point in the history
  • Loading branch information
pllim committed May 5, 2021
1 parent 8d61379 commit 3b1d8ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion astroquery/utils/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ def FK4CoordGenerator(*args, **kwargs):
'suppress_vo_warnings',
'validate_email',
'ASTROPY_LT_4_0',
'ASTROPY_LT_4_1']
'ASTROPY_LT_4_1',
'ASTROPY_LT_4_3']

ASTROPY_LT_4_0 = not minversion('astropy', '4.0')
ASTROPY_LT_4_1 = not minversion('astropy', '4.1')
ASTROPY_LT_4_3 = not minversion('astropy', '4.3')


def send_request(url, data, timeout, request_type='POST', headers={},
Expand Down
12 changes: 9 additions & 3 deletions astroquery/utils/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,11 @@ def patch_getreadablefileobj(request):
# Monkeypatch hack: ALWAYS treat as a URL
_is_url = aud._is_url
aud._is_url = lambda x: True
_try_url_open = aud._try_url_open
aud._try_url_open = lambda x, **kwargs: MockRemote(x, **kwargs)

if not commons.ASTROPY_LT_4_3:
_try_url_open = aud._try_url_open
aud._try_url_open = lambda x, **kwargs: MockRemote(x, **kwargs)

_urlopen = urllib.request.urlopen
_urlopener = urllib.request.build_opener
_urlrequest = urllib.request.Request
Expand Down Expand Up @@ -459,7 +462,10 @@ def monkey_urlrequest(x, *args, **kwargs):

def closing():
aud._is_url = _is_url
aud._try_url_open = _try_url_open

if not commons.ASTROPY_LT_4_3:
aud._try_url_open = _try_url_open

urllib.request.urlopen = _urlopen
aud.urllib.request.urlopen = _urlopen
urllib.request.build_opener = _urlopener
Expand Down

0 comments on commit 3b1d8ec

Please sign in to comment.