Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tox with C-extension #310

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ testpaths = "synphot" "docs"
norecursedirs = build docs/_build synphot/src
astropy_header = true
doctest_plus = enabled
doctest_rst = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, why this addition, is addopts = --doctest-rst not enough?

text_file_format = rst
addopts = --doctest-rst --doctest-ignore-import-errors
addopts = --import-mode append
xfail_strict = true
filterwarnings =
ignore:can't resolve package from __spec__
Expand Down
9 changes: 5 additions & 4 deletions synphot/tests/test_binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from astropy.utils.data import get_pkg_data_filename

# LOCAL
from .. import binning, exceptions, specio
from ..utils import merge_wavelengths, generate_wavelengths
from synphot import binning, exceptions, specio
from synphot.utils import merge_wavelengths, generate_wavelengths


@pytest.mark.parametrize(
Expand Down Expand Up @@ -196,7 +196,8 @@ def setup_class(self):
# Get bandpass data for interpolation.
hdr, wave, thru = specio.read_fits_spec(
get_pkg_data_filename(
os.path.join('data', 'hst_acs_hrc_f555w.fits')),
os.path.join('data', 'hst_acs_hrc_f555w.fits'),
package='synphot.tests'),
flux_col='THROUGHPUT', flux_unit=u.dimensionless_unscaled)

# Binned data.
Expand Down Expand Up @@ -232,7 +233,7 @@ def setup_class(self):

def test_c_ext(self):
# C-EXT: Sum over each bin.
from .. import synphot_utils
from synphot import synphot_utils

binflux_c, intwave_c = synphot_utils.calcbinflux(
self.size, self.i_beg, self.i_end, self.avflux, self.deltaw)
Expand Down
4 changes: 2 additions & 2 deletions synphot/tests/test_blackbody.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from astropy import constants as const
from astropy import units as u

from ..blackbody import blackbody_nu
from ..units import FNU
from synphot.blackbody import blackbody_nu
from synphot.units import FNU


# This test was removed from astropy in
Expand Down
6 changes: 3 additions & 3 deletions synphot/tests/test_integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from numpy.testing import assert_allclose

# LOCAL
from .. import models, units
from ..exceptions import SynphotError
from ..spectrum import SourceSpectrum, SpectralElement
from synphot import models, units
from synphot.exceptions import SynphotError
from synphot.spectrum import SourceSpectrum, SpectralElement


class TestSourceConstFlux1D:
Expand Down
9 changes: 5 additions & 4 deletions synphot/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
from astropy.utils.exceptions import AstropyUserWarning

# LOCAL
from .. import specio, units
from ..models import (BlackBody1D, ConstFlux1D, Empirical1D, PowerLawFlux1D,
get_metadata)
from synphot import specio, units
from synphot.models import (BlackBody1D, ConstFlux1D, Empirical1D,
PowerLawFlux1D, get_metadata)


def setup_module(module):
Expand Down Expand Up @@ -123,7 +123,8 @@ class TestEmpirical1D:
"""Test Empirical1D model."""
def setup_class(self):
filename = get_pkg_data_filename(
os.path.join('data', 'hst_acs_hrc_f555w_x_grw70d5824.fits'))
os.path.join('data', 'hst_acs_hrc_f555w_x_grw70d5824.fits'),
package='synphot.tests')
hdr, x, f = specio.read_spec(filename)
y = units.convert_flux(x, f, units.PHOTLAM)
self.flux_flam = f.value
Expand Down
39 changes: 25 additions & 14 deletions synphot/tests/test_observation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@
AstropyUserWarning)

# LOCAL
from .test_units import _area
from .. import exceptions, units
from ..compat import HAS_SPECUTILS # noqa
from ..models import (BlackBodyNorm1D, Box1D, ConstFlux1D, Empirical1D,
GaussianFlux1D)
from ..observation import Observation
from ..spectrum import SourceSpectrum, SpectralElement
from synphot.tests.test_units import _area
from synphot import exceptions, units
from synphot.compat import HAS_SPECUTILS # noqa
from synphot.models import (
BlackBodyNorm1D, Box1D, ConstFlux1D, Empirical1D, GaussianFlux1D
)
from synphot.observation import Observation
from synphot.spectrum import SourceSpectrum, SpectralElement

