Skip to content

Commit

Permalink
Clean-up: avoid writing or using tests/data/test_factory* files
Browse files Browse the repository at this point in the history
  • Loading branch information
barentsen committed Apr 24, 2019
1 parent 55ec7c8 commit a145a78
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -73,3 +73,4 @@ pyraf
sandbox
mastDownload
.pytest_cache
.vscode
7 changes: 5 additions & 2 deletions lightkurve/search.py
Expand Up @@ -900,8 +900,11 @@ def open(path_or_url, **kwargs):
>>> tpf = open("mytpf.fits") # doctest: +SKIP
"""
# pass header into `detect_filetype()`
with fits.open(path_or_url) as temp:
filetype = detect_filetype(temp[0].header)
try:
with fits.open(path_or_url) as temp:
filetype = detect_filetype(temp[0].header)
except OSError: # Raised if not a fits file ("Header missing END card")
filetype = None

# if the filetype is recognized, instantiate a class of that name
if filetype is not None:
Expand Down
Binary file removed lightkurve/tests/data/test_factory0.fits
Binary file not shown.
Binary file removed lightkurve/tests/data/test_factory1.fits
Binary file not shown.
Binary file removed lightkurve/tests/data/test_factory2.fits
Binary file not shown.
Binary file removed lightkurve/tests/data/test_factory3.fits
Binary file not shown.
Binary file removed lightkurve/tests/data/test_factory4.fits
Binary file not shown.
2 changes: 1 addition & 1 deletion lightkurve/tests/test_search.py
Expand Up @@ -293,7 +293,7 @@ def test_open():
assert(isinstance(tesstpf, TessTargetPixelFile))
# Open should fail if the filetype is not recognized
try:
open(os.path.join(PACKAGEDIR, "tests", "data", "test_factory0.fits"))
open(os.path.join(PACKAGEDIR, "data", "lightkurve.mplstyle"))
except ValueError:
pass
# Can you instantiate with a path?
Expand Down
13 changes: 9 additions & 4 deletions lightkurve/tests/test_targetpixelfile.py
Expand Up @@ -346,15 +346,16 @@ def test_tpf_from_images():

# Can we read in a list of file names or a list of HDUlists?
hdus = []
tmpfile_names = []
for idx, im in enumerate(images):
tmpfile = tempfile.NamedTemporaryFile(delete=False)
tmpfile_names.append(tmpfile.name)
hdu = fits.HDUList([fits.PrimaryHDU(), im])
hdu.writeto(get_pkg_data_filename('data/test_factory{}.fits'.format(idx)), overwrite=True)
hdu.writeto(tmpfile.name)
hdus.append(hdu)

fnames = [get_pkg_data_filename('data/test_factory{}.fits'.format(i)) for i in range(5)]

# Should be able to run with a list of file names
tpf_fnames = KeplerTargetPixelFile.from_fits_images(fnames,
tpf_tmpfiles = KeplerTargetPixelFile.from_fits_images(tmpfile_names,
size=(3, 3),
position=SkyCoord(ra, dec, unit=(u.deg, u.deg)))

Expand All @@ -363,6 +364,10 @@ def test_tpf_from_images():
size=(3, 3),
position=SkyCoord(ra, dec, unit=(u.deg, u.deg)))

# Clean up the temporary files we created
for filename in tmpfile_names:
os.remove(filename)


def test_tpf_wcs_from_images():
"""Test to see if tpf.from_fits_images() output a tpf with WCS in the header"""
Expand Down

0 comments on commit a145a78

Please sign in to comment.