Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GOES tests for new files #7226

Merged
merged 4 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ filterwarnings =
ignore:`product` is deprecated as of NumPy 1.25.0:DeprecationWarning
# sunpy IO skip here to prevent pytest breaking items downstream
ignore:.*module is deprecated, as it was designed for internal use
# This is raised when the VSO redirects and we do not want this to stop the CI
ignore::sunpy.util.exceptions.SunpyConnectionWarning

[pycodestyle]
max_line_length = 110
Expand Down
4 changes: 2 additions & 2 deletions sunpy/net/dataretriever/sources/tests/test_goes_ud.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def LCClient():
'https://umbra.nascom.nasa.gov/goes/fits/1995/go07950605.fits'),
(Time('2008/06/02 12:00', '2008/06/04'),
'https://www.ncei.noaa.gov/data/goes-space-environment-monitor/access/science/xrs/goes10/gxrs-l2-irrad_science/2008/06/sci_gxrs-l2-irrad_g10_d20080602_v0-0-0.nc',
'https://www.ncei.noaa.gov/data/goes-space-environment-monitor/access/science/xrs/goes10/gxrs-l2-irrad_science/2008/06/sci_gxrs-l2-irrad_g10_d20080604_v0-0-0.nc'),
'https://www.ncei.noaa.gov/data/goes-space-environment-monitor/access/science/xrs/goes10/xrsf-l2-avg1m_science/2008/06/sci_xrsf-l2-avg1m_g10_d20080604_v1-0-0.nc'),
(Time('2020/08/02', '2020/08/04'),
'https://data.ngdc.noaa.gov/platforms/solar-space-observing-satellites/goes/'
'goes16/l2/data/xrsf-l2-flx1s_science/2020/08/sci_xrsf-l2-flx1s_g16_d20200802_v2-2-0.nc',
Expand Down Expand Up @@ -62,7 +62,7 @@ def test_get_overlap_urls(LCClient, timerange, url_start, url_end):
def test_get_overlap_providers(LCClient, timerange, url_start, url_end):
qresponse = LCClient.search(timerange)
urls = [i['url'] for i in qresponse]
assert len(urls) == 8
assert len(urls) == 12
assert urls[0] == url_start
assert urls[-1] == url_end

Expand Down
2 changes: 0 additions & 2 deletions sunpy/net/helio/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,7 @@ def link_test(link):
--------
>>> from sunpy.net.helio import parser
>>> result = parser.link_test('http://msslkz.mssl.ucl.ac.uk/helio-hec/HelioService') # doctest: +SKIP

>>> print(parser.link_test('http://rrnx.invalid_url5523.com')) # doctest: +SKIP
None
"""
try:
with closing(urlopen(link, timeout=LINK_TIMEOUT)) as fd:
Expand Down
4 changes: 2 additions & 2 deletions sunpy/net/vso/tests/test_vso.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
from sunpy.tests.mocks import MockObject
from sunpy.time import parse_time
from sunpy.util.exceptions import SunpyUserWarning
from sunpy.util.exceptions import SunpyConnectionWarning, SunpyUserWarning


class MockQRRecord:
Expand Down Expand Up @@ -318,7 +318,7 @@ def test_fallback_if_cgi_offline(mocker):
# Now patch out that URL so we can cause it to return an error
mocker.patch('sunpy.net.vso.vso.urlopen', side_effect=partial(fail_to_open_nso_cgi, cgi_url))

with pytest.warns(SunpyUserWarning,
with pytest.warns(SunpyConnectionWarning,
match=f"Connection to {cgi_url} failed with error .* Retrying with different url and port"):
mirror = get_online_vso_url()
assert mirror["url"] != "http://docs.virtualsolar.org/WSDL/VSOi_rpc_literal.wsdl"
Expand Down
8 changes: 4 additions & 4 deletions sunpy/net/vso/vso.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from sunpy.net.base_client import BaseClient, QueryResponseRow
from sunpy.net.vso import attrs
from sunpy.net.vso.attrs import _walker as walker
from sunpy.util.exceptions import warn_user
from sunpy.util.exceptions import warn_connection, warn_user
from sunpy.util.net import parse_header, slugify
from sunpy.util.parfive_helpers import Downloader, Results
from .exceptions import (
Expand Down Expand Up @@ -59,7 +59,7 @@ def check_connection(url):
try:
return urlopen(url, timeout=15).getcode() == 200
except (OSError, HTTPError, URLError) as e:
warn_user(f"Connection to {url} failed with error {e}. Retrying with different url and port.")
warn_connection(f"Connection to {url} failed with error {e}. Retrying with different url and port.")
return False


Expand All @@ -74,10 +74,10 @@ def check_cgi_connection(url):
except HTTPError as e:
if e.code == 411:
return True
warn_user(f"Connection to {url} failed with error {e}. Retrying with different url and port.")
warn_connection(f"Connection to {url} failed with error {e}. Retrying with different url and port.")
return False
except (OSError, URLError) as e:
warn_user(f"Connection to {url} failed with error {e}. Retrying with different url and port.")
warn_connection(f"Connection to {url} failed with error {e}. Retrying with different url and port.")
return False


Expand Down
29 changes: 26 additions & 3 deletions sunpy/util/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

__all__ = ["NoMapsInFileError",
"SunpyWarning", "SunpyUserWarning", "SunpyDeprecationWarning",
"SunpyPendingDeprecationWarning", "SunpyMetadataWarning",
"warn_user", "warn_deprecated", "warn_metadata"]
"SunpyPendingDeprecationWarning", "SunpyMetadataWarning", "SunpyConnectionWarning",
"warn_user", "warn_deprecated", "warn_metadata", "warn_connection"]


class NoMapsInFileError(Exception):
Expand Down Expand Up @@ -44,7 +44,6 @@
stacklevel=3 to show the user where the issue occurred in their code.
"""


class SunpyDeprecationWarning(FutureWarning, SunpyWarning):
"""
A warning class to indicate a deprecated feature.
Expand All @@ -57,6 +56,16 @@
"""


class SunpyConnectionWarning(SunpyUserWarning):

Check warning on line 59 in sunpy/util/exceptions.py

View check run for this annotation

Codecov / codecov/patch

sunpy/util/exceptions.py#L59

Added line #L59 was not covered by tests
"""
A warning class to indicate a connection warning.

This warning should be issued when a recoverable error occurs during a connection to a remote server, such as falling back to a mirror etc.

This will not fail the CI (via a pytest ignore) as it is not a critical warning.
nabobalis marked this conversation as resolved.
Show resolved Hide resolved
"""


def warn_metadata(msg, stacklevel=1):
"""
Raise a `SunpyMetadataWarning`.
Expand Down Expand Up @@ -88,6 +97,20 @@
"""
warnings.warn(msg, SunpyUserWarning, stacklevel + 1)

def warn_connection(msg, stacklevel=1):

Check warning on line 100 in sunpy/util/exceptions.py

View check run for this annotation

Codecov / codecov/patch

sunpy/util/exceptions.py#L100

Added line #L100 was not covered by tests
"""
Raise a `SunpyConnectionWarning`.

Parameters
----------
msg : str
Warning message.
stacklevel : int
This is interpreted relative to the call to this function,
e.g. ``stacklevel=1`` (the default) sets the stack level in the
code that calls this function.
"""
warnings.warn(msg, SunpyConnectionWarning, stacklevel + 1)

def warn_deprecated(msg, stacklevel=1):
"""
Expand Down