# Global test data files
_specfile = get_pkg_data_filename(
os.path.join('data', 'grw_70d5824_stisnic_005.fits'))
os.path.join('data', 'grw_70d5824_stisnic_005.fits'),
package='synphot.tests'
)
_bandfile = get_pkg_data_filename(
os.path.join('data', 'hst_acs_hrc_f555w.fits'))
os.path.join('data', 'hst_acs_hrc_f555w.fits'),
package='synphot.tests'
)


class TestObservation:
Expand Down Expand Up @@ -412,8 +417,11 @@ class TestCountRateNegFlux:
"""Test countrate with files containing negative flux/throughput values."""
def setup_class(self):
self.bp = SpectralElement.from_file(get_pkg_data_filename(
os.path.join('data', 'cos_fuv_g130m_c1309_psa.fits')))
self.spfile = get_pkg_data_filename(os.path.join('data', 'us7.txt'))
os.path.join('data', 'cos_fuv_g130m_c1309_psa.fits'),
package='synphot.tests'))
self.spfile = get_pkg_data_filename(
os.path.join('data', 'us7.txt'), package='synphot.tests'
)

@pytest.mark.parametrize(
('keep_neg', 'ans'),
Expand All @@ -439,11 +447,14 @@ def test_countrate_neg_leak():
"""
# This bug only manifests itself in very specific cases.
bp = SpectralElement.from_file(get_pkg_data_filename(
os.path.join('data', 'stis_fuv_f25ndq2_mjd58300_0822774.fits')))
os.path.join('data', 'stis_fuv_f25ndq2_mjd58300_0822774.fits'),
package='synphot.tests'))
sp = SourceSpectrum.from_file(get_pkg_data_filename(
os.path.join('data', 'k93_4500_0_5_rn_box.fits')))
os.path.join('data', 'k93_4500_0_5_rn_box.fits'),
package='synphot.tests'))
binset = np.fromfile(get_pkg_data_filename(
os.path.join('data', 'stis_fuv_f25ndq2_binset.bin')))
os.path.join('data', 'stis_fuv_f25ndq2_binset.bin'),
package='synphot.tests'))
obs = Observation(sp, bp, binset=binset)
area = 45238.93416 # HST cm^2
wrange = [1109.22, 12000.0] # Angstrom
Expand Down
21 changes: 12 additions & 9 deletions synphot/tests/test_reddening.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
from astropy.utils.exceptions import AstropyUserWarning

# LOCAL
from .. import exceptions, units
from ..compat import HAS_DUST_EXTINCTION # noqa
from ..models import ConstFlux1D, Empirical1D
from ..observation import Observation
from ..reddening import ReddeningLaw, etau_madau
from ..spectrum import SourceSpectrum, SpectralElement
from synphot import exceptions, units
from synphot.compat import HAS_DUST_EXTINCTION # noqa
from synphot.models import ConstFlux1D, Empirical1D
from synphot.observation import Observation
from synphot.reddening import ReddeningLaw, etau_madau
from synphot.spectrum import SourceSpectrum, SpectralElement


class TestExtinction:
"""Test ReddeningLaw and ExtinctionCurve classes (most methods)."""
def setup_class(self):
rfile = get_pkg_data_filename(
os.path.join('data', 'milkyway_diffuse_001.fits'))
os.path.join('data', 'milkyway_diffuse_001.fits'),
package='synphot.tests')
self.redlaw = ReddeningLaw.from_file(rfile)
self.extcurve = self.redlaw.extinction_curve(0.3 * u.mag)

Expand Down Expand Up @@ -90,9 +91,11 @@ def test_qso_countrate(self):
https://github.com/spacetelescope/synphot_refactor/issues/129
"""
bp = SpectralElement.from_file(get_pkg_data_filename(
os.path.join('data', 'hst_acs_hrc_f850lp.fits')))
os.path.join('data', 'hst_acs_hrc_f850lp.fits'),
package='synphot.tests'))
qso = SourceSpectrum.from_file(get_pkg_data_filename(
os.path.join('data', 'qso_template_001.dat')))
os.path.join('data', 'qso_template_001.dat'),
package='synphot.tests'))
extcurve = self.redlaw.extinction_curve(1.0 * u.mag)
spext = qso * extcurve
with pytest.warns(AstropyUserWarning):
Expand Down
6 changes: 3 additions & 3 deletions synphot/tests/test_specio.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from astropy.utils.exceptions import AstropyUserWarning

# LOCAL
from .. import exceptions, specio, units
from synphot import exceptions, specio, units


