Skip to content

Commit 55954bd

Browse files
authored
use pytest instead of nose for automated tests (#204)
* remove module from singlediode * remove unused partial * use pytest in solarposition and pvsystem * remove all nose imports and make tests pass * add nose to envs for pandas * add requires_numba decorator * add pytest-runner to setup * use pytest on appveyor * update whatsnew * clean up rebase mistake * replace xfails with pytest.raises * remove init in favor of conftest.py * switch to pip install
1 parent a6ecb75 commit 55954bd

20 files changed

+456
-536
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ before_install:
4141
- conda config --set always_yes yes --set changeps1 no
4242
- conda update -q conda
4343
- conda info -a
44-
44+
4545
install:
4646
- echo "install"
4747
- conda env create --file ci/requirements-$CONDA_ENV.yml
@@ -51,10 +51,10 @@ install:
5151
- ls -l /home/travis/miniconda/envs/test_env/lib
5252
#- pip install . # use pip to automatically install anything not in the yml files (i.e. numpy/scipy/pandas for py3*)
5353
#- pip install scipy # won't do anything if already installed
54-
- python setup.py install
54+
- pip install -e .
5555

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

5959
after_success:
6060
coveralls

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ install:
3737
build: false
3838

3939
test_script:
40-
- "nosetests -v pvlib"
40+
- "py.test -v pvlib"

ci/requirements-py27-min.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
name: test_env
22
dependencies:
3-
- python=2.7
3+
- python=2.7
44
- numpy==1.8.2
55
- pandas==0.13.1
6-
- nose
76
- pytz
7+
- pytest
8+
- pytest-cov
9+
- nose
810
- pip:
9-
- coveralls
11+
- coveralls

ci/requirements-py27.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
name: test_env
22
dependencies:
3-
- python=2.7
3+
- python=2.7
44
- numpy
55
- scipy
66
- pandas
7-
- nose
87
- pytz
98
- ephem
109
- numba
10+
- pytest
11+
- pytest-cov
12+
- nose
1113
- pip:
12-
- coveralls
14+
- coveralls

ci/requirements-py34.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ dependencies:
44
- numpy
55
- scipy
66
- pandas
7-
- nose
87
- pytz
98
- ephem
109
- numba
10+
- pytest
11+
- pytest-cov
12+
- nose
1113
- pip:
12-
- coveralls
14+
- coveralls

ci/requirements-py35.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ dependencies:
44
- numpy
55
- scipy
66
- pandas
7-
- nose
87
- pytz
98
- ephem
109
- numba
10+
- pytest
11+
- pytest-cov
12+
- nose
1113
- pip:
12-
- coveralls
14+
- coveralls

docs/sphinx/source/whatsnew/v0.4.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Documentation
3838
Other
3939
~~~~~
4040

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

4243

4344
Code Contributors

pvlib/test/__init__.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

pvlib/test/conftest.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import sys
2+
import platform
3+
4+
import pandas as pd
5+
import numpy as np
6+
import pytest
7+
8+
9+
try:
10+
import scipy
11+
has_scipy = True
12+
except ImportError:
13+
has_scipy = False
14+
15+
requires_scipy = pytest.mark.skipif(not has_scipy, reason='requires scipy')
16+
17+
18+
try:
19+
import ephem
20+
has_ephem = True
21+
except ImportError:
22+
has_ephem = False
23+
24+
requires_ephem = pytest.mark.skipif(not has_ephem, reason='requires ephem')
25+
26+
27+
incompatible_pandas_0131 = pytest.mark.skipif(
28+
pd.__version__ == '0.13.1', reason='requires numpy 1.10 or greater')
29+
30+
31+
def numpy_1_10():
32+
version = tuple(map(int, np.__version__.split('.')))
33+
if version[0] <= 1 and version[1] < 10:
34+
return False
35+
else:
36+
return True
37+
38+
needs_numpy_1_10 = pytest.mark.skipif(
39+
not numpy_1_10(), reason='requires numpy 1.10 or greater')
40+
41+
42+
def has_spa_c():
43+
try:
44+
from pvlib.spa_c_files.spa_py import spa_calc
45+
except ImportError:
46+
return False
47+
else:
48+
return True
49+
50+
requires_spa_c = pytest.mark.skipif(not has_spa_c(), reason="requires spa_c")
51+
52+
def has_numba():
53+
try:
54+
import numba
55+
except ImportError:
56+
return True
57+
else:
58+
vers = numba.__version__.split('.')
59+
if int(vers[0] + vers[1]) < 17:
60+
return False
61+
else:
62+
return True
63+
64+
requires_numba = pytest.mark.skipif(not has_numba(), reason="requires numba")

pvlib/test/test_atmosphere.py

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import numpy as np
55
import pandas as pd
66

7-
from nose.tools import raises
8-
from nose.tools import assert_almost_equals
7+
import pytest
98
from numpy.testing import assert_allclose
109

1110
from pvlib.location import Location
@@ -30,25 +29,21 @@
3029
def test_pres2alt():
3130
atmosphere.pres2alt(100000)
3231

32+
3333
def test_alt2press():
3434
atmosphere.pres2alt(1000)
3535

3636

37-
# two functions combined will generate unique unit tests for each model
38-
def test_airmasses():
39-
models = ['simple', 'kasten1966', 'youngirvine1967', 'kastenyoung1989',
40-
'gueymard1993', 'young1994', 'pickering2002']
41-
for model in models:
42-
yield run_airmass, model, ephem_data['zenith']
43-
44-
45-
def run_airmass(model, zenith):
46-
atmosphere.relativeairmass(zenith, model)
37+
@pytest.mark.parametrize("model",
38+
['simple', 'kasten1966', 'youngirvine1967', 'kastenyoung1989',
39+
'gueymard1993', 'young1994', 'pickering2002'])
40+
def test_airmass(model):
41+
atmosphere.relativeairmass(ephem_data['zenith'], model)
4742

4843

49-
@raises(ValueError)
5044
def test_airmass_invalid():
51-
atmosphere.relativeairmass(ephem_data['zenith'], 'invalid')
45+
with pytest.raises(ValueError):
46+
atmosphere.relativeairmass(ephem_data['zenith'], 'invalid')
5247

5348

5449
def test_absoluteairmass():
@@ -79,31 +74,26 @@ def test_gueymard94_pw():
7974
assert_allclose(pws, expected, atol=0.01)
8075

8176

82-
def test_first_solar_spectral_correction():
83-
ams = np.array([1, 3, 5])
84-
pws = np.array([1, 3, 5])
85-
ams, pws = np.meshgrid(ams, pws)
86-
87-
expect = {}
88-
expect['cdte'] = np.array(
77+
@pytest.mark.parametrize("module_type,expect", [
78+
('cdte', np.array(
8979
[[ 0.99134828, 0.97701063, 0.93975103],
9080
[ 1.02852847, 1.01874908, 0.98604776],
91-
[ 1.04722476, 1.03835703, 1.00656735]])
92-
expect['monosi'] = np.array(
81+
[ 1.04722476, 1.03835703, 1.00656735]])),
82+
('monosi', np.array(
9383
[[ 0.9782842 , 1.02092726, 1.03602157],
9484
[ 0.9859024 , 1.0302268 , 1.04700244],
95-
[ 0.98885429, 1.03351495, 1.05062687]])
96-
expect['polysi'] = np.array(
85+
[ 0.98885429, 1.03351495, 1.05062687]])),
86+
('polysi', np.array(
9787
[[ 0.9774921 , 1.01757872, 1.02649543],
9888
[ 0.98947361, 1.0314545 , 1.04226547],
99-
[ 0.99403107, 1.03639082, 1.04758064]])
100-
101-
def run_fs_test(module_type):
102-
out = atmosphere.first_solar_spectral_correction(pws, ams, module_type)
103-
assert_allclose(out, expect[module_type], atol=0.001)
104-
105-
for module_type in expect.keys():
106-
yield run_fs_test, module_type
89+
[ 0.99403107, 1.03639082, 1.04758064]]))
90+
])
91+
def test_first_solar_spectral_correction(module_type, expect):
92+
ams = np.array([1, 3, 5])
93+
pws = np.array([1, 3, 5])
94+
ams, pws = np.meshgrid(ams, pws)
95+
out = atmosphere.first_solar_spectral_correction(pws, ams, module_type)
96+
assert_allclose(out, expect, atol=0.001)
10797

