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 warning filters in tests for pytest 8 #245

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading