File: test_read_line_lists.py

package info (click to toggle)
specreduce-data 0%2Bgit2021.11.18-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 36,064 kB
  • sloc: python: 211; makefile: 109
file content (33 lines) | stat: -rw-r--r-- 1,130 bytes parent folder | download | duplicates (2)
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
# test to make sure line list data is properly packaged and can be read in correctly

import os
import warnings

import astropy

from ..readers import read_basic_ascii_table, collect_data_files


def test_read_line_lists():
    line_dir = os.path.join("reference_data", "line_lists")
    data_files = collect_data_files(line_dir)
    for f in data_files:
        try:
            t = read_basic_ascii_table(f, names=['wavelength'])
            assert(len(t) > 0)
            assert(len(t.columns) >= 1)
        except astropy.io.ascii.core.InconsistentTableError as e:
            orig_e = e.__class__.__name__
            try:
                t = read_basic_ascii_table(
                    f,
                    reader="ascii.fixed_width",
                    names=['wavelength', 'info'],
                    col_starts=(0, 10),
                    delimiter=' '
                )
                assert(len(t) > 0)
                assert(len(t.columns) >= 1)
            except Exception as e:
                msg = f"Failed to load {f} as a AstroPy Table: {orig_e} {e.__class__.__name__}"
                warnings.warn(msg)