Skip to content

use pytest instead of nose for automated tests #204

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

Merged
merged 13 commits into from
Jul 5, 2016
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ before_install:
- conda config --set always_yes yes --set changeps1 no
- conda update -q conda
- conda info -a

install:
- echo "install"
- conda env create --file ci/requirements-$CONDA_ENV.yml
Expand All @@ -51,10 +51,10 @@ install:
- ls -l /home/travis/miniconda/envs/test_env/lib
#- pip install . # use pip to automatically install anything not in the yml files (i.e. numpy/scipy/pandas for py3*)
#- pip install scipy # won't do anything if already installed
- python setup.py install
- pip install -e .

script:
- nosetests -v --with-coverage --cover-package=pvlib pvlib
- py.test pvlib --cov=pvlib --cov-report term-missing

after_success:
coveralls
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ install:
build: false

test_script:
- "nosetests -v pvlib"
- "py.test -v pvlib"
8 changes: 5 additions & 3 deletions ci/requirements-py27-min.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: test_env
dependencies:
- python=2.7
- python=2.7
- numpy==1.8.2
- pandas==0.13.1
- nose
- pytz
- pytest
- pytest-cov
- nose
- pip:
- coveralls
- coveralls
8 changes: 5 additions & 3 deletions ci/requirements-py27.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
name: test_env
dependencies:
- python=2.7
- python=2.7
- numpy
- scipy
- pandas
- nose
- pytz
- ephem
- numba
- pytest
- pytest-cov
- nose
- pip:
- coveralls
- coveralls
6 changes: 4 additions & 2 deletions ci/requirements-py34.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ dependencies:
- numpy
- scipy
- pandas
- nose
- pytz
- ephem
- numba
- pytest
- pytest-cov
- nose
- pip:
- coveralls
- coveralls
6 changes: 4 additions & 2 deletions ci/requirements-py35.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ dependencies:
- numpy
- scipy
- pandas
- nose
- pytz
- ephem
- numba
- pytest
- pytest-cov
- nose
- pip:
- coveralls
- coveralls
1 change: 1 addition & 0 deletions docs/sphinx/source/whatsnew/v0.4.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Documentation
Other
~~~~~

* Switch to the py.test testing framework. (:issue:`204`)


Code Contributors
Expand Down
82 changes: 0 additions & 82 deletions pvlib/test/__init__.py

This file was deleted.

64 changes: 64 additions & 0 deletions pvlib/test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import sys
import platform

import pandas as pd
import numpy as np
import pytest


try:
import scipy
has_scipy = True
except ImportError:
has_scipy = False

requires_scipy = pytest.mark.skipif(not has_scipy, reason='requires scipy')


try:
import ephem
has_ephem = True
except ImportError:
has_ephem = False

requires_ephem = pytest.mark.skipif(not has_ephem, reason='requires ephem')


incompatible_pandas_0131 = pytest.mark.skipif(
pd.__version__ == '0.13.1', reason='requires numpy 1.10 or greater')


def numpy_1_10():
version = tuple(map(int, np.__version__.split('.')))
if version[0] <= 1 and version[1] < 10:
return False
else:
return True

needs_numpy_1_10 = pytest.mark.skipif(
not numpy_1_10(), reason='requires numpy 1.10 or greater')


def has_spa_c():
try:
from pvlib.spa_c_files.spa_py import spa_calc
except ImportError:
return False
else:
return True

requires_spa_c = pytest.mark.skipif(not has_spa_c(), reason="requires spa_c")

def has_numba():
try:
import numba
except ImportError:
return True
else:
vers = numba.__version__.split('.')
if int(vers[0] + vers[1]) < 17:
return False
else:
return True

requires_numba = pytest.mark.skipif(not has_numba(), reason="requires numba")
60 changes: 25 additions & 35 deletions pvlib/test/test_atmosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import numpy as np
import pandas as pd

from nose.tools import raises
from nose.tools import assert_almost_equals
import pytest
from numpy.testing import assert_allclose

from pvlib.location import Location
Expand All @@ -30,25 +29,21 @@
def test_pres2alt():
atmosphere.pres2alt(100000)


def test_alt2press():
atmosphere.pres2alt(1000)


# two functions combined will generate unique unit tests for each model
def test_airmasses():
models = ['simple', 'kasten1966', 'youngirvine1967', 'kastenyoung1989',
'gueymard1993', 'young1994', 'pickering2002']
for model in models:
yield run_airmass, model, ephem_data['zenith']


