Skip to content

Commit

Permalink
Merge pull request #7417 from nabobalis/pytest
Browse files Browse the repository at this point in the history
Handle pytest 8.0.0
  • Loading branch information
Cadair committed Jan 31, 2024
2 parents a9821d2 + df5d1c7 commit e4b9c43
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ jobs:
with:
activate-environment: sunpy-test
environment-file: sunpy-dev-env.yml
python-version: 3.10
python-version: "3.11"
- name: Install sunpy
shell: bash -el {0}
run: |
Expand Down
11 changes: 5 additions & 6 deletions sunpy/io/special/asdf/tests/test_coordinate_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def assert_round_trip_frame(old):


@pytest.fixture(params=sunpy_frames)
@asdf_entry_points
def coordframe_scalar(request):
frame = request.param

Expand All @@ -39,7 +38,6 @@ def coordframe_scalar(request):


@pytest.fixture(params=sunpy_frames)
@asdf_entry_points
def coordframe_array(request):
frame = request.param

Expand All @@ -51,12 +49,13 @@ def coordframe_array(request):
return frame(*data, obstime='2018-01-01T00:00:00')


# Ignore warnings thrown when trying to load the ASDF in a different astropy
# version to that with which it was created.
# Ignore warnings thrown when trying to load the ASDF in a different
# astropy version to that with which it was created.
@pytest.mark.filterwarnings('ignore:.*was created with extension.*')
@asdf_entry_points
def test_hgc_100():
# Test that HeliographicCarrington is populated with Earth as the observer when loading a
# older schema (1.0.0)
# Test that HeliographicCarrington is populated with Earth as the
# observer when loading a older schema (1.0.0)
test_file = os.path.join(os.path.dirname(__file__), "hgc_100.asdf")
with asdf.open(test_file) as input_asdf:
hgc = input_asdf['hgc']
Expand Down
19 changes: 11 additions & 8 deletions sunpy/map/tests/test_map_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
import sunpy.map
from sunpy.data.test import get_dummy_map_from_header, get_test_data_filenames, get_test_filepath, rootdir
from sunpy.tests.helpers import figure_test, skip_glymur
from sunpy.util.exceptions import NoMapsInFileError, SunpyMetadataWarning, SunpyUserWarning
from sunpy.util.exceptions import (
NoMapsInFileError,
SunpyDeprecationWarning,
SunpyMetadataWarning,
SunpyUserWarning,
)

a_list_of_many = [f for f in get_test_data_filenames() if 'efz' in f.name]

Expand Down Expand Up @@ -154,7 +159,7 @@ def test_patterns(eit_fits_directory):
header = {'cdelt1': 10, 'cdelt2': 10,
'telescop': 'sunpy',
'cunit1': 'arcsec', 'cunit2': 'arcsec'}
with pytest.warns(SunpyMetadataWarning, match='Missing CTYPE1 from metadata, assuming CTYPE1 is HPLN-TAN'):
with pytest.warns(SunpyMetadataWarning, match='Missing CTYPE'):
pair_map = sunpy.map.Map(data, header)
assert isinstance(pair_map, sunpy.map.GenericMap)

Expand All @@ -165,7 +170,7 @@ def test_patterns(eit_fits_directory):
'detector': 1,
'instrume': 50,
'cunit1': 'arcsec', 'cunit2': 'arcsec'}
with pytest.warns(SunpyMetadataWarning, match='Missing CTYPE1 from metadata, assuming CTYPE1 is HPLN-TAN'):
with pytest.warns(SunpyMetadataWarning, match='Missing CTYPE'):
pair_map = sunpy.map.Map(data, header)
assert isinstance(pair_map, sunpy.map.GenericMap)

Expand Down Expand Up @@ -266,10 +271,7 @@ def test_map_list_urls_cache():
])
def test_sources(file, mapcls):
p = pathlib.Path(get_test_filepath(file))
if p.suffix == '.header':
m = get_dummy_map_from_header(p)
else:
m = sunpy.map.Map(p)
m = get_dummy_map_from_header(p) if p.suffix == '.header' else sunpy.map.Map(p)
assert isinstance(m, mapcls)


