Skip to content

Commit

Permalink
Merge pull request #2 from bmorris3/tests
Browse files Browse the repository at this point in the history
Tests
  • Loading branch information
Brett M. Morris committed Oct 28, 2017
2 parents 4a625ba + e9d185d commit 513b843
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 126 deletions.
50 changes: 6 additions & 44 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,12 @@ env:
- NUMPY_VERSION=stable
- ASTROPY_VERSION=stable
- MAIN_CMD='python setup.py'
- SETUP_CMD='test'
- PIP_DEPENDENCIES=''
- SETUP_CMD='test -V'
- CONDA_CHANNELS='astropy astropy-ci-extras conda-forge'
- CONDA_DEPENDENCIES='specutils astroquery matplotlib scipy'
- EVENT_TYPE='pull_request push'
- ASTROPY_USE_SYSTEM_PYTEST=1


# For this package-template, we include examples of Cython modules,
# so Cython is required for testing. If your package does not include
# Cython code, you can set CONDA_DEPENDENCIES=''
- CONDA_DEPENDENCIES='Cython'

# List other runtime dependencies for the package that are available as
# pip packages here.
# - PIP_DEPENDENCIES=''

# Conda packages for affiliated packages are hosted in channel
# "astropy" while builds for astropy LTS with recent numpy versions
# are in astropy-ci-extras. If your package uses either of these,
# add the channels to CONDA_CHANNELS along with any other channels
# you want to use.
- CONDA_CHANNELS='astropy-ci-extras astropy'

# If there are matplotlib or other GUI tests, uncomment the following
# line to use the X virtual framebuffer.
# - SETUP_XVFB=True

matrix:
# Make sure that egg_info works without dependencies
Expand All @@ -71,10 +53,6 @@ matrix:
- os: osx
env: SETUP_CMD='test'

# Do a coverage test.
- os: linux
env: SETUP_CMD='test --coverage'

# Check for sphinx doc build warnings - we do this first because it
# may run for a long time
- os: linux
Expand All @@ -84,34 +62,18 @@ matrix:
- os: linux
env: ASTROPY_VERSION=development
EVENT_TYPE='pull_request push cron'

- os: linux
env: PYTHON_VERSION=2.7 ASTROPY_VERSION=lts
- os: linux
env: ASTROPY_VERSION=lts

# Try all python versions and Numpy versions. Since we can assume that
# the Numpy developers have taken care of testing Numpy with different
# versions of Python, we can vary Python and Numpy versions at the same
# time.

- os: linux
env: PYTHON_VERSION=2.7 NUMPY_VERSION=1.9
- os: linux
env: PYTHON_VERSION=3.4 NUMPY_VERSION=1.10
- os: linux
env: PYTHON_VERSION=3.5 NUMPY_VERSION=1.11
- os: linux
env: NUMPY_VERSION=1.12
env: ASTROPY_VERSION=lts

# Try numpy pre-release
- os: linux
env: NUMPY_VERSION=prerelease
EVENT_TYPE='pull_request push cron'

# Do a PEP8 test with pycodestyle
- os: linux
env: MAIN_CMD='pycodestyle aesop --count' SETUP_CMD=''

allow_failures:
# Do a PEP8 test with pycodestyle
# (allow to fail unless your code completely compliant)
Expand Down
97 changes: 53 additions & 44 deletions aesop/conftest.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,55 @@
# this contains imports plugins that configure py.test for astropy tests.
# by importing them here in conftest.py they are discoverable by py.test
# no matter how it is invoked within the source tree.

from astropy.tests.pytest_plugins import *

## Uncomment the following line 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']}
# enable_deprecations_as_exceptions()

## Uncomment and customize the following lines to add/remove entries from
## the list of packages for which version numbers are displayed when running
## the tests. Making it pass for KeyError is essential in some cases when
## the package uses other astropy affiliated packages.
# try:
# PYTEST_HEADER_MODULES['Astropy'] = 'astropy'
# PYTEST_HEADER_MODULES['scikit-image'] = 'skimage'
# del PYTEST_HEADER_MODULES['h5py']
# except (NameError, KeyError): # NameError is needed to support Astropy < 1.0
# pass

## Uncomment the following lines to display the version number of the
## package rather than the version number of Astropy in the top line when
## running the tests.
# import os
#
## This is to figure out the package version, rather than
## using Astropy's
# try:
# from .version import version
# except ImportError:
# version = 'dev'
#
# try:
# packagename = os.path.basename(os.path.dirname(__file__))
# TESTED_VERSIONS[packagename] = version
# except NameError: # Needed to support Astropy <= 1.0.0
# pass
# also save a copy of the astropy hooks so we can use them below when
# overriding
from astropy.tests import pytest_plugins as astropy_pytest_plugins

import warnings

import os

# This is to figure out the affiliated package version, rather than
# using Astropy's
try:
from .version import version
except ImportError:
version = 'dev'