def run_airmass(model, zenith):
atmosphere.relativeairmass(zenith, model)
@pytest.mark.parametrize("model",
['simple', 'kasten1966', 'youngirvine1967', 'kastenyoung1989',
'gueymard1993', 'young1994', 'pickering2002'])
def test_airmass(model):
atmosphere.relativeairmass(ephem_data['zenith'], model)


@raises(ValueError)
def test_airmass_invalid():
atmosphere.relativeairmass(ephem_data['zenith'], 'invalid')
with pytest.raises(ValueError):
atmosphere.relativeairmass(ephem_data['zenith'], 'invalid')


def test_absoluteairmass():
Expand Down Expand Up @@ -79,31 +74,26 @@ def test_gueymard94_pw():
assert_allclose(pws, expected, atol=0.01)


def test_first_solar_spectral_correction():
ams = np.array([1, 3, 5])
pws = np.array([1, 3, 5])
ams, pws = np.meshgrid(ams, pws)

expect = {}
expect['cdte'] = np.array(
@pytest.mark.parametrize("module_type,expect", [
('cdte', np.array(
[[ 0.99134828, 0.97701063, 0.93975103],
[ 1.02852847, 1.01874908, 0.98604776],
[ 1.04722476, 1.03835703, 1.00656735]])
expect['monosi'] = np.array(
[ 1.04722476, 1.03835703, 1.00656735]])),
('monosi', np.array(
[[ 0.9782842 , 1.02092726, 1.03602157],
[ 0.9859024 , 1.0302268 , 1.04700244],
[ 0.98885429, 1.03351495, 1.05062687]])
expect['polysi'] = np.array(
[ 0.98885429, 1.03351495, 1.05062687]])),
('polysi', np.array(
[[ 0.9774921 , 1.01757872, 1.02649543],
[ 0.98947361, 1.0314545 , 1.04226547],
[ 0.99403107, 1.03639082, 1.04758064]])

def run_fs_test(module_type):
out = atmosphere.first_solar_spectral_correction(pws, ams, module_type)
assert_allclose(out, expect[module_type], atol=0.001)

for module_type in expect.keys():
yield run_fs_test, module_type
[ 0.99403107, 1.03639082, 1.04758064]]))
])
def test_first_solar_spectral_correction(module_type, expect):
ams = np.array([1, 3, 5])
pws = np.array([1, 3, 5])
ams, pws = np.meshgrid(ams, pws)
out = atmosphere.first_solar_spectral_correction(pws, ams, module_type)
assert_allclose(out, expect, atol=0.001)


def test_first_solar_spectral_correction_supplied():
Expand All @@ -114,6 +104,6 @@ def test_first_solar_spectral_correction_supplied():
assert_allclose(out, expected, atol=1e-3)


@raises(TypeError)
def test_first_solar_spectral_correction_ambiguous():
atmosphere.first_solar_spectral_correction(1, 1)
with pytest.raises(TypeError):
atmosphere.first_solar_spectral_correction(1, 1)
13 changes: 5 additions & 8 deletions pvlib/test/test_clearsky.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import logging
pvl_logger = logging.getLogger('pvlib')

from collections import OrderedDict

import numpy as np
import pandas as pd

from nose.tools import raises
import pytest
from numpy.testing import assert_almost_equal, assert_allclose
from pandas.util.testing import assert_frame_equal, assert_series_equal

from pvlib.location import Location
from pvlib import clearsky
from pvlib import solarposition

from . import requires_scipy
from conftest import requires_scipy

# setup times and location to be tested.
tus = Location(32.2, -111, 'US/Arizona', 700)
Expand Down Expand Up @@ -263,7 +260,7 @@ def test_simplified_solis_small_scalar_pw():

out = clearsky.simplified_solis(80, precipitable_water=0.1)
for k, v in expected.items():
yield assert_allclose, expected[k], out[k]
assert_allclose(expected[k], out[k])


def test_simplified_solis_return_arrays():
Expand All @@ -286,7 +283,7 @@ def test_simplified_solis_return_arrays():
out = clearsky.simplified_solis(80, aod700, precipitable_water)

for k, v in expected.items():
yield assert_allclose, expected[k], out[k]
assert_allclose(expected[k], out[k])


def test_simplified_solis_nans_arrays():
Expand Down Expand Up @@ -324,7 +321,7 @@ def test_simplified_solis_nans_arrays():
precipitable_water, pressure, dni_extra)

for k, v in expected.items():
yield assert_allclose, expected[k], out[k]
assert_allclose(expected[k], out[k])


def test_simplified_solis_nans_series():
Expand Down
Loading