-
Notifications
You must be signed in to change notification settings - Fork 158
/
test_read.py
60 lines (52 loc) · 2.5 KB
/
test_read.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
import warnings
import pytest
from ...utils import LightkurveDeprecationWarning, LightkurveError
from ... import PACKAGEDIR, KeplerTargetPixelFile, TessTargetPixelFile
from .. import read
def test_read():
# define paths to k2 and tess data
k2_path = os.path.join(PACKAGEDIR, "tests", "data", "test-tpf-star.fits")
tess_path = os.path.join(PACKAGEDIR, "tests", "data", "tess25155310-s01-first-cadences.fits.gz")
# Ensure files are read in as the correct object
k2tpf = read(k2_path)
assert(isinstance(k2tpf, KeplerTargetPixelFile))
tesstpf = read(tess_path)
assert(isinstance(tesstpf, TessTargetPixelFile))
# Open should fail if the filetype is not recognized
try:
read(os.path.join(PACKAGEDIR, "data", "lightkurve.mplstyle"))
except LightkurveError:
pass
# Can you instantiate with a path?
assert(isinstance(KeplerTargetPixelFile(k2_path), KeplerTargetPixelFile))
assert(isinstance(TessTargetPixelFile(tess_path), TessTargetPixelFile))
# Can open take a quality_bitmask argument?
assert(read(k2_path, quality_bitmask='hard').quality_bitmask == 'hard')
def test_open():
"""Does the deprecated `open` function still work?"""
from .. import open
with warnings.catch_warnings(): # lk.open is deprecated
warnings.simplefilter("ignore", LightkurveDeprecationWarning)
# define paths to k2 and tess data
k2_path = os.path.join(PACKAGEDIR, "tests", "data", "test-tpf-star.fits")
tess_path = os.path.join(PACKAGEDIR, "tests", "data", "tess25155310-s01-first-cadences.fits.gz")
# Ensure files are read in as the correct object
k2tpf = open(k2_path)
assert(isinstance(k2tpf, KeplerTargetPixelFile))
tesstpf = open(tess_path)
assert(isinstance(tesstpf, TessTargetPixelFile))
# Open should fail if the filetype is not recognized
try:
open(os.path.join(PACKAGEDIR, "data", "lightkurve.mplstyle"))
except LightkurveError:
pass
# Can you instantiate with a path?
assert(isinstance(KeplerTargetPixelFile(k2_path), KeplerTargetPixelFile))
assert(isinstance(TessTargetPixelFile(tess_path), TessTargetPixelFile))
# Can open take a quality_bitmask argument?
assert(open(k2_path, quality_bitmask='hard').quality_bitmask == 'hard')
def test_filenotfound():
"""Regression test for #540; ensure lk.read() yields `FileNotFoundError`."""
with pytest.raises(FileNotFoundError):
read("DOESNOTEXIST")