@pytest.mark.remote_data
Expand All @@ -28,7 +28,7 @@ def test_read_remote_spec():
.. note:: This is just I/O test. No check on data quality.

"""
from .. import config
from synphot import config

hdr, wave, flux = specio.read_remote_spec(
config.conf.vega_file, cache=False, show_progress=False)
Expand All @@ -41,7 +41,7 @@ def test_read_remote_spec():
def test_read_ascii_spec():
"""Test read local ASCII spectrum."""
specfile = get_pkg_data_filename(
os.path.join('data', 'qso_template_001.dat'))
os.path.join('data', 'qso_template_001.dat'), package='synphot.tests')
hdr, wave, flux = specio.read_spec(specfile)

assert_quantity_allclose(wave[::500], [800, 2050, 3300, 4550, 5800] * u.AA)
Expand Down
13 changes: 7 additions & 6 deletions synphot/tests/test_spectrum_bandpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
from astropy.utils.exceptions import AstropyUserWarning

# LOCAL
from .test_units import _area, _wave, _flux_photlam
from .. import exceptions, units
from ..compat import HAS_SPECUTILS # noqa
from ..models import Box1D, Empirical1D, GaussianAbsorption1D
from ..spectrum import SpectralElement
from synphot.tests.test_units import _area, _wave, _flux_photlam
from synphot import exceptions, units
from synphot.compat import HAS_SPECUTILS # noqa
from synphot.models import Box1D, Empirical1D, GaussianAbsorption1D
from synphot.spectrum import SpectralElement


@pytest.mark.remote_data
Expand Down Expand Up @@ -52,7 +52,8 @@ class TestEmpiricalBandpassFromFile:
"""This is the most common model used in ASTROLIB PYSYNPHOT."""
def setup_class(self):
bandfile = get_pkg_data_filename(
os.path.join('data', 'hst_acs_hrc_f555w.fits'))
os.path.join('data', 'hst_acs_hrc_f555w.fits'),
package='synphot.tests')
self.bp = SpectralElement.from_file(bandfile)

def test_invalid_flux_unit(self):
Expand Down
10 changes: 5 additions & 5 deletions synphot/tests/test_spectrum_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
from astropy.tests.helper import assert_quantity_allclose

# LOCAL
from .test_units import _wave, _flux_jy, _flux_photlam
from .. import exceptions, units
from ..compat import ASTROPY_LT_4_0
from ..models import Box1D, Empirical1D, GaussianFlux1D, get_waveset
from ..spectrum import SourceSpectrum, SpectralElement
from synphot.tests.test_units import _wave, _flux_jy, _flux_photlam
from synphot import exceptions, units
from synphot.compat import ASTROPY_LT_4_0
from synphot.models import Box1D, Empirical1D, GaussianFlux1D, get_waveset
from synphot.spectrum import SourceSpectrum, SpectralElement


def setup_module(module):
Expand Down
22 changes: 13 additions & 9 deletions synphot/tests/test_spectrum_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@
from astropy.utils.exceptions import AstropyUserWarning

# LOCAL
from .test_units import _area, _wave, _flux_jy, _flux_photlam, _flux_vegamag
from .. import exceptions, units
from ..compat import ASTROPY_LT_4_0
from ..compat import HAS_SPECUTILS # noqa
from ..models import (
from synphot.tests.test_units import (
_area, _wave, _flux_jy, _flux_photlam, _flux_vegamag
)
from synphot import exceptions, units
from synphot.compat import ASTROPY_LT_4_0
from synphot.compat import HAS_SPECUTILS # noqa
from synphot.models import (
BlackBodyNorm1D, Box1D, ConstFlux1D, Empirical1D, Gaussian1D,
GaussianFlux1D, Lorentz1D, RickerWavelet1D, PowerLawFlux1D)
from ..observation import Observation
from ..spectrum import SourceSpectrum, SpectralElement
from synphot.observation import Observation
from synphot.spectrum import SourceSpectrum, SpectralElement

# GLOBAL VARIABLES
_vspec = None # Loaded in test_load_vspec()
Expand Down Expand Up @@ -92,7 +94,8 @@ class TestEmpiricalSourceFromFile:
"""This is the most common model used in ASTROLIB PYSYNPHOT."""
def setup_class(self):
specfile = get_pkg_data_filename(
os.path.join('data', 'hst_acs_hrc_f555w_x_grw70d5824.fits'))
os.path.join('data', 'hst_acs_hrc_f555w_x_grw70d5824.fits'),
package='synphot.tests')
self.sp = SourceSpectrum.from_file(specfile)

def test_invalid_flux_unit(self):
Expand Down Expand Up @@ -394,7 +397,8 @@ def setup_class(self):

# ACS bandpass: band(acs,hrc,f555w)
bandfile = get_pkg_data_filename(
os.path.join('data', 'hst_acs_hrc_f555w.fits'))
os.path.join('data', 'hst_acs_hrc_f555w.fits'),
package='synphot.tests')
self.acs = SpectralElement.from_file(bandfile)

# Box bandpass: box(5500,1)
Expand Down
10 changes: 6 additions & 4 deletions synphot/tests/test_thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from astropy.utils.data import get_pkg_data_filename

# LOCAL
from .. import exceptions
from ..thermal import ThermalSpectralElement
from synphot import exceptions
from synphot.thermal import ThermalSpectralElement


def setup_module(module):
Expand All @@ -39,7 +39,8 @@ class TestThermalSpectralElement:
"""Test ``ThermalSpectralElement``."""
def setup_class(self):
thfile = get_pkg_data_filename(
os.path.join('data', 'wfc3_ir_g141_src_003_th.fits'))
os.path.join('data', 'wfc3_ir_g141_src_003_th.fits'),
package='synphot.tests')
self.th = ThermalSpectralElement.from_file(thfile)

def test_taper(self):
Expand All @@ -66,6 +67,7 @@ def test_from_file_exceptions(self):

# Missing DEFT keyword
thfile = get_pkg_data_filename(
os.path.join('data', 'hst_acs_hrc_f555w.fits'))
os.path.join('data', 'hst_acs_hrc_f555w.fits'),
package='synphot.tests')
with pytest.raises(exceptions.SynphotError):
ThermalSpectralElement.from_file(thfile, flux_col='THROUGHPUT')
2 changes: 1 addition & 1 deletion synphot/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from astropy import units as u

# LOCAL
from .. import exceptions, units
from synphot import exceptions, units

# Wavelength conversions
_wave_angstrom = [0.1, 5000.0, 10000.0] * u.AA
Expand Down
4 changes: 2 additions & 2 deletions synphot/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from astropy import units as u

# LOCAL
from .. import exceptions, utils, units
from synphot import exceptions, utils, units


@pytest.mark.parametrize(
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_download_bad_root(tmpdir):

def test_download_data(tmpdir):
"""Test data download helper in dry run mode."""
from ..config import conf
from synphot.config import conf

# Use case where user downloads all data into new dir.
cdbs_root = os.path.join(tmpdir.strpath, 'cdbs')
Expand Down
14 changes: 6 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ isolated_build = true
# Pass through the following environemnt variables which are needed for the CI
passenv = HOME WINDIR CC CI

# FIXME: Cannot do this, need to force C-ext to build below.
# Run the tests in a temporary directory to make sure that we don't import
# package from the source tree
#changedir = .tmp/{envname}
changedir = .tmp/{envname}

# tox environments are constructued with so-called 'factors' (or terms)
# separated by hyphens, e.g. test-devdeps-cov. Lines below starting with factor:
Expand Down Expand Up @@ -53,13 +52,12 @@ extras =
alldeps: all

commands =
# FIXME: Not sure why need this for tox to see the C-ext
python setup.py build_ext --inplace
# End of FIXME
pip freeze
!cov: pytest --pyargs synphot {toxinidir}/docs {posargs}
cov: pytest --pyargs synphot {toxinidir}/docs --cov synphot --cov-config={toxinidir}/setup.cfg {posargs}
cov: coverage xml -o {toxinidir}/coverage.xml
# FIXME: Seems like using -c option with multiline Pytest is broken: see
# https://github.com/tox-dev/tox-travis/issues/146
# at the very least on CI - it runs fine locally on MacOSX.
!cov: pytest -c {toxinidir}/setup.cfg --pyargs synphot --rootdir={toxinidir} {posargs}
cov: pytest -c {toxinidir}/setup.cfg --pyargs synphot --rootdir={toxinidir} {posargs} --cov={envsitepackagesdir}/synphot --cov-config={toxinidir}/setup.cfg --cov-report xml:{toxinidir}/coverage.xml

[testenv:codestyle]
skip_install = true
Expand Down