Expand All @@ -283,7 +285,8 @@ def test_no_2d_hdus(tmpdir):
sunpy.map.Map(tmp_fpath)

with pytest.warns(SunpyUserWarning, match='One of the arguments failed to parse'):
sunpy.map.Map([tmp_fpath, AIA_171_IMAGE], silence_errors=True)
with pytest.warns(SunpyDeprecationWarning, match='"silence_errors" was deprecated in version 5.1 and will be removed in a future version'):
sunpy.map.Map([tmp_fpath, AIA_171_IMAGE], silence_errors=True)


@skip_glymur
Expand Down
21 changes: 12 additions & 9 deletions sunpy/map/tests/test_mapbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
def test_fits_data_comparison(aia171_test_map):
"""Make sure the data is the same when read with astropy.io.fits and sunpy"""
with pytest.warns(VerifyWarning, match="Invalid 'BLANK' keyword in header."):
data = fits.open(get_test_filepath('aia_171_level1.fits'))[0].data
np.testing.assert_allclose(aia171_test_map.data, data)
hdulist = fits.open(get_test_filepath('aia_171_level1.fits'))
np.testing.assert_allclose(aia171_test_map.data, hdulist[0].data)
hdulist.close()


def test_header_fits_io():
Expand Down Expand Up @@ -1219,8 +1220,9 @@ def test_more_than_two_dimensions():
hdr['TELESCOP'] = 'XXX'
hdr['cunit1'] = 'arcsec'
hdr['cunit2'] = 'arcsec'
with pytest.warns(SunpyUserWarning, match='This file contains more than 2 dimensions.'):
bad_map = sunpy.map.Map(bad_data, hdr)
with pytest.warns(SunpyMetadataWarning, match='Missing CTYPE'):
with pytest.warns(SunpyUserWarning, match='This file contains more than 2 dimensions.'):
bad_map = sunpy.map.Map(bad_data, hdr)
# Test fails if map.ndim > 2 and if the dimensions of the array are wrong.
assert bad_map.ndim == 2
assert_quantity_allclose(bad_map.dimensions, (5, 3) * u.pix)
Expand All @@ -1229,11 +1231,12 @@ def test_more_than_two_dimensions():
def test_missing_metadata_warnings():
# Checks that warnings for missing metadata are only raised once
with pytest.warns(Warning) as record:
header = {}
header['cunit1'] = 'arcsec'
header['cunit2'] = 'arcsec'
header['ctype1'] = 'HPLN-TAN'
header['ctype2'] = 'HPLT-TAN'
header = {
'cunit1': 'arcsec',
'cunit2': 'arcsec',
'ctype1': 'HPLN-TAN',
'ctype2': 'HPLT-TAN',
}
array_map = sunpy.map.Map(np.random.rand(20, 15), header)
array_map.peek()
# There should be 2 warnings for missing metadata (obstime and observer location)
Expand Down
6 changes: 4 additions & 2 deletions sunpy/map/tests/test_mapbase_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import astropy.wcs
from astropy.io import fits
from astropy.io.fits.verify import VerifyWarning
from astropy.wcs import FITSFixedWarning

import sunpy.map
from sunpy.data.test import get_test_filepath
Expand All @@ -21,7 +22,7 @@ def aia171_test_dask_map(aia171_test_map):
)


def test_dask_array(aia171_test_dask_map):
def test_dask_array_repr(aia171_test_dask_map):
# Check that _repr_html_ functions for a dask array
html_dask_repr = aia171_test_dask_map._repr_html_(compute_dask=False)
html_computed_repr = aia171_test_dask_map._repr_html_(compute_dask=True)
Expand All @@ -31,7 +32,8 @@ def test_dask_array(aia171_test_dask_map):
# This is needed for the reproject_to function
with pytest.warns(VerifyWarning, match="Invalid 'BLANK' keyword in header."):
with fits.open(get_test_filepath('aia_171_level1.fits')) as hdu:
aia_wcs = astropy.wcs.WCS(header=hdu[0].header)
with pytest.warns(FITSFixedWarning, match="'datfix' made the change"):
aia_wcs = astropy.wcs.WCS(header=hdu[0].header)


