Skip to content

Commit

Permalink
BUG: Raise ImportError if optional dependency speclite is not install…
Browse files Browse the repository at this point in the history
  • Loading branch information
rrjbca committed Sep 18, 2021
1 parent 9140a5c commit c9c61bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions skypy/utils/photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
]

try:
import speclite.filters
import speclite.filters # noqa F401
except ImportError:
HAS_SPECLITE = False
else:
Expand Down Expand Up @@ -84,11 +84,12 @@ def mag_ab(wavelength, spectrum, filters, *, redshift=None, coefficients=None,
.. [1] M. R. Blanton et al., 2003, AJ, 125, 2348
'''
from speclite.filters import load_filters

# load the filters
if np.ndim(filters) == 0:
filters = (filters,)
filters = speclite.filters.load_filters(*filters)
filters = load_filters(*filters)
if np.shape(filters) == (1,):
filters = filters[0]

Expand Down
14 changes: 14 additions & 0 deletions skypy/utils/tests/test_photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,17 @@ def __init__(self):
Planck15, resolution=2)
np.testing.assert_allclose(m_true, m_interp, rtol=1e-5)
assert not np.all(m_true == m_interp)


@pytest.mark.skipif(HAS_SPECLITE, reason='test requires that speclite is not installed')
def test_speclite_not_installed():
"""
Regression test for #436
Test that mag_ab raises the correct exception if speclite is not insalled.
"""
from skypy.utils.photometry import mag_ab
wavelength = np.linspace(1, 10, 100)
spectrum = np.ones(10)
filter = 'bessell-B'
with pytest.raises(ImportError):
mag_ab(wavelength, spectrum, filter)

0 comments on commit c9c61bc

Please sign in to comment.