File: test_warnings.py

package info (click to toggle)
python-fitsio 1.3.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,020 kB
  • sloc: python: 7,963; ansic: 3,962; makefile: 10
file content (42 lines) | stat: -rw-r--r-- 1,329 bytes parent folder | download
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,
            )