tests.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:SoftwareTesting 作者: adrn 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号