Skip to content

Commit

Permalink
Polishing test infrastructure.
Browse files Browse the repository at this point in the history
* Display pytest header correctly.
* Make test generate output in tmpdir, not cwd.
* Close open file in test gracefully.
* Ignore remaining ResourceWarning, see spacetelescope#119.
  • Loading branch information
pllim committed Apr 3, 2020
1 parent 6c4cc95 commit 27692fb
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ htmlcov
.coverage
MANIFEST
.ipynb_checkpoints
u40x010hm*.fits

# Sphinx
docs/api
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TESTED_VERSIONS = {}

try:
from .version import version
from stsci.tools import __version__ as version
except ImportError:
version = 'unknown'

Expand Down
35 changes: 20 additions & 15 deletions lib/stsci/tools/tests/test_check_files.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import shutil

import pytest
from astropy.io import fits
from astropy.io.fits import diff

Expand All @@ -10,6 +9,7 @@

data_dir = os.path.join(os.path.dirname(__file__), 'data')


def test_exptime():
fobj = fits.HDUList([fits.PrimaryHDU(), fits.ImageHDU()])
fobj[0].header['INSTRUME'] = 'ACS'
Expand Down Expand Up @@ -41,29 +41,34 @@ def test_check_files():

fname = os.path.join(data_dir, 'acs_test.fits')
result = check_files.checkFiles([fname])
assert result == ([os.path.join(data_dir, 'acs_test.fits')], [None])
assert result == ([os.path.join(data_dir, 'acs_test.fits')], [None])

fobj = fits.open(fname)
result = check_files.checkFiles([fobj])
assert isinstance(result[0][0], fits.HDUList)
assert result[0][0].filename() == os.path.join(data_dir, 'acs_test.fits')
assert result[1] == [None]
with fits.open(fname) as fobj:
result = check_files.checkFiles([fobj])
assert isinstance(result[0][0], fits.HDUList)
assert result[0][0].filename() == os.path.join(data_dir, 'acs_test.fits')
assert result[1] == [None]

fname = os.path.join(data_dir, 'o4sp040b0_raw.fits')
assert check_files.checkFiles([fname]) == ([], [])


def test_waivered_fits():
def test_waivered_fits(tmpdir):
"""
Test converting wavered FITS to multiextension FITS.
"""
c0f_name = 'u40x010hm_c0f.fits'
c0h_name = 'u40x010hm_c0h.fits'
path_name = os.path.join(data_dir, c0f_name)
shutil.copyfile(path_name, c0f_name)
check_files.checkFiles([c0f_name])
fobj = fits.open(c0f_name, mode='update')
fnew, _ = check_files.checkFiles([fobj])
assert fu.isFits(fnew[0]) == (True, 'mef')
report = diff.FITSDiff(fnew[0], c0h_name).report()
assert report.splitlines()[-1] == 'No differences found.'
current_dir = os.getcwd()
try:
os.chdir(tmpdir)
shutil.copyfile(path_name, c0f_name)
check_files.checkFiles([c0f_name])
with fits.open(c0f_name, mode='update') as fobj:
fnew, _ = check_files.checkFiles([fobj])
assert fu.isFits(fnew[0]) == (True, 'mef')
report = diff.FITSDiff(fnew[0], c0h_name).report()
assert report.splitlines()[-1] == 'No differences found.'
finally:
os.chdir(current_dir)
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ console_scripts =
minversion = 4
testpaths = lib/stsci/tools
addopts = --doctest-modules
astropy_header = true
xfail_strict = true
filterwarnings =
ignore:.*Column disp option
ignore:NMPFIT is deprecated
ignore:GFIT is deprecated
ignore:unclosed file:ResourceWarning

[flake8]
# E501: line too long
Expand Down

0 comments on commit 27692fb

Please sign in to comment.