diff --git a/docs/changes.rst b/docs/changes.rst index f0b8a821..15cf1774 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -5,9 +5,11 @@ PyDL Changelog 1.0.0 (unreleased) ------------------ +* Update testing infrastructure (PR `#67`_). * Update links to documentation (PR `#64`_). .. _`#64`: https://github.com/weaverba137/pydl/pull/64 +.. _`#67`: https://github.com/weaverba137/pydl/pull/67 1.0.0rc2 (2021-07-22) --------------------- diff --git a/pydl/conftest.py b/pydl/conftest.py index 87e58416..a5ef64b0 100644 --- a/pydl/conftest.py +++ b/pydl/conftest.py @@ -3,7 +3,7 @@ This file is used to configure the behavior of pytest when using the Astropy test infrastructure. It needs to live inside the package in order for it to get picked up when running the tests inside an interpreter using -packagename.test +``pydl.test()`` """ @@ -11,17 +11,11 @@ from astropy.version import version as astropy_version -# For Astropy 3.0 and later, we can use the standalone pytest plugin -if astropy_version < '3.0': - from astropy.tests.pytest_plugins import * # noqa - del pytest_report_header +try: + from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS ASTROPY_HEADER = True -else: - try: - from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS - ASTROPY_HEADER = True - except ImportError: - ASTROPY_HEADER = False +except ImportError: + ASTROPY_HEADER = False def pytest_configure(config): @@ -46,16 +40,3 @@ def pytest_configure(config): from . import __version__ packagename = os.path.basename(os.path.dirname(__file__)) TESTED_VERSIONS[packagename] = __version__ - -# Uncomment the last two lines in this block to treat all DeprecationWarnings as -# exceptions. For Astropy v2.0 or later, there are 2 additional keywords, -# as follow (although default should work for most cases). -# To ignore some packages that produce deprecation warnings on import -# (in addition to 'compiler', 'scipy', 'pygments', 'ipykernel', and -# 'setuptools'), add: -# modules_to_ignore_on_import=['module_1', 'module_2'] -# To ignore some specific deprecation warning messages for Python version -# MAJOR.MINOR or later, add: -# warnings_to_ignore_by_pyver={(MAJOR, MINOR): ['Message to ignore']} -# from astropy.tests.helper import enable_deprecations_as_exceptions # noqa -# enable_deprecations_as_exceptions() diff --git a/pydl/goddard/tests/test_goddard.py b/pydl/goddard/tests/test_goddard.py index a602504c..05988447 100644 --- a/pydl/goddard/tests/test_goddard.py +++ b/pydl/goddard/tests/test_goddard.py @@ -2,9 +2,9 @@ # -*- coding: utf-8 -*- """Test the pydl.goddard package. """ +import pytest import numpy as np import astropy.units as u -from astropy.tests.helper import raises from ..astro import airtovac, gcirc, get_juldate, vactoair from ..math import flegendre from ..misc import cirrange @@ -65,7 +65,7 @@ def test_flegendre(): # # Test order # - with raises(ValueError): + with pytest.raises(ValueError): f = flegendre(x, 0) # # m = 1 @@ -140,7 +140,7 @@ def test_gcirc(): # # Units = whatever # - with raises(ValueError): + with pytest.raises(ValueError): d0 = gcirc(ra1, dec1, ra2, dec2, units=5) diff --git a/pydl/photoop/tests/test_photoop.py b/pydl/photoop/tests/test_photoop.py index f8406ad8..36752b3e 100644 --- a/pydl/photoop/tests/test_photoop.py +++ b/pydl/photoop/tests/test_photoop.py @@ -2,8 +2,8 @@ # -*- coding: utf-8 -*- """Test the functions in pydl.photoop.photoobj. """ +import pytest import numpy as np -from astropy.tests.helper import raises from ..photoobj import sdss_calibv, unwrap_objid @@ -36,5 +36,5 @@ def test_unwrap_objid(): assert objid.firstfield == 1 assert objid.frame == 618 assert objid.id == 459 - with raises(ValueError): + with pytest.raises(ValueError): objid = unwrap_objid(np.array([3.14159])) diff --git a/pydl/photoop/tests/test_sdssio.py b/pydl/photoop/tests/test_sdssio.py index aef4d1a0..301ea4a6 100644 --- a/pydl/photoop/tests/test_sdssio.py +++ b/pydl/photoop/tests/test_sdssio.py @@ -5,7 +5,6 @@ import os import pytest import numpy as np -from astropy.tests.helper import raises from ..sdssio import (filtername, filternum, sdss_calib, sdss_name, sdss_path, sdssflux2ab) @@ -109,7 +108,7 @@ def test_sdss_name(sdss_env): # # Bad ftype # - with raises(KeyError): + with pytest.raises(KeyError): p = sdss_name('fooBar', 137, 4, 42) for ftype in name_data: assert sdss_name(ftype, 137, 4, 42, '301', 'r', @@ -131,7 +130,7 @@ def test_sdss_name_reObj(sdss_env): def test_sdss_path(sdss_env): - with raises(KeyError): + with pytest.raises(KeyError): p = sdss_path('fooBar', 137) for ftype in path_data: assert sdss_path(ftype, 137, 4, '301') == path_data[ftype] diff --git a/pydl/photoop/tests/test_window.py b/pydl/photoop/tests/test_window.py index 878a9bb5..2680b6e6 100644 --- a/pydl/photoop/tests/test_window.py +++ b/pydl/photoop/tests/test_window.py @@ -5,7 +5,6 @@ import os import pytest import numpy as np -from astropy.tests.helper import raises from .. import PhotoopException from ..window import sdss_score, window_read, window_score from ...pydlutils.mangle import FITS_polygon @@ -58,7 +57,7 @@ def test_sdss_score(): def test_window_read_no_photo_resolve(monkeypatch): monkeypatch.delenv('PHOTO_RESOLVE', raising=False) - with raises(PhotoopException) as e: + with pytest.raises(PhotoopException) as e: window_read() assert (str(e.value) == 'You have not set the environment variable PHOTO_RESOLVE!') @@ -111,7 +110,7 @@ def test_window_read_rescore(monkeypatch, mocker, table_read): def test_window_score_no_photo_calib(monkeypatch): monkeypatch.delenv('PHOTO_CALIB', raising=False) - with raises(PhotoopException) as e: + with pytest.raises(PhotoopException) as e: window_score() assert (str(e.value) == 'You have not set the environment variable PHOTO_CALIB!') @@ -120,7 +119,7 @@ def test_window_score_no_photo_calib(monkeypatch): def test_window_score_no_photo_resolve(monkeypatch): monkeypatch.setenv('PHOTO_CALIB', '/fake/directory') monkeypatch.delenv('PHOTO_RESOLVE', raising=False) - with raises(PhotoopException) as e: + with pytest.raises(PhotoopException) as e: window_score() assert (str(e.value) == 'You have not set the environment variable PHOTO_RESOLVE!') @@ -129,7 +128,7 @@ def test_window_score_no_photo_resolve(monkeypatch): def test_window_score_no_window_flist(monkeypatch): monkeypatch.setenv('PHOTO_CALIB', '/fake/directory') monkeypatch.setenv('PHOTO_RESOLVE', '/another/fake/directory') - with raises(PhotoopException) as e: + with pytest.raises(PhotoopException) as e: window_score() assert str(e.value) == 'Unable to read FLIST file.' diff --git a/pydl/pydlspec2d/tests/test_spec1d.py b/pydl/pydlspec2d/tests/test_spec1d.py index 31260aa8..d974b418 100644 --- a/pydl/pydlspec2d/tests/test_spec1d.py +++ b/pydl/pydlspec2d/tests/test_spec1d.py @@ -5,7 +5,6 @@ import os import pytest import numpy as np -from astropy.tests.helper import raises from astropy.utils.data import get_pkg_data_filename from .. import Pydlspec2dException from ..spec1d import (HMF, findspec, log, spec_append, spec_path, template_metadata, @@ -96,7 +95,7 @@ def test_spec_path(sdss_env): def test_template_metadata(): - with raises(Pydlspec2dException): + with pytest.raises(Pydlspec2dException): slist, metadata = template_metadata('/no/such/file.par') inputfile = get_pkg_data_filename('t/test_template_metadata.par') slist, metadata = template_metadata(inputfile) diff --git a/pydl/pydlspec2d/tests/test_spec2d.py b/pydl/pydlspec2d/tests/test_spec2d.py index ac5f6011..fd3ac36b 100644 --- a/pydl/pydlspec2d/tests/test_spec2d.py +++ b/pydl/pydlspec2d/tests/test_spec2d.py @@ -6,7 +6,6 @@ import pytest import numpy as np from astropy.io import fits -from astropy.tests.helper import raises from astropy.utils.data import get_pkg_data_filename from ..spec2d import aesthetics, combine1fiber, filter_thru from .. import Pydlspec2dException @@ -42,7 +41,7 @@ def test_aesthetics(): # # Bad method # - with raises(Pydlspec2dException): + with pytest.raises(Pydlspec2dException): f = aesthetics(flux, ivar, 'badmethod') # # Nothing @@ -75,9 +74,9 @@ def test_filter_thru(sdss_env): # # Test bad input. # - with raises(ValueError): + with pytest.raises(ValueError): f = filter_thru(flux) - with raises(ValueError): + with pytest.raises(ValueError): f = filter_thru(flux, waveimg=waveimg, filter_prefix='sdss') return diff --git a/pydl/pydlutils/mangle.py b/pydl/pydlutils/mangle.py index 59b7570c..1b6dd9f6 100644 --- a/pydl/pydlutils/mangle.py +++ b/pydl/pydlutils/mangle.py @@ -583,7 +583,7 @@ def is_in_polygon(polygon, points, ncaps=0): usencaps = p['ncaps'] if ncaps > 0: usencaps = min(ncaps, p['ncaps']) - in_polygon = np.ones((npoints,), dtype=np.bool) + in_polygon = np.ones((npoints,), dtype=bool) for icap in range(usencaps): if is_cap_used(p['use_caps'], icap): in_polygon &= is_in_cap(p['x'][icap, :], p['cm'][icap], points) diff --git a/pydl/pydlutils/tests/test_bspline.py b/pydl/pydlutils/tests/test_bspline.py index df229f75..9f89256f 100644 --- a/pydl/pydlutils/tests/test_bspline.py +++ b/pydl/pydlutils/tests/test_bspline.py @@ -2,8 +2,8 @@ # -*- coding: utf-8 -*- """Test the functions in pydl.pydlutils.bspline. """ +import pytest import numpy as np -from astropy.tests.helper import catch_warnings, raises from .. import PydlutilsUserWarning from ..bspline import cholesky_band, cholesky_solve, iterfit from ... import smooth @@ -53,13 +53,13 @@ def test_cholesky_band(): i, ll = cholesky_band(ab) assert np.allclose(l, ll) ab[0, 0] = 1.0e-6 - with catch_warnings(PydlutilsUserWarning) as w: + with pytest.warns(PydlutilsUserWarning) as w: i, ll = cholesky_band(ab, mininf=1.0e-5) assert len(w) > 0 assert str(w[0].message) == "Bad entries: [0]" assert i == 0 # ab[0, :] = np.array([ 1., 2., 3., 4., 5., 6., 7., 0., 0., 0.]) - # with catch_warnings(PydlutilsUserWarning) as w: + # with pytest.warns(PydlutilsUserWarning) as w: # i, ll = cholesky_band(ab) # assert len(w) > 0 diff --git a/pydl/pydlutils/tests/test_cooling.py b/pydl/pydlutils/tests/test_cooling.py index 25e184ad..f1ad9526 100644 --- a/pydl/pydlutils/tests/test_cooling.py +++ b/pydl/pydlutils/tests/test_cooling.py @@ -2,13 +2,13 @@ # -*- coding: utf-8 -*- """Test the functions in pydl.pydlutils.cooling. """ +import pytest import numpy as np -from astropy.tests.helper import raises from ..cooling import read_ds_cooling def test_read_ds_cooling(): - with raises(ValueError): + with pytest.raises(ValueError): logT, loglambda = read_ds_cooling('m-99.cie') logT, logL = read_ds_cooling('m-15.cie') assert np.allclose(logT[0:5], np.array([4.0, 4.05, 4.1, 4.15, 4.2])) diff --git a/pydl/pydlutils/tests/test_coord.py b/pydl/pydlutils/tests/test_coord.py index bd7d5063..6dc2946c 100644 --- a/pydl/pydlutils/tests/test_coord.py +++ b/pydl/pydlutils/tests/test_coord.py @@ -5,7 +5,6 @@ import numpy as np from astropy import units as u from astropy.coordinates import ICRS -# from astropy.tests.helper import raises from ..coord import SDSSMuNu, current_mjd, stripe_to_eta, stripe_to_incl @@ -15,7 +14,7 @@ def test_current_mjd(): def test_munu_to_radec(): munu = SDSSMuNu(mu=0.0*u.deg, nu=0.0*u.deg, stripe=10) - radec = munu.transform_to(ICRS) + radec = munu.transform_to(ICRS()) assert radec.ra.value == 0.0 assert radec.dec.value == 0.0 diff --git a/pydl/pydlutils/tests/test_image.py b/pydl/pydlutils/tests/test_image.py index 929a2ecd..5740ce2d 100644 --- a/pydl/pydlutils/tests/test_image.py +++ b/pydl/pydlutils/tests/test_image.py @@ -2,8 +2,8 @@ # -*- coding: utf-8 -*- """Test the functions in pydl.pydlutils.image. """ +import pytest import numpy as np -from astropy.tests.helper import raises from ..image import djs_maskinterp1, djs_maskinterp @@ -56,11 +56,11 @@ def test_djs_maskinterp1(): def test_djs_maskinterp(): y = np.array([0.0, 1.0, 2.0, 3.0, 4.0], dtype=np.float64) mask = np.array([0, 1, 0]) - with raises(ValueError): + with pytest.raises(ValueError): yi = djs_maskinterp(y, mask) mask = np.array([0, 1, 0, 0, 0]) x = np.array([0.0, 0.5, 1.0], dtype=y.dtype) - with raises(ValueError): + with pytest.raises(ValueError): yi = djs_maskinterp(y, mask, xval=x) # 1-D case yi = djs_maskinterp(y, mask) @@ -70,11 +70,11 @@ def test_djs_maskinterp(): x = np.vstack((x, x, x)) y = np.vstack((y, y, y)) mask = np.vstack((mask, mask, mask)) - with raises(ValueError): + with pytest.raises(ValueError): yi = djs_maskinterp(y, mask) - with raises(ValueError): + with pytest.raises(ValueError): yi = djs_maskinterp(y, mask, axis=-1) - with raises(ValueError): + with pytest.raises(ValueError): yi = djs_maskinterp(y, mask, axis=2) yi = djs_maskinterp(y, mask, axis=0) assert np.allclose(y, yi) @@ -110,5 +110,5 @@ def test_djs_maskinterp(): assert np.allclose(y, yi) # 4-D case y = np.random.random((2, 2, 2, 2)) - with raises(ValueError): + with pytest.raises(ValueError): yi = djs_maskinterp(y, (y > 0.5), axis=0) diff --git a/pydl/pydlutils/tests/test_mangle.py b/pydl/pydlutils/tests/test_mangle.py index 72cfe648..40528512 100644 --- a/pydl/pydlutils/tests/test_mangle.py +++ b/pydl/pydlutils/tests/test_mangle.py @@ -1,9 +1,9 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst # -*- coding: utf-8 -*- +import pytest import numpy as np -from astropy.tests.helper import raises from astropy.utils.data import get_pkg_data_filename -from .. import PydlutilsException +from .. import PydlutilsException, PydlutilsUserWarning from .. import mangle as mng @@ -40,7 +40,7 @@ def test_ManglePolygon(self): # # Bad inputs # - with raises(ValueError): + with pytest.raises(ValueError): poly = mng.ManglePolygon(weight=1.0) # # Multiple caps @@ -70,7 +70,8 @@ def test_ManglePolygon(self): poly2 = poly.add_caps(np.array([[0.0, 1.0, 0.0], ]), np.array([1.0, ])) assert poly2.ncaps == 3 assert poly2.use_caps == poly.use_caps - assert poly2.str == 1.0 # dummy value! + with pytest.warns(PydlutilsUserWarning): + assert poly2.str == 1.0 # dummy value! poly3 = poly.polyn(poly2, 2) assert poly3.ncaps == 3 assert poly3.use_caps == poly.use_caps @@ -93,7 +94,7 @@ def test_angles_to_x(self): def test_cap_distance(self): x = np.array([0.0, 0.0, 1.0]) cm = 1.0 - with raises(ValueError): + with pytest.raises(ValueError): d = mng.cap_distance(x, cm, np.array([[1.0, 2.0, 3.0, 4.0], ])) d = mng.cap_distance(x, cm, np.array([[0.0, 45.0], ])) assert np.allclose(d, np.array([45.0])) @@ -106,7 +107,7 @@ def test_cap_distance(self): assert np.allclose(d, np.array([45.0])) def test_circle_cap(self): - with raises(ValueError): + with pytest.raises(ValueError): x, cm = mng.circle_cap(90.0, np.array([[1.0, 2.0, 3.0, 4.0], ])) xin = np.array([[0.0, 0.0, 1.0], ]) x, cm = mng.circle_cap(90.0, xin) @@ -122,7 +123,7 @@ def test_circle_cap(self): x, cm = mng.circle_cap(np.array([90.0, ]), radec) assert np.allclose(x, xin) assert np.allclose(cm, np.array([1.0, ])) - with raises(ValueError): + with pytest.raises(ValueError): x, cm = mng.circle_cap(np.array([90.0, 90.0]), radec) def test_is_cap_used(self): @@ -175,7 +176,7 @@ def test_read_fits_polygons(self): # assert (poly['USE_CAPS'] == use_caps).all() assert (poly['use_caps'] == use_caps).all() - with raises(AttributeError): + with pytest.raises(AttributeError): foo = poly.no_such_attribute cm0 = np.array([-1.0, -0.99369437, 1.0, -1.0, 0.00961538]) assert np.allclose(poly.cm[0][0:poly.ncaps[0]], cm0) @@ -196,7 +197,7 @@ def test_read_fits_polygons(self): assert poly[0].ncaps == 1 def test_read_mangle_polygons(self): - with raises(PydlutilsException): + with pytest.raises(PydlutilsException): poly = mng.read_mangle_polygons(self.bad_ply) poly = mng.read_mangle_polygons(self.poly_ply) assert len(poly.header) == 3 @@ -262,7 +263,7 @@ def test_single_polygon(self): pl.append(p) p2 = mng._single_polygon(pl) assert id(p2) == id(p) - with raises(ValueError): + with pytest.raises(ValueError): pl.append(p2) p3 = mng._single_polygon(pl) p = mng.read_fits_polygons(self.no_id_fits) diff --git a/pydl/pydlutils/tests/test_math.py b/pydl/pydlutils/tests/test_math.py index 0a20e3c6..9062bc45 100644 --- a/pydl/pydlutils/tests/test_math.py +++ b/pydl/pydlutils/tests/test_math.py @@ -2,8 +2,8 @@ # -*- coding: utf-8 -*- """Test the functions in pydl.pydlutils.math. """ +import pytest import numpy as np -from astropy.tests.helper import raises from astropy.utils.data import get_pkg_data_filename from ..math import computechi2, djs_median, find_contiguous @@ -62,17 +62,17 @@ def test_djs_median(): # # Exceptions # - with raises(ValueError): + with pytest.raises(ValueError): foo = djs_median(data, width=5, boundary='nearest') - with raises(ValueError): + with pytest.raises(ValueError): foo = djs_median(data, width=5, boundary='wrap') - with raises(ValueError): + with pytest.raises(ValueError): foo = djs_median(data, width=5, boundary='foobar') - with raises(ValueError): + with pytest.raises(ValueError): foo = djs_median(data2, width=5, dimension=1) - with raises(ValueError): + with pytest.raises(ValueError): foo = djs_median(data3, width=5) - with raises(ValueError): + with pytest.raises(ValueError): foo = djs_median(data3, width=5, boundary='reflect') diff --git a/pydl/pydlutils/tests/test_misc.py b/pydl/pydlutils/tests/test_misc.py index 553460d2..fd180509 100644 --- a/pydl/pydlutils/tests/test_misc.py +++ b/pydl/pydlutils/tests/test_misc.py @@ -3,9 +3,9 @@ """Test the functions in pydl.pydlutils.misc. """ import os +import pytest import numpy as np import tempfile -from astropy.tests.helper import raises from .. import PydlutilsException from ..misc import djs_laxisgen, djs_laxisnum, hogg_iau_name, struct_print @@ -25,7 +25,7 @@ def test_djs_laxisgen(): dtype='i4') assert (l == djs_laxisgen((4, 4))).all() assert (l.T == djs_laxisgen((4, 4), iaxis=1)).all() - with raises(ValueError): + with pytest.raises(ValueError): foo = djs_laxisgen((4, 4), iaxis=2) # # 3d @@ -37,12 +37,12 @@ def test_djs_laxisgen(): assert (l == djs_laxisgen((4, 4, 4))).all() assert (l.swapaxes(0, 1) == djs_laxisgen((4, 4, 4), iaxis=1)).all() assert (l.swapaxes(0, 2) == djs_laxisgen((4, 4, 4), iaxis=2)).all() - with raises(ValueError): + with pytest.raises(ValueError): foo = djs_laxisgen((4, 4, 4), iaxis=3) # # More d # - with raises(ValueError): + with pytest.raises(ValueError): foo = djs_laxisgen((4, 4, 4, 4)) @@ -61,7 +61,7 @@ def test_djs_laxisnum(): dtype='i4') assert (l == djs_laxisnum((4, 4))).all() assert (l.T == djs_laxisnum((4, 4), iaxis=1)).all() - with raises(ValueError): + with pytest.raises(ValueError): foo = djs_laxisnum((4, 4), iaxis=2) # # 3d @@ -73,12 +73,12 @@ def test_djs_laxisnum(): assert (l == djs_laxisnum((4, 4, 4))).all() assert (l.swapaxes(0, 1) == djs_laxisnum((4, 4, 4), iaxis=1)).all() assert (l.swapaxes(0, 2) == djs_laxisnum((4, 4, 4), iaxis=2)).all() - with raises(ValueError): + with pytest.raises(ValueError): foo = djs_laxisnum((4, 4, 4), iaxis=3) # # More d # - with raises(ValueError): + with pytest.raises(ValueError): foo = djs_laxisnum((4, 4, 4, 4)) @@ -103,8 +103,8 @@ def test_hogg_iau_name(): def test_struct_print(): - slist = np.zeros((5,), dtype=[('a', 'c16'), ('b', np.bool)]) - with raises(PydlutilsException): + slist = np.zeros((5,), dtype=[('a', 'c16'), ('b', bool)]) + with pytest.raises(PydlutilsException): lines, css = struct_print(slist, silent=True) slist = np.array([(1, 2.34, 'five'), (2, 3.456, 'seven'), diff --git a/pydl/pydlutils/tests/test_rgbcolor.py b/pydl/pydlutils/tests/test_rgbcolor.py index 093c3539..3114f0a7 100644 --- a/pydl/pydlutils/tests/test_rgbcolor.py +++ b/pydl/pydlutils/tests/test_rgbcolor.py @@ -2,8 +2,8 @@ # -*- coding: utf-8 -*- """Test the functions in pydl.pydlutils.rgbcolor. """ +import pytest import numpy as np -from astropy.tests.helper import catch_warnings, raises from .. import PydlutilsUserWarning from ..rgbcolor import (nw_arcsinh, nw_cut_to_box, nw_float_to_byte, nw_scale_rgb) @@ -11,10 +11,10 @@ def test_nw_arcsinh(): colors = np.random.random((10, 10)) - with raises(ValueError): + with pytest.raises(ValueError): fitted_colors = nw_arcsinh(colors) colors = np.random.random((10, 10, 5)) - with raises(ValueError): + with pytest.raises(ValueError): fitted_colors = nw_arcsinh(colors) colors = np.random.random((10, 10, 3)) fitted_colors = nw_arcsinh(colors, nonlinearity=0) @@ -27,39 +27,39 @@ def test_nw_arcsinh(): def test_nw_cut_to_box(): colors = np.random.random((10, 10)) - with raises(ValueError): + with pytest.raises(ValueError): boxed_colors = nw_cut_to_box(colors) colors = np.random.random((10, 10, 5)) - with raises(ValueError): + with pytest.raises(ValueError): boxed_colors = nw_cut_to_box(colors) colors = np.random.random((10, 10, 3)) - with raises(ValueError): + with pytest.raises(ValueError): boxed_colors = nw_cut_to_box(colors, origin=(1.0, 1.0)) boxed_colors = nw_cut_to_box(colors) assert np.allclose(boxed_colors, colors) def test_nw_float_to_byte(): - colors = np.zeros((10, 10, 3), dtype=np.float) + colors = np.zeros((10, 10, 3), dtype=np.float32) byte_colors = nw_float_to_byte(colors) assert (byte_colors == 0).all() - colors = np.ones((10, 10, 3), dtype=np.float) + colors = np.ones((10, 10, 3), dtype=np.float32) byte_colors = nw_float_to_byte(colors) assert (byte_colors == 255).all() - with catch_warnings(PydlutilsUserWarning) as w: + with pytest.warns(PydlutilsUserWarning) as w: byte_colors = nw_float_to_byte(colors, bits=16) assert len(w) > 0 def test_nw_scale_rgb(): colors = np.random.random((10, 10)) - with raises(ValueError): + with pytest.raises(ValueError): scaled_colors = nw_scale_rgb(colors) colors = np.random.random((10, 10, 5)) - with raises(ValueError): + with pytest.raises(ValueError): scaled_colors = nw_scale_rgb(colors) colors = np.random.random((10, 10, 3)) - with raises(ValueError): + with pytest.raises(ValueError): scaled_colors = nw_scale_rgb(colors, scales=(1.0, 1.0)) colors = np.ones((2, 2, 3)) scaled_colors = nw_scale_rgb(colors, scales=(2.0, 2.0, 2.0)) diff --git a/pydl/pydlutils/tests/test_sdss.py b/pydl/pydlutils/tests/test_sdss.py index 3628bccd..7f9ce520 100644 --- a/pydl/pydlutils/tests/test_sdss.py +++ b/pydl/pydlutils/tests/test_sdss.py @@ -1,8 +1,8 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst # -*- coding: utf-8 -*- +import pytest import numpy as np import pydl.pydlutils.sdss -from astropy.tests.helper import remote_data, raises from astropy.utils.data import get_pkg_data_filename from ..sdss import (default_skyversion, sdss_flagexist, sdss_flagname, sdss_flagval, set_maskbits, sdss_astrombad, @@ -58,7 +58,7 @@ def test_sdss_flagname(self): names = sdss_flagname('ANCILLARY_TARGET1', 2310346608843161600, concat=True) assert names == 'BRIGHTGAL BLAZGX ELG' - with raises(KeyError): + with pytest.raises(KeyError): names = sdss_flagname('ABADMASK', 123456789) def test_sdss_flagval(self): @@ -66,9 +66,9 @@ def test_sdss_flagval(self): assert val == 2**9 val = sdss_flagval('ANCILLARY_TARGET1', ['BLAZGX', 'ELG', 'BRIGHTGAL']) assert val == 2310346608843161600 - with raises(KeyError): + with pytest.raises(KeyError): val = sdss_flagval('TARGET', 'ROSAT_Q') - with raises(KeyError): + with pytest.raises(KeyError): val = sdss_flagval('ABADMASK', "ABADFLAG") def test_set_maskbits(self): @@ -98,24 +98,24 @@ def test_sdss_astrombad(self): np.array([False, True, True])).all() def test_sdss_astrombad_raises(self): - with raises(ValueError): + with pytest.raises(ValueError): foo = sdss_astrombad(77, 32, 20) - with raises(ValueError): + with pytest.raises(ValueError): foo = sdss_astrombad(-1, 1, 20) - with raises(ValueError): + with pytest.raises(ValueError): foo = sdss_astrombad(2**17, 1, 20) - with raises(ValueError): + with pytest.raises(ValueError): foo = sdss_astrombad(-2, 1, 20) - with raises(ValueError): + with pytest.raises(ValueError): foo = sdss_astrombad(251, 1, 2**16) - with raises(ValueError): + with pytest.raises(ValueError): foo = sdss_astrombad(np.array([77, 85, 251]), np.array([1]), np.array([20, 15, 151])) - with raises(ValueError): + with pytest.raises(ValueError): foo = sdss_astrombad(np.array([77, 85, 251]), np.array([1, 2, 3]), np.array([20])) - @remote_data + @pytest.mark.remote_data def test_sdss_astrombad_remote(self): pydl.pydlutils.sdss.opbadfields = None assert not sdss_astrombad(77, 1, 20) @@ -136,47 +136,47 @@ def test_sdss_objid(self): # # Exceptions # - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(run, 3, 91, 146) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, camcol, 91, 146) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, field, 146) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 91, obj) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 91, 146, rerun=np.array([137, 301])) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 91, 146, skyversion=np.array([2, 3])) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 91, 146, firstfield=np.array([0, 1])) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 91, 146, skyversion=-2) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 91, 146, skyversion=16) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 91, 146, firstfield=-2) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 91, 146, firstfield=2) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 91, 146, rerun=-2) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 91, 146, rerun=2**11) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(-2, 3, 91, 146) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(2**16, 3, 91, 146) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 0, 91, 146) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 7, 91, 146) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, -2, 146) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 2**12, 146) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 91, -2) - with raises(ValueError): + with pytest.raises(ValueError): objid = sdss_objid(3704, 3, 91, 2**16) def test_sdss_specobjid(self): @@ -198,49 +198,49 @@ def test_sdss_specobjid(self): # # Exceptions # - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(np.array([4055, 4056]), 408, 55359, 'v5_7_0') - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, np.array([408, 409]), 55359, 'v5_7_0') - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, np.array([55359, 55360]), 'v5_7_0') - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 55359, np.array(['v5_7_0', 'v5_7_2'])) - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 55359, 'v5_7_0', line=np.array([137, 138])) - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 55359, 'v5_7_0', index=np.array([137, 138])) - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 55359, 'v5_7_0', line=137, index=137) - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 55359, 'V5.7.0') - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(-1, 408, 55359, 'v5_7_0') - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(2**15, 408, 55359, 'v5_7_0') - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, -1, 55359, 'v5_7_0') - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 2**12, 55359, 'v5_7_0') - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 49999, 'v5_7_0') - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 2**15, 'v5_7_0') - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 55359, -1) - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 55359, 2**15) - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 55359, 'v5_7_0', line=-1) - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 55359, 'v5_7_0', line=2**10) - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 55359, 'v5_7_0', index=-1) - with raises(ValueError): + with pytest.raises(ValueError): s = sdss_specobjid(4055, 408, 55359, 'v5_7_0', index=2**10) def test_unwrap_specobjid(self): @@ -291,6 +291,6 @@ def test_unwrap_specobjid(self): # # Exceptions # - with raises(ValueError): + with pytest.raises(ValueError): d = unwrap_specobjid(np.array([4565636362342690816], dtype=np.int64)) diff --git a/pydl/pydlutils/tests/test_spheregroup.py b/pydl/pydlutils/tests/test_spheregroup.py index ecb098b8..c765a83c 100644 --- a/pydl/pydlutils/tests/test_spheregroup.py +++ b/pydl/pydlutils/tests/test_spheregroup.py @@ -2,8 +2,8 @@ # -*- coding: utf-8 -*- """Test the functions in pydl.pydlutils.spheregroup. """ +import pytest import numpy as np -from astropy.tests.helper import raises, catch_warnings from astropy.utils.data import get_pkg_data_filename from ..spheregroup import spheregroup, spherematch from .. import PydlutilsException, PydlutilsUserWarning @@ -57,12 +57,12 @@ def test_spheregroup(): # # Exceptions # - with raises(PydlutilsException): + with pytest.raises(PydlutilsException): group = spheregroup(np.array([137.0]), np.array([55.0]), linklength) # # warnings # - with catch_warnings(PydlutilsUserWarning) as w: + with pytest.warns(PydlutilsUserWarning) as w: group = spheregroup(ra, dec, linklength, chunksize=linklength) # w = recwarn.pop(PydlutilsUserWarning) assert "chunksize changed to" in str(w[0].message) diff --git a/pydl/pydlutils/tests/test_trace.py b/pydl/pydlutils/tests/test_trace.py index 50975bec..32ff3b45 100644 --- a/pydl/pydlutils/tests/test_trace.py +++ b/pydl/pydlutils/tests/test_trace.py @@ -1,8 +1,8 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst # -*- coding: utf-8 -*- +import pytest import numpy as np from astropy.io import fits -from astropy.tests.helper import raises from astropy.utils.data import get_pkg_data_filename from ..trace import (fchebyshev, fchebyshev_split, fpoly, func_fit, TraceSet, traceset2xy, xy2traceset) @@ -31,7 +31,7 @@ def test_fchebyshev(self): # # Test order # - with raises(ValueError): + with pytest.raises(ValueError): f = fchebyshev(x, 0) # # m = 1 @@ -73,9 +73,9 @@ def test_fchebyshev_split(self): # # Test order # - with raises(ValueError): + with pytest.raises(ValueError): f = fchebyshev_split(x, 0) - with raises(ValueError): + with pytest.raises(ValueError): f = fchebyshev_split(x, 1) # # m = 2 @@ -122,7 +122,7 @@ def test_fpoly(self): # # Test order # - with raises(ValueError): + with pytest.raises(ValueError): f = fpoly(x, 0) # # m = 1 @@ -166,13 +166,13 @@ def test_func_fit(self): # # Bad inputs # - with raises(ValueError): + with pytest.raises(ValueError): foo = func_fit(x, np.array([1, 2, 3]), 3) - with raises(ValueError): + with pytest.raises(ValueError): foo = func_fit(x, y, 3, invvar=np.array([0, 0, 0])) - with raises(ValueError): + with pytest.raises(ValueError): foo = func_fit(x, y, 3, inputfunc=np.array([1.0, 1.0, 1.0])) - with raises(KeyError): + with pytest.raises(KeyError): foo = func_fit(x, y, 3, function_name='npoly') # # No good points @@ -263,12 +263,12 @@ def test_traceset_keywords(self): tset = TraceSet(self.boss[1].data) x, y = traceset2xy(tset) iv = 2.0 * np.ones(x.shape, dtype=x.dtype) - im = np.ones(x.shape, dtype=np.bool) + im = np.ones(x.shape, dtype=bool) im[1] = False tset2 = TraceSet(x, y, func='chebyshev', invvar=iv, maxiter=20, inmask=im) assert tset2.func == 'chebyshev' def test_traceset_bad(self): - with raises(PydlutilsException): + with pytest.raises(PydlutilsException): tset = TraceSet(1, 2, 3) diff --git a/pydl/pydlutils/tests/test_yanny.py b/pydl/pydlutils/tests/test_yanny.py index 31259826..5b269112 100644 --- a/pydl/pydlutils/tests/test_yanny.py +++ b/pydl/pydlutils/tests/test_yanny.py @@ -8,8 +8,8 @@ from tempfile import mkdtemp from time import sleep from collections import OrderedDict +import pytest import numpy as np -from astropy.tests.helper import catch_warnings, raises from astropy.utils.data import get_pkg_data_filename from astropy.table import Table from astropy.io.registry import (register_identifier, register_reader, @@ -33,8 +33,8 @@ def setup(self): self.temp_dir = mkdtemp(prefix='yanny-test-') # Ignore deprecation warnings--this only affects Python 2.5 and 2.6, # since deprecation warnings are ignored by defualt on 2.7 - warnings.simplefilter('ignore') - warnings.simplefilter('always', UserWarning) + # warnings.simplefilter('ignore') + # warnings.simplefilter('always', UserWarning) # raise ValueError("I am setting up a subclass of YannyTestCase!") with open(get_pkg_data_filename("t/yanny_data.json")) as js: self.test_data = json.load(js) @@ -103,9 +103,9 @@ def test_read_table_yanny(self): """Test reading to an astropy Table. """ filename = self.data('test_table.par') - with raises(PydlutilsException): + with pytest.raises(PydlutilsException): t = Table.read(filename) - with raises(KeyError): + with pytest.raises(KeyError): t = Table.read(filename, tablename='foo') t = Table.read(filename, tablename='test') assert isinstance(t.meta, OrderedDict) @@ -192,10 +192,10 @@ def test_write_ndarray_to_yanny_exceptions(self): for col in table['dtype']: mystruct[col[0]] = np.array(table['data'][col[0]], dtype=col[1]) enums = {'new_flag': test_data['enums']['new_flag']} - with raises(PydlutilsException): + with pytest.raises(PydlutilsException): par = write_ndarray_to_yanny(self.data('test.par'), mystruct, structnames='magnitudes', enums=enums) - with raises(PydlutilsException): + with pytest.raises(PydlutilsException): par = write_ndarray_to_yanny(self.temp('tempfile3.par'), mystruct, structnames=('magnitudes', 'my_status'), enums=enums) @@ -324,15 +324,15 @@ def test_yanny(self): # Test expected write failures. # # This should fail, since test.par already exists. - with raises(PydlutilsException): + with pytest.raises(PydlutilsException): par.write() - with catch_warnings(PydlutilsUserWarning) as w: + with pytest.warns(PydlutilsUserWarning) as w: par.append({}) datatable = {'status_update': {'state': ['SUCCESS', 'SUCCESS'], 'timestamp': ['2008-06-22 01:27:33', '2008-06-22 01:27:36']}, 'new_keyword': 'new_value'} par.filename = self.temp('test_append.par') # This should also fail, because test_append.par does not exist. - with raises(PydlutilsException): + with pytest.raises(PydlutilsException): par.append(datatable) return diff --git a/pydl/pydlutils/trace.py b/pydl/pydlutils/trace.py index 390bb788..3ecf60bd 100644 --- a/pydl/pydlutils/trace.py +++ b/pydl/pydlutils/trace.py @@ -187,7 +187,7 @@ def func_fit(x, y, ncoeff, invvar=None, function_name='legendre', ia=None, if invvar.shape != x.shape: raise ValueError('Dimensions of X and invvar do not agree!') if ia is None: - ia = np.ones((ncoeff,), dtype=np.bool) + ia = np.ones((ncoeff,), dtype=bool) if not ia.all(): if inputans is None: inputans = np.zeros((ncoeff,), dtype=x.dtype) @@ -346,7 +346,7 @@ def __init__(self, *args, **kwargs): if 'inmask' in kwargs: inmask = kwargs['inmask'] else: - inmask = np.ones(xpos.shape, dtype=np.bool) + inmask = np.ones(xpos.shape, dtype=bool) do_jump = False if 'xjumplo' in kwargs: do_jump = True @@ -362,7 +362,7 @@ def __init__(self, *args, **kwargs): else: self.xjumpval = None self.coeff = np.zeros((self.nTrace, self.ncoeff), dtype=xpos.dtype) - self.outmask = np.zeros(xpos.shape, dtype=np.bool) + self.outmask = np.zeros(xpos.shape, dtype=bool) self.yfit = np.zeros(xpos.shape, dtype=xpos.dtype) for iTrace in range(self.nTrace): xvec = self.xnorm(xpos[iTrace, :], do_jump) diff --git a/pydl/rebin.py b/pydl/rebin.py index 39d1c693..b84b3010 100644 --- a/pydl/rebin.py +++ b/pydl/rebin.py @@ -50,12 +50,12 @@ def rebin(x, d, sample=False): Examples -------- - >>> from numpy import arange, float + >>> from numpy import arange, float32 >>> from pydl import rebin - >>> rebin(arange(10, dtype=float), (5,)) # doctest: +NORMALIZE_WHITESPACE - array([0.5, 2.5, 4.5, 6.5, 8.5]) - >>> rebin(arange(5, dtype=float), (10,)) # doctest: +NORMALIZE_WHITESPACE - array([0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4. ]) + >>> rebin(arange(10, dtype=float32), (5,)) # doctest: +NORMALIZE_WHITESPACE + array([0.5, 2.5, 4.5, 6.5, 8.5], dtype=float32) + >>> rebin(arange(5, dtype=float32), (10,)) # doctest: +NORMALIZE_WHITESPACE + array([0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4. ], dtype=float32) """ from numpy import floor, zeros d0 = x.shape diff --git a/pydl/tests/test_pydl.py b/pydl/tests/test_pydl.py index 1a386888..14b6771a 100644 --- a/pydl/tests/test_pydl.py +++ b/pydl/tests/test_pydl.py @@ -8,7 +8,6 @@ from astropy.tests.compat import assert_allclose except ImportError: from numpy.testing import assert_allclose -from astropy.tests.helper import raises from astropy.utils.data import get_pkg_data_filename from ..file_lines import file_lines from ..median import median @@ -55,7 +54,7 @@ def test_median(): assert median(even_data) == 7 assert median(even_data, even=True) == 6.5 assert (median(odd_data, 3) == odd_data).all() - with raises(ValueError): + with pytest.raises(ValueError): foo = median(np.ones((9, 9, 9)), 3) odd_data2 = np.vstack((odd_data, odd_data, odd_data, odd_data, odd_data)) assert (median(odd_data2, 3) == odd_data2).all() @@ -67,7 +66,7 @@ def test_median(): def test_pcomp(): test_data_file = get_pkg_data_filename('t/pcomp_data.txt') test_data = np.loadtxt(test_data_file, dtype='d', delimiter=',') - with raises(ValueError): + with pytest.raises(ValueError): foo = pcomp(np.arange(10)) pcomp_data = test_data[0:20, :] m = 4 @@ -126,11 +125,11 @@ def test_pcomp(): def test_rebin(): x = np.arange(40) - with raises(ValueError): + with pytest.raises(ValueError): r = rebin(x, d=(10, 10)) - with raises(ValueError): + with pytest.raises(ValueError): r = rebin(x, d=(70,)) - with raises(ValueError): + with pytest.raises(ValueError): r = rebin(x, d=(30,)) x = np.array([[1.0, 2.0], [2.0, 3.0]]) rexpect = np.array([[1.0, 2.0], [1.5, 2.5], [2.0, 3.0], [2.0, 3.0]]) diff --git a/setup.py b/setup.py index 366b5dfa..0ca3df0f 100755 --- a/setup.py +++ b/setup.py @@ -11,8 +11,6 @@ # from extension_helpers import get_extensions -from distutils.command.sdist import sdist as DistutilsSdist - # First provide helpful messages if contributors try and run legacy commands # for tests or docs. @@ -78,8 +76,6 @@ version = '{version}' """.lstrip() -cmdclass = {'sdist': DistutilsSdist} - setup(use_scm_version={"write_to": os.path.join("pydl", "version.py"), - "write_to_template": VERSION_TEMPLATE}, - cmdclass=cmdclass) + "write_to_template": VERSION_TEMPLATE}) + # ext_modules=get_extensions())