@pytest.mark.parametrize(("func", "args"), [
Expand Down
22 changes: 5 additions & 17 deletions sunpy/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
import platform
import warnings
from pathlib import Path
from platform import python_version
from functools import wraps
from importlib.metadata import entry_points

import matplotlib as mpl
import matplotlib.pyplot as plt
import pytest
from packaging.version import Version

import astropy
from astropy.wcs.wcs import FITSFixedWarning
Expand Down Expand Up @@ -46,21 +44,11 @@
skip_windows = pytest.mark.skipif(platform.system() == "Windows", reason="Windows.")
skip_glymur = pytest.mark.skipif(SKIP_GLYMUR, reason="Glymur can not be imported.")
skip_ana = pytest.mark.skipif(SKIP_ANA, reason="ANA is not available.")
if Version(python_version()) >= Version("3.10.0"):
asdf_entry_points = pytest.mark.skipif(
not entry_points().select(group="asdf.resource_mappings", name="sunpy"),
reason="No SunPy ASDF entry points.",
)
else:
asdf_entry_points = pytest.mark.skipif(
not any(
[
enter_point.name == "sunpy"
for enter_point in entry_points()["asdf.resource_mappings"]
]
),
reason="No SunPy ASDF entry points.",
)
asdf_entry_points = pytest.mark.skipif(
not entry_points().select(group="asdf.resource_mappings", name="sunpy"),
reason="No SunPy ASDF entry points.",
)



@pytest.fixture
Expand Down
6 changes: 3 additions & 3 deletions sunpy/timeseries/sources/tests/test_eve.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@


def test_eve():
# Test an EVE TimeSeries
with pytest.warns(SunpyUserWarning, match='Unknown units for x_cool proxy'):
ts_eve = sunpy.timeseries.TimeSeries(eve_filepath, source='EVE')
with pytest.warns(SunpyUserWarning, match='Unknown units for oldXRSB proxy'):
with pytest.warns(SunpyUserWarning, match='Unknown units for x_cool'):
ts_eve = sunpy.timeseries.TimeSeries(eve_filepath, source='EVE')
assert isinstance(ts_eve, sunpy.timeseries.sources.eve.EVESpWxTimeSeries)


Expand Down
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ description =
setenv =
MPLBACKEND = agg
SUNPY_SAMPLEDIR = {env:SUNPY_SAMPLEDIR:{toxinidir}/.tox/sample_data/}
PYTEST_COMMAND = pytest -vvv -r a --pyargs sunpy --cov-report=xml --cov=sunpy --cov-config={toxinidir}/setup.cfg {toxinidir}/docs
PYTEST_COMMAND = pytest -vvv -r fEs --pyargs sunpy --cov-report=xml --cov=sunpy --cov-config={toxinidir}/setup.cfg {toxinidir}/docs
devdeps,build_docs,online: HOME = {envtmpdir}
PARFIVE_HIDE_PROGRESS = True
NO_VERIFY_HELIO_SSL = 1
Expand All @@ -35,11 +35,13 @@ deps =
devdeps: git+https://github.com/astropy/asdf-astropy
devdeps: git+https://github.com/astropy/reproject
devdeps: git+https://github.com/Cadair/parfive
devdeps: git+https://github.com/sunpy/mpl-animators
devdeps: git+https://github.com/MAVENSDC/cdflib
devdeps: git+https://github.com/sunpy/mpl-animators
devdeps: matplotlib>=0.0.dev0
devdeps: numpy>=0.0.dev0
devdeps: pandas>=0.0.dev0
devdeps: pluggy>=0.0.dev0
devdeps: pytest>=0.0.dev0
# Oldest deps we pin against
oldestdeps: asdf-astropy<0.1.2
oldestdeps: asdf<2.9.0
Expand Down

0 comments on commit e4b9c43

Please sign in to comment.