Skip to content

Commit

Permalink
update warning filters in tests for pytest 8
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Jan 17, 2024
1 parent ee53eab commit 0a21094
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions tests/test_fits.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import warnings

import pytest
from astropy.io import fits
Expand Down Expand Up @@ -592,15 +593,21 @@ def test_ndarray_validation(tmp_path):

# But raise an error when casting is disabled
with pytest.raises(ValidationError, match="Array datatype 'float64' is not compatible with 'float32'"):
# also warn due to the cast_fits_array deprecation
with pytest.warns(DeprecationWarning, match="cast_fits_array"):
with FitsModel(
file_path,
strict_validation=True,
cast_fits_arrays=False,
validate_arrays=True,
) as model:
model.validate()
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
category=UserWarning,
message="cast_arrays is deprecated and will be removed"
)
# also warn due to the cast_fits_array deprecation
with pytest.warns(DeprecationWarning, match="cast_fits_array"):
with FitsModel(
file_path,
strict_validation=True,
cast_fits_arrays=False,
validate_arrays=True,
) as model:
model.validate()

# Wrong dimensions
hdu = fits.ImageHDU(data=np.ones((4,), dtype=np.float64), name="SCI")
Expand All @@ -614,10 +621,16 @@ def test_ndarray_validation(tmp_path):

# Should also be caught by validation
with pytest.raises(ValidationError, match="Wrong number of dimensions: Expected 2, got 1"):
# also warn due to the cast_fits_array deprecation
with pytest.warns(DeprecationWarning, match="cast_fits_array"):
with FitsModel(file_path, strict_validation=True, cast_fits_arrays=False, validate_arrays=True) as model:
model.validate()
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
category=UserWarning,
message="cast_arrays is deprecated and will be removed"
)
# also warn due to the cast_fits_array deprecation
with pytest.warns(DeprecationWarning, match="cast_fits_array"):
with FitsModel(file_path, strict_validation=True, cast_fits_arrays=False, validate_arrays=True) as model:
model.validate()


def test_resave_duplication_bug(tmp_path):
Expand Down

0 comments on commit 0a21094

Please sign in to comment.