Skip to content

Commit

Permalink
Merge pull request #21 from mwcraig/fix-tests
Browse files Browse the repository at this point in the history
Standardize handling of tests in which exceptions are raised
  • Loading branch information
mwcraig committed Mar 20, 2014
2 parents 6ece73e + 0a6a5da commit fd16da0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
10 changes: 5 additions & 5 deletions ccdproc/tests/test_ccddata.py
Expand Up @@ -5,7 +5,7 @@
from astropy.io import fits

from numpy.testing import assert_array_equal
from astropy.tests.helper import pytest, raises
from astropy.tests.helper import pytest
from astropy.utils import NumpyRNGContext

from ..ccddata import CCDData, electrons, fromFITS
Expand Down Expand Up @@ -36,13 +36,13 @@ def test_fromFITS():
assert cd.meta == hdu.header


@raises(ValueError)
def test_fromMEF():
with NumpyRNGContext(123):
nd = np.random.random((10, 10))
hdu = fits.PrimaryHDU(nd)
hdulist = fits.HDUList([hdu, hdu])
cd = fromFITS(hdulist)
with pytest.raises(ValueError):
cd = fromFITS(hdulist)


def test_metafromheader():
Expand Down Expand Up @@ -72,10 +72,10 @@ def test_header2meta():
assert d1.header['OBSERVER'] == 'Edwin Hubble'


@raises(TypeError)
def test_metafromstring_fail():
hdr = 'this is not a valid header'
d1 = CCDData(np.ones((5, 5)), meta=hdr)
with pytest.raises(TypeError):
d1 = CCDData(np.ones((5, 5)), meta=hdr)


def test_create_variance():
Expand Down
11 changes: 3 additions & 8 deletions ccdproc/tests/test_ccdproc.py
Expand Up @@ -7,7 +7,7 @@
from astropy.units.quantity import Quantity

from numpy.testing import assert_array_equal
from astropy.tests.helper import pytest, raises
from astropy.tests.helper import pytest
from astropy.utils import NumpyRNGContext

from ..ccddata import CCDData, electrons, adu, fromFITS, toFITS
Expand Down Expand Up @@ -64,14 +64,9 @@ def test_subtract_overscan_model():
assert abs(ccd.data.mean()) < 0.1


@raises(TypeError)
def test_sutract_overscan_ccd_failt():
subtract_overscan(3, oscan, median=False, model=None)


@raises(TypeError)
def test_sutract_overscan_ccd_failt():
subtract_overscan(np.zeros((10, 10)), 3, median=False, model=None)
with pytest.raises(TypeError):
subtract_overscan(np.zeros((10, 10)), 3, median=False, model=None)


# test for flat correction
Expand Down
10 changes: 5 additions & 5 deletions ccdproc/tests/test_cosmicray.py
Expand Up @@ -5,7 +5,7 @@
from astropy.io import fits

from numpy.testing import assert_array_equal
from astropy.tests.helper import pytest, raises
from astropy.tests.helper import pytest
from astropy.utils import NumpyRNGContext

from ..ccddata import CCDData, electrons, fromFITS, toFITS
Expand Down Expand Up @@ -88,12 +88,12 @@ def test_background_variance_box():
assert abs(bd.mean() - scale) < 0.10


@raises(ValueError)
def test_background_variance_box_fail():
with NumpyRNGContext(123):
scale = 5.3
cd = np.random.normal(loc=0, size=(100, 100), scale=scale)
bd = background_variance_box(cd, 0.5)
with pytest.raises(ValueError):
bd = background_variance_box(cd, 0.5)


def test_background_variance_filter():
Expand All @@ -104,9 +104,9 @@ def test_background_variance_filter():
assert abs(bd.mean() - scale) < 0.10


@raises(ValueError)
def test_background_variance_filter_fail():
with NumpyRNGContext(123):
scale = 5.3
cd = np.random.normal(loc=0, size=(100, 100), scale=scale)
bd = background_variance_filter(cd, 0.5)
with pytest.raises(ValueError):
bd = background_variance_filter(cd, 0.5)
6 changes: 3 additions & 3 deletions ccdproc/test_gain.py → ccdproc/tests/test_gain.py
Expand Up @@ -6,12 +6,12 @@
from astropy import modeling as models

from numpy.testing import assert_array_equal
from astropy.tests.helper import pytest, raises
from astropy.tests.helper import pytest
from astropy.utils import NumpyRNGContext
from astropy.units.quantity import Quantity

from ccddata import CCDData, adu, electrons, fromFITS, toFITS
from ccdproc import *
from ..ccddata import CCDData, adu, electrons, fromFITS, toFITS
from ..ccdproc import *


def writeout(cd, outfile):
Expand Down

0 comments on commit fd16da0

Please sign in to comment.