def test_creation():
wvln = np.linspace(1000., 4000., 1024)
flux = np.random.uniform(0., 1., wvln.size)
# try with list, array, Quantity input
s = Spectrum(list(wvln), list(flux))
s = Spectrum(wvln, flux)
s = Spectrum(wvln*u.angstrom, flux*u.erg/u.cm**2/u.angstrom)
# ------------------------------------------------------------------------
# Check that creation fails as expected if:
# 1) shapes don't match
with pytest.raises(ValueError):
s = Spectrum(wvln[:-1], flux)
with pytest.raises(ValueError):
s = Spectrum(wvln, flux[:-1])
# 2) object can't be coerced to a Quantity
with pytest.raises(TypeError):
s = Spectrum(wvln, None)
with pytest.raises(TypeError):
s = Spectrum(None, flux)
with pytest.raises(TypeError):
s = Spectrum(None, None)
# 3) wavelength goes negative
wvln2 = wvln.copy()
wvln2[:-10] *= -1.
with pytest.raises(ValueError):
s = Spectrum(wvln2, flux)
评论列表
文章目录