Skip to content

Commit 2f124d9

Browse files
authored
handle warnings from temperature model tests (#796)
* handle warnings in temperature model tests * test for content of exceptions * test warning message content * fix it up * correct indent on asserts * fix indent on pop * fix exceptioninfo reference * use match kwarg * use match kwarg throughout
1 parent 16cc0d4 commit 2f124d9

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

pvlib/modelchain.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,15 @@ def __init__(self, system, location,
324324
# TODO: deprecated kwarg temp_model. Remove use of temp_model in v0.8
325325
temp_model = kwargs.pop('temp_model', None)
326326
if temp_model is not None:
327-
warnings.warn('The temp_model keyword argument is deprecated. Use '
328-
'temperature_model instead', pvlibDeprecationWarning)
329327
if temperature_model is None:
328+
warnings.warn('The temp_model keyword argument is deprecated.'
329+
' Use temperature_model instead',
330+
pvlibDeprecationWarning)
330331
temperature_model = temp_model
331332
elif temp_model == temperature_model:
332333
warnings.warn('Provide only one of temperature_model or '
333-
'temp_model (deprecated).')
334+
'temp_model (deprecated).',
335+
pvlibDeprecationWarning)
334336
else:
335337
raise ValueError(
336338
'Conflicting temperature_model {} and temp_model {}. '

pvlib/test/test_modelchain.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,10 @@ def test_infer_aoi_model(location, system_no_aoi, aoi_model):
470470

471471

472472
def test_infer_aoi_model_invalid(location, system_no_aoi):
473-
with pytest.raises(ValueError) as excinfo:
473+
exc_text = 'could not infer AOI model'
474+
with pytest.raises(ValueError, match=exc_text):
474475
ModelChain(system_no_aoi, location, orientation_strategy='None',
475476
spectral_model='no_loss')
476-
assert 'could not infer AOI model' in str(excinfo.value)
477477

478478

479479
def constant_spectral_loss(mc):
@@ -593,29 +593,26 @@ def test_deprecated_08():
593593
module_parameters = {'R_sh_ref': 1, 'a_ref': 1, 'I_o_ref': 1,
594594
'alpha_sc': 1, 'I_L_ref': 1, 'R_s': 1}
595595
# do not assign PVSystem.temperature_model_parameters
596+
# leave out PVSystem.racking_model and PVSystem.module_type
596597
system = PVSystem(module_parameters=module_parameters)
597-
with pytest.warns(pvlibDeprecationWarning):
598-
ModelChain(system, location,
599-
dc_model='desoto',
600-
aoi_model='no_loss', spectral_model='no_loss',
601-
temp_model='sapm',
602-
ac_model='snlinverter')
603-
system = PVSystem(module_parameters=module_parameters)
604-
with pytest.warns(pvlibDeprecationWarning):
605-
ModelChain(system, location,
606-
dc_model='desoto',
607-
aoi_model='no_loss', spectral_model='no_loss',
608-
temperature_model='sapm',
609-
temp_model='sapm',
610-
ac_model='snlinverter')
611-
system = PVSystem(module_parameters=module_parameters)
612-
with pytest.raises(ValueError):
613-
ModelChain(system, location,
614-
dc_model='desoto',
615-
aoi_model='no_loss', spectral_model='no_loss',
616-
temperature_model='pvsyst',
617-
temp_model='sapm',
618-
ac_model='snlinverter')
598+
# deprecated temp_model kwarg
599+
warn_txt = 'temp_model keyword argument is deprecated'
600+
with pytest.warns(pvlibDeprecationWarning, match=warn_txt):
601+
ModelChain(system, location, dc_model='desoto', aoi_model='no_loss',
602+
spectral_model='no_loss', ac_model='snlinverter',
603+
temp_model='sapm')
604+
# provide both temp_model and temperature_model kwargs
605+
warn_txt = 'Provide only one of temperature_model'
606+
with pytest.warns(pvlibDeprecationWarning, match=warn_txt):
607+
ModelChain(system, location, dc_model='desoto', aoi_model='no_loss',
608+
spectral_model='no_loss', ac_model='snlinverter',
609+
temperature_model='sapm', temp_model='sapm')
610+
# conflicting temp_model and temperature_model kwargs
611+
exc_text = 'Conflicting temperature_model'
612+
with pytest.raises(ValueError, match=exc_text):
613+
ModelChain(system, location, dc_model='desoto', aoi_model='no_loss',
614+
spectral_model='no_loss', ac_model='snlinverter',
615+
temperature_model='pvsyst', temp_model='sapm')
619616

620617

621618
@requires_scipy

pvlib/test/test_pvsystem.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,16 +419,20 @@ def test__infer_temperature_model_params():
419419
expected = temperature.TEMPERATURE_MODEL_PARAMETERS[
420420
'sapm']['open_rack_glass_polymer']
421421
assert expected == system._infer_temperature_model_params()
422-
expected = temperature.TEMPERATURE_MODEL_PARAMETERS[
423-
'pvsyst']['freestanding']
424422
system = pvsystem.PVSystem(module_parameters={},
425423
racking_model='freestanding',
426424
module_type='glass_polymer')
425+
expected = temperature.TEMPERATURE_MODEL_PARAMETERS[
426+
'pvsyst']['freestanding']
427427
assert expected == system._infer_temperature_model_params()
428-
system = pvsystem.PVSystem(module_parameters={},
429-
racking_model='not_a_rack_model',
430-
module_type='glass_polymer')
431-
assert {} == system._infer_temperature_model_params()
428+
429+
430+
def test__infer_temperature_model_params_deprec_warning():
431+
warn_txt = "Reverting to deprecated default"
432+
with pytest.warns(pvlibDeprecationWarning, match=warn_txt):
433+
pvsystem.PVSystem(module_parameters={},
434+
racking_model='not_a_rack_model',
435+
module_type='glass_polymer')
432436

433437

434438
def test_calcparams_desoto(cec_module_params):

0 commit comments

Comments
 (0)