Skip to content

Commit d68ee4c

Browse files
wholmgrencwhanse
authored andcommitted
test compat with pytest 4.0 (#624)
* test compat with pytest 4.0. minor clean up * fix timeout args
1 parent 673ab97 commit d68ee4c

File tree

7 files changed

+66
-60
lines changed

7 files changed

+66
-60
lines changed

docs/sphinx/source/whatsnew/v0.6.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Bug fixes
5555
Testing
5656
~~~~~~~
5757
* Add test for :func:`~pvlib.solarposition.hour_angle` (:issue:`597`)
58+
* Update tests to be compatible with pytest 4.0. (:issue:`623`)
5859

5960

6061
Contributors

pvlib/test/test_clearsky.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ def test_haurwitz():
279279
487.894132885425,
280280
778.766689344363,
281281
1035.09203253450]),
282-
columns=['ghi'],
283-
index=apparent_solar_zenith)
282+
columns=['ghi'],
283+
index=apparent_solar_zenith)
284284
out = clearsky.haurwitz(data_in['apparent_zenith'])
285285
assert_frame_equal(expected, out)
286286

@@ -293,7 +293,7 @@ def test_simplified_solis_scalar_elevation():
293293

294294
out = clearsky.simplified_solis(80)
295295
for k, v in expected.items():
296-
yield assert_allclose, expected[k], out[k]
296+
assert_allclose(expected[k], out[k])
297297

298298

299299
def test_simplified_solis_scalar_neg_elevation():
@@ -304,7 +304,7 @@ def test_simplified_solis_scalar_neg_elevation():
304304

305305
out = clearsky.simplified_solis(-10)
306306
for k, v in expected.items():
307-
yield assert_allclose, expected[k], out[k]
307+
assert_allclose(expected[k], out[k])
308308

309309

310310
def test_simplified_solis_series_elevation():

pvlib/test/test_forecast.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from datetime import datetime, timedelta
2-
import inspect
3-
from math import isnan
42
from pytz import timezone
53
import warnings
64

7-
import numpy as np
85
import pandas as pd
96

107
import pytest
@@ -14,13 +11,8 @@
1411

1512
pytestmark = pytest.mark.skipif(not has_siphon, reason='requires siphon')
1613

17-
from pvlib.location import Location
1814

1915
if has_siphon:
20-
import requests
21-
from requests.exceptions import HTTPError
22-
from xml.etree.ElementTree import ParseError
23-
2416
from pvlib.forecast import GFS, HRRR_ESRL, HRRR, NAM, NDFD, RAP
2517

2618
# setup times and location to be tested. Tucson, AZ
@@ -31,15 +23,16 @@
3123
_end = _start + pd.Timedelta(days=1)
3224
_modelclasses = [
3325
GFS, NAM, HRRR, NDFD, RAP,
34-
skip_windows(
35-
pytest.mark.xfail(
36-
pytest.mark.timeout(HRRR_ESRL, timeout=60),
37-
reason="HRRR_ESRL is unreliable"))]
26+
pytest.param(
27+
HRRR_ESRL, marks=[
28+
skip_windows,
29+
pytest.mark.xfail(reason="HRRR_ESRL is unreliable"),
30+
pytest.mark.timeout(timeout=60)])]
3831
_working_models = []
3932
_variables = ['temp_air', 'wind_speed', 'total_clouds', 'low_clouds',
40-
'mid_clouds', 'high_clouds', 'dni', 'dhi', 'ghi',]
33+
'mid_clouds', 'high_clouds', 'dni', 'dhi', 'ghi']
4134
_nonnan_variables = ['temp_air', 'wind_speed', 'total_clouds', 'dni',
42-
'dhi', 'ghi',]
35+
'dhi', 'ghi']
4336
else:
4437
_modelclasses = []
4538

pvlib/test/test_irradiance.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010

1111
from pandas.util.testing import assert_frame_equal, assert_series_equal
1212

13-
from pvlib import atmosphere, irradiance, solarposition
13+
from pvlib import irradiance
1414
from pvlib._deprecation import pvlibDeprecationWarning
15-
from pvlib.location import Location
1615

1716
from conftest import (fail_on_pvlib_version, needs_numpy_1_10, pandas_0_22,
1817
requires_ephem, requires_numba)
@@ -102,7 +101,7 @@ def test_deprecated_07():
102101
(timestamp, value)
103102
])
104103
@pytest.mark.parametrize('method', [
105-
'asce', 'spencer', 'nrel', requires_ephem('pyephem')])
104+
'asce', 'spencer', 'nrel', pytest.param('pyephem', marks=requires_ephem)])
106105
def test_get_extra_radiation(input, expected, method):
107106
out = irradiance.get_extra_radiation(input)
108107
assert_allclose(out, expected, atol=1)

