1
+ import sys
2
+
1
3
import numpy as np
2
4
import pandas as pd
3
5
from numpy import nan
@@ -78,11 +80,19 @@ def pvwatts_dc_pvwatts_ac_system(sam_data):
78
80
return system
79
81
80
82
81
- @pytest .fixture ()
83
+ @pytest .fixture
82
84
def location ():
83
85
return Location (32.2 , - 111 , altitude = 700 )
84
86
85
87
88
+ @pytest .fixture
89
+ def weather ():
90
+ times = pd .date_range ('20160101 1200-0700' , periods = 2 , freq = '6H' )
91
+ weather = pd .DataFrame ({'ghi' : [500 , 0 ], 'dni' : [800 , 0 ], 'dhi' : [100 , 0 ]},
92
+ index = times )
93
+ return weather
94
+
95
+
86
96
def test_ModelChain_creation (system , location ):
87
97
mc = ModelChain (system , location )
88
98
@@ -292,7 +302,7 @@ def test_spectral_models(system, location, spectral_model):
292
302
columns = ['precipitable_water' ])
293
303
mc = ModelChain (system , location , dc_model = 'sapm' ,
294
304
aoi_model = 'no_loss' , spectral_model = spectral_model )
295
- spectral_modifier = mc .run_model (times = times ,
305
+ spectral_modifier = mc .run_model (times = times ,
296
306
weather = weather ).spectral_modifier
297
307
assert isinstance (spectral_modifier , (pd .Series , float , int ))
298
308
@@ -302,22 +312,44 @@ def constant_losses(mc):
302
312
mc .ac *= mc .losses
303
313
304
314
305
- @requires_scipy
306
- @pytest .mark .parametrize ('losses_model, expected' , [
307
- ('pvwatts' , [163.280464174 , 0 ]),
308
- ('no_loss' , [190.028186986 , 0 ]),
309
- (constant_losses , [171.025368287 , 0 ])
310
- ])
311
- def test_losses_models (pvwatts_dc_pvwatts_ac_system , location , losses_model ,
312
- expected ):
315
+ def test_losses_models_pvwatts (pvwatts_dc_pvwatts_ac_system , location , weather ,
316
+ mocker ):
317
+ age = 1
318
+ pvwatts_dc_pvwatts_ac_system .losses_parameters = dict (age = age )
319
+ m = mocker .spy (pvsystem , 'pvwatts_losses' )
313
320
mc = ModelChain (pvwatts_dc_pvwatts_ac_system , location , dc_model = 'pvwatts' ,
314
321
aoi_model = 'no_loss' , spectral_model = 'no_loss' ,
315
- losses_model = losses_model )
316
- times = pd .date_range ('20160101 1200-0700' , periods = 2 , freq = '6H' )
317
- ac = mc .run_model (times ).ac
322
+ losses_model = 'pvwatts' )
323
+ mc .run_model (weather .index , weather = weather )
324
+ assert m .call_count == 1
325
+ m .assert_called_with (age = age )
326
+ assert isinstance (mc .ac , (pd .Series , pd .DataFrame ))
327
+ assert not mc .ac .empty
318
328
319
- expected = pd .Series (np .array (expected ), index = times )
320
- assert_series_equal (ac , expected , check_less_precise = 2 )
329
+
330
+ def test_losses_models_ext_def (pvwatts_dc_pvwatts_ac_system , location , weather ,
331
+ mocker ):
332
+ m = mocker .spy (sys .modules [__name__ ], 'constant_losses' )
333
+ mc = ModelChain (pvwatts_dc_pvwatts_ac_system , location , dc_model = 'pvwatts' ,
334
+ aoi_model = 'no_loss' , spectral_model = 'no_loss' ,
335
+ losses_model = constant_losses )
336
+ mc .run_model (weather .index , weather = weather )
337
+ assert m .call_count == 1
338
+ assert isinstance (mc .ac , (pd .Series , pd .DataFrame ))
339
+ assert mc .losses == 0.9
340
+ assert not mc .ac .empty
341
+
342
+
343
+ def test_losses_models_no_loss (pvwatts_dc_pvwatts_ac_system , location , weather ,
344
+ mocker ):
345
+ m = mocker .spy (pvsystem , 'pvwatts_losses' )
346
+ mc = ModelChain (pvwatts_dc_pvwatts_ac_system , location , dc_model = 'pvwatts' ,
347
+ aoi_model = 'no_loss' , spectral_model = 'no_loss' ,
348
+ losses_model = 'no_loss' )
349
+ assert mc .losses_model == mc .no_extra_losses
350
+ mc .run_model (weather .index , weather = weather )
351
+ assert m .call_count == 0
352
+ assert mc .losses == 1
321
353
322
354
323
355
@pytest .mark .parametrize ('model' , [
0 commit comments