10898

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

116106

117-
@raises(TypeError)
118107
def test_first_solar_spectral_correction_ambiguous():
119-
atmosphere.first_solar_spectral_correction(1, 1)
108+
with pytest.raises(TypeError):
109+
atmosphere.first_solar_spectral_correction(1, 1)

pvlib/test/test_clearsky.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
import logging
2-
pvl_logger = logging.getLogger('pvlib')
3-
41
from collections import OrderedDict
52

63
import numpy as np
74
import pandas as pd
85

9-
from nose.tools import raises
6+
import pytest
107
from numpy.testing import assert_almost_equal, assert_allclose
118
from pandas.util.testing import assert_frame_equal, assert_series_equal
129

1310
from pvlib.location import Location
1411
from pvlib import clearsky
1512
from pvlib import solarposition
1613

17-
from . import requires_scipy
14+
from conftest import requires_scipy
1815

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

264261
out = clearsky.simplified_solis(80, precipitable_water=0.1)
265262
for k, v in expected.items():
266-
yield assert_allclose, expected[k], out[k]
263+
assert_allclose(expected[k], out[k])
267264

268265

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

288285
for k, v in expected.items():
289-
yield assert_allclose, expected[k], out[k]
286+
assert_allclose(expected[k], out[k])
290287

291288

292289
def test_simplified_solis_nans_arrays():
@@ -324,7 +321,7 @@ def test_simplified_solis_nans_arrays():
324321
precipitable_water, pressure, dni_extra)
325322

326323
for k, v in expected.items():
327-
yield assert_allclose, expected[k], out[k]
324+
assert_allclose(expected[k], out[k])
328325

329326

330327
def test_simplified_solis_nans_series():

0 commit comments

Comments
 (0)