pvlib/test/test_modelchain.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ def cec_dc_snl_ac_system(sam_data):
5555

5656

5757
@pytest.fixture
58-
def pvsyst_dc_snl_ac_system(sam_data):
58+
def pvsyst_dc_snl_ac_system(sam_data, pvsyst_module_params):
5959
module = 'PVsyst test module'
60-
module_parameters = pvsyst_module_params()
60+
module_parameters = pvsyst_module_params
6161
module_parameters['b'] = 0.05
6262
inverters = sam_data['cecinverter']
6363
inverter = inverters['ABB__MICRO_0_25_I_OUTD_US_208_208V__CEC_2014_'].copy()
@@ -446,12 +446,16 @@ def test_bad_get_orientation():
446446
@fail_on_pvlib_version('0.7')
447447
def test_deprecated_07():
448448
# explicit system creation call because fail_on_pvlib_version
449-
# does not support decorators
450-
system = cec_dc_snl_ac_system(sam_data())
449+
# does not support decorators.
450+
# does not matter what the parameters are, just fake it until we make it
451+
module_parameters = {'R_sh_ref': 1, 'a_ref': 1, 'I_o_ref': 1,
452+
'alpha_sc': 1, 'I_L_ref': 1, 'R_s': 1}
453+
system = PVSystem(module_parameters=module_parameters)
451454
with pytest.warns(pvlibDeprecationWarning):
452455
mc = ModelChain(system, location,
453456
dc_model='singlediode', # this should fail after 0.7
454-
aoi_model='no_loss', spectral_model='no_loss')
457+
aoi_model='no_loss', spectral_model='no_loss',
458+
ac_model='snlinverter')
455459

456460

457461
@requires_scipy

pvlib/test/test_singlediode.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ def test_brentq_fs_495():
129129
return isc, voc, imp, vmp, pmp, i, v, pvs
130130

131131

