1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
import os
import tempfile
import warnings
import numpy as np
from ..fitslib import FITS
from ..util import FITSRuntimeWarning
def test_non_standard_key_value():
with tempfile.TemporaryDirectory() as tmpdir:
fname = os.path.join(tmpdir, 'test.fits')
im = np.zeros((3, 3))
with warnings.catch_warnings(record=True) as w:
with FITS(fname, 'rw') as fits:
fits.write(im)
# now write a key with a non-standard value
value = {'test': 3}
fits[-1].write_key('odd', value)
# DeprecationWarnings have crept into the Warning list. This will
# filter the list to be just
# FITSRuntimeWarning instances.
# @at88mph 2019.10.09
filtered_warnings = list(
filter(
lambda x: 'FITSRuntimeWarning' in '{}'.format(x.category),
w,
) # noqa
)
assert len(filtered_warnings) == 1, (
'Wrong length of output (Expected {} but got {}.)'.format(
1,
len(filtered_warnings),
)
)
assert issubclass(
filtered_warnings[-1].category,
FITSRuntimeWarning,
)
|