Skip to content

Commit

Permalink
Merge 8b36832 into 0fd5177
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Jan 14, 2022
2 parents 0fd5177 + 8b36832 commit 230d5b2
Show file tree
Hide file tree
Showing 25 changed files with 168 additions and 194 deletions.
2 changes: 2 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
---------------------
Expand Down
29 changes: 5 additions & 24 deletions pydl/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,19 @@
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()``
"""

import os

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):
Expand All @@ -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()
6 changes: 3 additions & 3 deletions pydl/goddard/tests/test_goddard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_flegendre():
#
# Test order
#
with raises(ValueError):
with pytest.raises(ValueError):
f = flegendre(x, 0)
#
# m = 1
Expand Down Expand Up @@ -140,7 +140,7 @@ def test_gcirc():
#
# Units = whatever
#
with raises(ValueError):
with pytest.raises(ValueError):
d0 = gcirc(ra1, dec1, ra2, dec2, units=5)


Expand Down
4 changes: 2 additions & 2 deletions pydl/photoop/tests/test_photoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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]))
5 changes: 2 additions & 3 deletions pydl/photoop/tests/test_sdssio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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',
Expand All @@ -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]
Expand Down
9 changes: 4 additions & 5 deletions pydl/photoop/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!')
Expand Down Expand Up @@ -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!')
Expand All @@ -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!')
Expand All @@ -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.'

Expand Down
3 changes: 1 addition & 2 deletions pydl/pydlspec2d/tests/test_spec1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions pydl/pydlspec2d/tests/test_spec2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,7 +41,7 @@ def test_aesthetics():
#
# Bad method
#
with raises(Pydlspec2dException):
with pytest.raises(Pydlspec2dException):
f = aesthetics(flux, ivar, 'badmethod')
#
# Nothing
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pydl/pydlutils/mangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pydl/pydlutils/tests/test_bspline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pydl/pydlutils/tests/test_cooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
3 changes: 1 addition & 2 deletions pydl/pydlutils/tests/test_coord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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

Expand Down
14 changes: 7 additions & 7 deletions pydl/pydlutils/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Loading

0 comments on commit 230d5b2

Please sign in to comment.