132-
@pytest.fixture
133-
def pvsyst_fs_495():
132+
def get_pvsyst_fs_495():
134133
"""
135134
PVsyst parameters for First Solar FS-495 module from PVSyst-6.7.2 database.
136135
@@ -156,16 +155,23 @@ def pvsyst_fs_495():
156155

157156

158157
@pytest.mark.parametrize(
159-
'poa, temp_cell, expected, tol',
160-
[(pvsyst_fs_495()['irrad_ref'], pvsyst_fs_495()['temp_ref'],
161-
{'pmp': pvsyst_fs_495()['I_mp_ref'] * pvsyst_fs_495()['V_mp_ref'],
162-
'isc': pvsyst_fs_495()['I_sc_ref'], 'voc': pvsyst_fs_495()['V_oc_ref']},
163-
(5e-4, 0.04)),
164-
(POA, TCELL, {'pmp': 76.26, 'isc': 1.387, 'voc': 79.29}, (1e-3, 1e-3))]
158+
'poa, temp_cell, expected, tol', [
159+
(
160+
get_pvsyst_fs_495()['irrad_ref'],
161+
get_pvsyst_fs_495()['temp_ref'],
162+
{
163+
'pmp': (get_pvsyst_fs_495()['I_mp_ref'] *
164+
get_pvsyst_fs_495()['V_mp_ref']),
165+
'isc': get_pvsyst_fs_495()['I_sc_ref'],
166+
'voc': get_pvsyst_fs_495()['V_oc_ref']
167+
},
168+
(5e-4, 0.04)
169+
),
170+
(POA, TCELL, {'pmp': 76.26, 'isc': 1.387, 'voc': 79.29}, (1e-3, 1e-3))]
165171
) # DeSoto @(888[W/m**2], 55[degC]) = {Pmp: 72.71, Isc: 1.402, Voc: 75.42)
166-
def test_pvsyst_recombination_loss(pvsyst_fs_495, poa, temp_cell, expected,
167-
tol):
172+
def test_pvsyst_recombination_loss(poa, temp_cell, expected, tol):
168173
"""test PVSst recombination loss"""
174+
pvsyst_fs_495 = get_pvsyst_fs_495()
169175
# first evaluate PVSyst model with thin-film recombination loss current
170176
# at reference conditions
171177
x = pvsystem.calcparams_pvsyst(

pvlib/test/test_solarposition.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def golden_mst():
3939

4040
@pytest.fixture()
4141
def expected_solpos():
42+
return _expected_solpos_df()
43+
44+
45+
# hack to make tests work without too much modification while avoiding
46+
# pytest 4.0 inability to call features directly
47+
def _expected_solpos_df():
4248
return pd.DataFrame({'elevation': 39.872046,
4349
'apparent_zenith': 50.111622,
4450
'azimuth': 194.340241,
@@ -483,15 +489,14 @@ def test_get_solarposition_error(golden):
483489
method='error this')
484490

485491

486-
@pytest.mark.parametrize(
487-
"pressure, expected", [
488-
(82000, expected_solpos()),
492+
@pytest.mark.parametrize("pressure, expected", [
493+
(82000, _expected_solpos_df()),
489494
(90000, pd.DataFrame(
490495
np.array([[ 39.88997, 50.11003, 194.34024, 39.87205, 14.64151,
491496
50.12795]]),
492-
columns=['apparent_elevation', 'apparent_zenith', 'azimuth', 'elevation',
493-
'equation_of_time', 'zenith'],
494-
index=expected_solpos().index))
497+
columns=['apparent_elevation', 'apparent_zenith', 'azimuth',
498+
'elevation', 'equation_of_time', 'zenith'],
499+
index=['2003-10-17T12:30:30Z']))
495500
])
496501
def test_get_solarposition_pressure(pressure, expected, golden):
497502
times = pd.date_range(datetime.datetime(2003,10,17,13,30,30),
@@ -507,15 +512,14 @@ def test_get_solarposition_pressure(pressure, expected, golden):
507512
assert_frame_equal(this_expected, ephem_data[this_expected.columns])
508513

509514

510-
@pytest.mark.parametrize(
511-
"altitude, expected",
512-
[(golden().altitude, expected_solpos()),
515+
@pytest.mark.parametrize("altitude, expected", [
516+
(1830.14, _expected_solpos_df()),
513517
(2000, pd.DataFrame(
514518
np.array([[ 39.88788, 50.11212, 194.34024, 39.87205, 14.64151,
515519
50.12795]]),
516520
columns=['apparent_elevation', 'apparent_zenith', 'azimuth',
517521
'elevation', 'equation_of_time', 'zenith'],
518-
index=expected_solpos().index))
522+
index=['2003-10-17T12:30:30Z']))
519523
])
520524
def test_get_solarposition_altitude(altitude, expected, golden):
521525
times = pd.date_range(datetime.datetime(2003,10,17,13,30,30),
@@ -531,17 +535,18 @@ def test_get_solarposition_altitude(altitude, expected, golden):
531535
assert_frame_equal(this_expected, ephem_data[this_expected.columns])
532536

533537

534-
@pytest.mark.parametrize(
535-
"delta_t, method, expected", [
536-
(None, 'nrel_numpy', expected_solpos_multi()),
537-
(67.0, 'nrel_numpy', expected_solpos_multi()),
538-
pytest.mark.xfail(
538+
@pytest.mark.parametrize("delta_t, method", [
539+
(None, 'nrel_numpy'),
540+
(67.0, 'nrel_numpy'),
541+
pytest.param(
542+
None, 'nrel_numba',
543+
marks=[pytest.mark.xfail(
539544
raises=ValueError,
540-
reason='spa.calculate_deltat not implemented for numba yet')
541-
((None, 'nrel_numba', expected_solpos_multi())),
542-
(67.0, 'nrel_numba', expected_solpos_multi())
545+
reason='spa.calculate_deltat not implemented for numba yet')]),
546+
(67.0, 'nrel_numba')
543547
])
544-
def test_get_solarposition_deltat(delta_t, method, expected, golden):
548+
def test_get_solarposition_deltat(delta_t, method, expected_solpos_multi,
549+
golden):
545550
times = pd.date_range(datetime.datetime(2003,10,17,13,30,30),
546551
periods=2, freq='D', tz=golden.tz)
547552
ephem_data = solarposition.get_solarposition(times, golden.latitude,
@@ -550,7 +555,7 @@ def test_get_solarposition_deltat(delta_t, method, expected, golden):
550555
delta_t=delta_t,
551556
temperature=11,
552557
method=method)
553-
this_expected = expected.copy()
558+
this_expected = expected_solpos_multi
554559
this_expected.index = times
555560
this_expected = np.round(this_expected, 5)
556561
ephem_data = np.round(ephem_data, 5)
@@ -673,10 +678,8 @@ def test_analytical_azimuth():
673678
decl, zenith)
674679

675680
idx = np.where(solar_zenith < np.pi/2)
676-
assert np.allclose(azimuth_1[idx], solar_azimuth.as_matrix()[idx],
677-
atol=0.01)
678-
assert np.allclose(azimuth_2[idx], solar_azimuth.as_matrix()[idx],
679-
atol=0.017)
681+
assert np.allclose(azimuth_1[idx], solar_azimuth.values[idx], atol=0.01)
682+
assert np.allclose(azimuth_2[idx], solar_azimuth.values[idx], atol=0.017)
680683

681684
# test for NaN values at boundary conditions (PR #431)
682685
test_angles = np.radians(np.array(

0 commit comments

Comments
 (0)