packagename = os.path.basename(os.path.dirname(__file__))
TESTED_VERSIONS[packagename] = version


# Comment out this line to avoid deprecation warnings being raised as
# exceptions
enable_deprecations_as_exceptions()

# Define list of packages for which to display version numbers in the test log
try:
PYTEST_HEADER_MODULES['Astropy'] = 'astropy'
del PYTEST_HEADER_MODULES['h5py']
except KeyError:
pass


def pytest_configure(config):
if hasattr(astropy_pytest_plugins, 'pytest_configure'):
# sure ought to be true right now, but always possible it will change in
# future versions of astropy
astropy_pytest_plugins.pytest_configure(config)

# activate image comparison tests only if the dependencies needed are installed:
# matplotlib, nose, pytest-mpl
try:
import matplotlib
import nose # needed for the matplotlib testing tools
HAS_MATPLOTLIB_AND_NOSE = True
except ImportError:
HAS_MATPLOTLIB_AND_NOSE = False

if HAS_MATPLOTLIB_AND_NOSE and config.pluginmanager.hasplugin('mpl'):
pass
# TODO: turn image comparison tests back on once this issue is figured out:
# https://github.com/astropy/astroplan/pull/104#issuecomment-137734007
# config.option.mpl = True
# config.option.mpl_baseline_path = 'astroplan/plots/tests/baseline_images'

5 changes: 5 additions & 0 deletions aesop/setup_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def get_package_data():
"""Declare aesop datafiles"""
pdata = dict()
pdata['aesop.tests'] = ['coveragerc']
return pdata
4 changes: 2 additions & 2 deletions aesop/spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ def get_order(self, order):
"""
Get the spectrum from a specific spectral order
Parameter
---------
Parameters
----------
order : int
Echelle order to return
Expand Down
4 changes: 0 additions & 4 deletions aesop/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""
This module contains package tests.
"""
11 changes: 0 additions & 11 deletions aesop/tests/setup_package.py

This file was deleted.

25 changes: 25 additions & 0 deletions aesop/tests/test_spectrum1d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)


import numpy as np
import astropy.units as u
import pytest
from astropy.units import UnitsError

from ..spectra import Spectrum1D


def test_constructor():
wl = np.linspace(3000, 4000) * u.Angstrom
f = 1 + 0.1 * np.random.randn()
example = Spectrum1D(wavelength=wl, flux=f)

# raise an error if there is no unit on the wavelength
with pytest.raises(TypeError):
example = Spectrum1D(wavelength=[0, 1, 2, 3], flux=f)

# raise an error if the wavelength unit is not a unit of length
with pytest.raises(UnitsError):
example = Spectrum1D(wavelength=u.Quantity([0, 1, 2, 3], unit=u.day),
flux=f)
9 changes: 0 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,3 @@

# -- Resolving issue number to links in changelog -----------------------------
github_issues_url = 'https://github.com/{0}/issues/'.format(setup_cfg['github_project'])


# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping['astropy'] = ('http://astropy.readthedocs.io/en/latest/', None)
intersphinx_mapping['astroquery'] = ('http://astroquery.readthedocs.io/en/latest/', None)
intersphinx_mapping['matplotlib'] = ('https://matplotlib.org/contents.html', None)
intersphinx_mapping['numpy'] = ('https://docs.scipy.org/doc/numpy/', None)
intersphinx_mapping['specutils'] = ('http://specutils.readthedocs.io/en/latest/', None)
7 changes: 5 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

.. _aesop:

.. include:: references.txt

Welcome to the aesop documentation!
===================================
*****
aesop
*****

``aesop`` is a data reduction toolkit for spectra from the Astrophysical
Research Consortium (ARC) 3.5 m Telescope at Apache Point Observatory (APO).
Expand Down
15 changes: 7 additions & 8 deletions docs/install.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.. include:: references.txt

.. _install:

.. include:: references.txt

****************
Installing aesop
================
****************

Clone the ``aesop`` repository from GitHub, and go into the top-level ``aesop``
directory::
Expand All @@ -16,9 +17,7 @@ Install ``aesop`` with::
python setup.py install

You can ensure that the package was installed successfully by running the tests
from a Python interpreter with the following commands:

.. code-block:: python
from a Python interpreter with the following commands::

>>> import aesop
>>> aesop.test()
import aesop
aesop.test()
1 change: 1 addition & 0 deletions docs/rtd-pip-requirements
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ astropy >= 1.3
sphinx-automodapi
scipy
astroquery
specutils
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ url = https://github.com/bmorris3/aesop
edit_on_github = True
github_project = bmorris3/aesop
# install_requires should be formatted as a comma-separated list, e.g.:
# install_requires = astropy, scipy, matplotlib
install_requires = astropy
install_requires = astropy, scipy, matplotlib, specutils, astroquery, numpy
# version should be PEP386 compatible (http://www.python.org/dev/peps/pep-0386)
version = 0.0.dev0

Expand Down

0 comments on commit 513b843

Please sign in to comment.