Skip to content

Commit a43d52f

Browse files
committed
Rename system fixture
1 parent 03d6180 commit a43d52f

File tree

1 file changed

+73
-73
lines changed

1 file changed

+73
-73
lines changed

pvlib/tests/test_modelchain.py

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818

1919
@pytest.fixture(scope='function')
20-
def system(sapm_module_params, cec_inverter_parameters,
21-
sapm_temperature_cs5p_220m):
20+
def sapm_dc_snl_ac_system(sapm_module_params, cec_inverter_parameters,
21+
sapm_temperature_cs5p_220m):
2222
module = 'Canadian_Solar_CS5P_220M___2009_'
2323
module_parameters = sapm_module_params.copy()
2424
temp_model_params = sapm_temperature_cs5p_220m.copy()
@@ -166,26 +166,26 @@ def weather():
166166
return weather
167167

168168

169-
def test_ModelChain_creation(system, location):
170-
ModelChain(system, location)
169+
def test_ModelChain_creation(sapm_dc_snl_ac_system, location):
170+
ModelChain(sapm_dc_snl_ac_system, location)
171171

172172

173173
@pytest.mark.parametrize('strategy, expected', [
174174
(None, (32.2, 180)), ('None', (32.2, 180)), ('flat', (0, 180)),
175175
('south_at_latitude_tilt', (32.2, 180))
176176
])
177-
def test_orientation_strategy(strategy, expected, system, location):
178-
mc = ModelChain(system, location, orientation_strategy=strategy)
177+
def test_orientation_strategy(strategy, expected, sapm_dc_snl_ac_system, location):
178+
mc = ModelChain(sapm_dc_snl_ac_system, location, orientation_strategy=strategy)
179179

180180
# the || accounts for the coercion of 'None' to None
181181
assert (mc.orientation_strategy == strategy or
182182
mc.orientation_strategy is None)
183-
assert system.surface_tilt == expected[0]
184-
assert system.surface_azimuth == expected[1]
183+
assert sapm_dc_snl_ac_system.surface_tilt == expected[0]
184+
assert sapm_dc_snl_ac_system.surface_azimuth == expected[1]
185185

186186

187-
def test_run_model_with_irradiance(system, location):
188-
mc = ModelChain(system, location)
187+
def test_run_model_with_irradiance(sapm_dc_snl_ac_system, location):
188+
mc = ModelChain(sapm_dc_snl_ac_system, location)
189189
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
190190
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
191191
index=times)
@@ -196,42 +196,42 @@ def test_run_model_with_irradiance(system, location):
196196
assert_series_equal(ac, expected)
197197

198198

199-
def test_run_model_times(system, location):
200-
mc = ModelChain(system, location)
199+
def test_run_model_times(sapm_dc_snl_ac_system, location):
200+
mc = ModelChain(sapm_dc_snl_ac_system, location)
201201
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
202202
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
203203
index=times)
204204
with pytest.warns(pvlibDeprecationWarning):
205205
mc.run_model(irradiance, times=times)
206206

207207

208-
def test_prepare_inputs_times(system, location):
209-
mc = ModelChain(system, location)
208+
def test_prepare_inputs_times(sapm_dc_snl_ac_system, location):
209+
mc = ModelChain(sapm_dc_snl_ac_system, location)
210210
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
211211
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
212212
index=times)
213213
with pytest.warns(pvlibDeprecationWarning):
214214
mc.prepare_inputs(irradiance, times=times)
215215

216216

217-
def test_prepare_inputs_no_irradiance(system, location):
218-
mc = ModelChain(system, location)
217+
def test_prepare_inputs_no_irradiance(sapm_dc_snl_ac_system, location):
218+
mc = ModelChain(sapm_dc_snl_ac_system, location)
219219
weather = pd.DataFrame()
220220
with pytest.raises(ValueError):
221221
mc.prepare_inputs(weather)
222222

223223

224224
@requires_tables
225-
def test_complete_irradiance_times(system, location):
226-
mc = ModelChain(system, location)
225+
def test_complete_irradiance_times(sapm_dc_snl_ac_system, location):
226+
mc = ModelChain(sapm_dc_snl_ac_system, location)
227227
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
228228
irradiance = pd.DataFrame({'ghi': 600., 'dhi': 150.}, index=times)
229229
with pytest.warns(pvlibDeprecationWarning):
230230
mc.complete_irradiance(irradiance, times=times)
231231

232232

233-
def test_run_model_perez(system, location):
234-
mc = ModelChain(system, location, transposition_model='perez')
233+
def test_run_model_perez(sapm_dc_snl_ac_system, location):
234+
mc = ModelChain(sapm_dc_snl_ac_system, location, transposition_model='perez')
235235
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
236236
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
237237
index=times)
@@ -242,8 +242,8 @@ def test_run_model_perez(system, location):
242242
assert_series_equal(ac, expected)
243243

244244

245-
def test_run_model_gueymard_perez(system, location):
246-
mc = ModelChain(system, location, airmass_model='gueymard1993',
245+
def test_run_model_gueymard_perez(sapm_dc_snl_ac_system, location):
246+
mc = ModelChain(sapm_dc_snl_ac_system, location, airmass_model='gueymard1993',
247247
transposition_model='perez')
248248
times = pd.date_range('20160101 1200-0700', periods=2, freq='6H')
249249
irradiance = pd.DataFrame({'dni': 900, 'ghi': 600, 'dhi': 150},
@@ -255,15 +255,15 @@ def test_run_model_gueymard_perez(system, location):
255255
assert_series_equal(ac, expected)
256256

257257

258-
def test_run_model_with_weather_sapm_temp(system, location, weather, mocker):
258+
def test_run_model_with_weather_sapm_temp(sapm_dc_snl_ac_system, location, weather, mocker):
259259
# test with sapm cell temperature model
260260
weather['wind_speed'] = 5
261261
weather['temp_air'] = 10
262-
system.racking_model = 'open_rack'
263-
system.module_type = 'glass_glass'
264-
mc = ModelChain(system, location)
262+
sapm_dc_snl_ac_system.racking_model = 'open_rack'
263+
sapm_dc_snl_ac_system.module_type = 'glass_glass'
264+
mc = ModelChain(sapm_dc_snl_ac_system, location)
265265
mc.temperature_model = 'sapm'
266-
m_sapm = mocker.spy(system, 'sapm_celltemp')
266+
m_sapm = mocker.spy(sapm_dc_snl_ac_system, 'sapm_celltemp')
267267
mc.run_model(weather)
268268
assert m_sapm.call_count == 1
269269
# assert_called_once_with cannot be used with series, so need to use
@@ -273,43 +273,43 @@ def test_run_model_with_weather_sapm_temp(system, location, weather, mocker):
273273
assert not mc.ac.empty
274274

275275

276-
def test_run_model_with_weather_pvsyst_temp(system, location, weather, mocker):
276+
def test_run_model_with_weather_pvsyst_temp(sapm_dc_snl_ac_system, location, weather, mocker):
277277
# test with pvsyst cell temperature model
278278
weather['wind_speed'] = 5
279279
weather['temp_air'] = 10
280-
system.racking_model = 'freestanding'
281-
system.temperature_model_parameters = \
280+
sapm_dc_snl_ac_system.racking_model = 'freestanding'
281+
sapm_dc_snl_ac_system.temperature_model_parameters = \
282282
temperature._temperature_model_params('pvsyst', 'freestanding')
283-
mc = ModelChain(system, location)
283+
mc = ModelChain(sapm_dc_snl_ac_system, location)
284284
mc.temperature_model = 'pvsyst'
285-
m_pvsyst = mocker.spy(system, 'pvsyst_celltemp')
285+
m_pvsyst = mocker.spy(sapm_dc_snl_ac_system, 'pvsyst_celltemp')
286286
mc.run_model(weather)
287287
assert m_pvsyst.call_count == 1
288288
assert_series_equal(m_pvsyst.call_args[0][1], weather['temp_air'])
289289
assert_series_equal(m_pvsyst.call_args[0][2], weather['wind_speed'])
290290
assert not mc.ac.empty
291291

292292

293-
def test_run_model_with_weather_faiman_temp(system, location, weather, mocker):
293+
def test_run_model_with_weather_faiman_temp(sapm_dc_snl_ac_system, location, weather, mocker):
294294
# test with faiman cell temperature model
295295
weather['wind_speed'] = 5
296296
weather['temp_air'] = 10
297-
system.temperature_model_parameters = {'u0': 25.0, 'u1': 6.84}
298-
mc = ModelChain(system, location)
297+
sapm_dc_snl_ac_system.temperature_model_parameters = {'u0': 25.0, 'u1': 6.84}
298+
mc = ModelChain(sapm_dc_snl_ac_system, location)
299299
mc.temperature_model = 'faiman'
300-
m_faiman = mocker.spy(system, 'faiman_celltemp')
300+
m_faiman = mocker.spy(sapm_dc_snl_ac_system, 'faiman_celltemp')
301301
mc.run_model(weather)
302302
assert m_faiman.call_count == 1
303303
assert_series_equal(m_faiman.call_args[0][1], weather['temp_air'])
304304
assert_series_equal(m_faiman.call_args[0][2], weather['wind_speed'])
305305
assert not mc.ac.empty
306306

307307

308-
def test_run_model_tracker(system, location, weather, mocker):
308+
def test_run_model_tracker(sapm_dc_snl_ac_system, location, weather, mocker):
309309
system = SingleAxisTracker(
310-
module_parameters=system.module_parameters,
311-
temperature_model_parameters=system.temperature_model_parameters,
312-
inverter_parameters=system.inverter_parameters)
310+
module_parameters=sapm_dc_snl_ac_system.module_parameters,
311+
temperature_model_parameters=sapm_dc_snl_ac_system.temperature_model_parameters,
312+
inverter_parameters=sapm_dc_snl_ac_system.inverter_parameters)
313313
mocker.spy(system, 'singleaxis')
314314
mc = ModelChain(system, location)
315315
mc.run_model(weather)
@@ -332,10 +332,10 @@ def poadc(mc):
332332
pytest.param('pvsyst', marks=requires_scipy),
333333
pytest.param('singlediode', marks=requires_scipy),
334334
'pvwatts_dc'])
335-
def test_infer_dc_model(system, cec_dc_snl_ac_system, pvsyst_dc_snl_ac_system,
335+
def test_infer_dc_model(sapm_dc_snl_ac_system, cec_dc_snl_ac_system, pvsyst_dc_snl_ac_system,
336336
pvwatts_dc_pvwatts_ac_system, location, dc_model,
337337
weather, mocker):
338-
dc_systems = {'sapm': system,
338+
dc_systems = {'sapm': sapm_dc_snl_ac_system,
339339
'cec': cec_dc_snl_ac_system,
340340
'desoto': cec_dc_snl_ac_system,
341341
'pvsyst': pvsyst_dc_snl_ac_system,
@@ -374,9 +374,9 @@ def test_infer_dc_model(system, cec_dc_snl_ac_system, pvsyst_dc_snl_ac_system,
374374
'sapm',
375375
pytest.param('cec', marks=requires_scipy),
376376
pytest.param('cec_native', marks=requires_scipy)])
377-
def test_infer_spectral_model(location, system, cec_dc_snl_ac_system,
377+
def test_infer_spectral_model(location, sapm_dc_snl_ac_system, cec_dc_snl_ac_system,
378378
cec_dc_native_snl_ac_system, dc_model):
379-
dc_systems = {'sapm': system,
379+
dc_systems = {'sapm': sapm_dc_snl_ac_system,
380380
'cec': cec_dc_snl_ac_system,
381381
'cec_native': cec_dc_native_snl_ac_system}
382382
system = dc_systems[dc_model]
@@ -388,11 +388,11 @@ def test_infer_spectral_model(location, system, cec_dc_snl_ac_system,
388388
@pytest.mark.parametrize('temp_model', [
389389
'sapm_temp', 'faiman_temp',
390390
pytest.param('pvsyst_temp', marks=requires_scipy)])
391-
def test_infer_temp_model(location, system,
391+
def test_infer_temp_model(location, sapm_dc_snl_ac_system,
392392
pvwatts_dc_pvwatts_ac_pvsyst_temp_system,
393393
pvwatts_dc_pvwatts_ac_faiman_temp_system,
394394
temp_model):
395-
dc_systems = {'sapm_temp': system,
395+
dc_systems = {'sapm_temp': sapm_dc_snl_ac_system,
396396
'pvsyst_temp': pvwatts_dc_pvwatts_ac_pvsyst_temp_system,
397397
'faiman_temp': pvwatts_dc_pvwatts_ac_faiman_temp_system}
398398
system = dc_systems[temp_model]
@@ -404,17 +404,17 @@ def test_infer_temp_model(location, system,
404404

405405

406406
@requires_scipy
407-
def test_infer_temp_model_invalid(location, system):
408-
system.temperature_model_parameters.pop('a')
407+
def test_infer_temp_model_invalid(location, sapm_dc_snl_ac_system):
408+
sapm_dc_snl_ac_system.temperature_model_parameters.pop('a')
409409
with pytest.raises(ValueError):
410-
ModelChain(system, location, orientation_strategy='None',
410+
ModelChain(sapm_dc_snl_ac_system, location, orientation_strategy='None',
411411
aoi_model='physical', spectral_model='no_loss')
412412

413413

414414
@requires_scipy
415-
def test_temperature_model_inconsistent(location, system):
415+
def test_temperature_model_inconsistent(location, sapm_dc_snl_ac_system):
416416
with pytest.raises(ValueError):
417-
ModelChain(system, location, orientation_strategy='None',
417+
ModelChain(sapm_dc_snl_ac_system, location, orientation_strategy='None',
418418
aoi_model='physical', spectral_model='no_loss',
419419
temperature_model='pvsyst')
420420

@@ -437,9 +437,9 @@ def acdc(mc):
437437
@pytest.mark.parametrize('ac_model', [
438438
'snlinverter', pytest.param('adrinverter', marks=requires_scipy),
439439
'pvwatts'])
440-
def test_ac_models(system, cec_dc_adr_ac_system, pvwatts_dc_pvwatts_ac_system,
440+
def test_ac_models(sapm_dc_snl_ac_system, cec_dc_adr_ac_system, pvwatts_dc_pvwatts_ac_system,
441441
location, ac_model, weather, mocker):
442-
ac_systems = {'snlinverter': system, 'adrinverter': cec_dc_adr_ac_system,
442+
ac_systems = {'snlinverter': sapm_dc_snl_ac_system, 'adrinverter': cec_dc_adr_ac_system,
443443
'pvwatts': pvwatts_dc_pvwatts_ac_system}
444444
system = ac_systems[ac_model]
445445

@@ -473,10 +473,10 @@ def constant_aoi_loss(mc):
473473
@pytest.mark.parametrize('aoi_model', [
474474
'sapm', 'ashrae', 'physical', 'martin_ruiz'
475475
])
476-
def test_aoi_models(system, location, aoi_model, weather, mocker):
477-
mc = ModelChain(system, location, dc_model='sapm',
476+
def test_aoi_models(sapm_dc_snl_ac_system, location, aoi_model, weather, mocker):
477+
mc = ModelChain(sapm_dc_snl_ac_system, location, dc_model='sapm',
478478
aoi_model=aoi_model, spectral_model='no_loss')
479-
m = mocker.spy(system, 'get_iam')
479+
m = mocker.spy(sapm_dc_snl_ac_system, 'get_iam')
480480
mc.run_model(weather=weather)
481481
assert m.call_count == 1
482482
assert isinstance(mc.ac, pd.Series)
@@ -485,8 +485,8 @@ def test_aoi_models(system, location, aoi_model, weather, mocker):
485485
assert mc.ac[1] < 1
486486

487487

488-
def test_aoi_model_no_loss(system, location, weather):
489-
mc = ModelChain(system, location, dc_model='sapm',
488+
def test_aoi_model_no_loss(sapm_dc_snl_ac_system, location, weather):
489+
mc = ModelChain(sapm_dc_snl_ac_system, location, dc_model='sapm',
490490
aoi_model='no_loss', spectral_model='no_loss')
491491
mc.run_model(weather)
492492
assert mc.aoi_modifier == 1.0
@@ -495,9 +495,9 @@ def test_aoi_model_no_loss(system, location, weather):
495495
assert mc.ac[1] < 1
496496

497497

498-
def test_aoi_model_user_func(system, location, weather, mocker):
498+
def test_aoi_model_user_func(sapm_dc_snl_ac_system, location, weather, mocker):
499499
m = mocker.spy(sys.modules[__name__], 'constant_aoi_loss')
500-
mc = ModelChain(system, location, dc_model='sapm',
500+
mc = ModelChain(sapm_dc_snl_ac_system, location, dc_model='sapm',
501501
aoi_model=constant_aoi_loss, spectral_model='no_loss')
502502
mc.run_model(weather)
503503
assert m.call_count == 1
@@ -534,10 +534,10 @@ def constant_spectral_loss(mc):
534534
@pytest.mark.parametrize('spectral_model', [
535535
'sapm', 'first_solar', 'no_loss', constant_spectral_loss
536536
])
537-
def test_spectral_models(system, location, spectral_model, weather):
537+
def test_spectral_models(sapm_dc_snl_ac_system, location, spectral_model, weather):
538538
# add pw to weather dataframe
539539
weather['precipitable_water'] = [0.3, 0.5]
540-
mc = ModelChain(system, location, dc_model='sapm',
540+
mc = ModelChain(sapm_dc_snl_ac_system, location, dc_model='sapm',
541541
aoi_model='no_loss', spectral_model=spectral_model)
542542
spectral_modifier = mc.run_model(weather).spectral_modifier
543543
assert isinstance(spectral_modifier, (pd.Series, float, int))
@@ -596,14 +596,14 @@ def test_losses_models_no_loss(pvwatts_dc_pvwatts_ac_system, location, weather,
596596
assert mc.losses == 1
597597

598598

599-
def test_invalid_dc_model_params(system, cec_dc_snl_ac_system,
599+
def test_invalid_dc_model_params(sapm_dc_snl_ac_system, cec_dc_snl_ac_system,
600600
pvwatts_dc_pvwatts_ac_system, location):
601601
kwargs = {'dc_model': 'sapm', 'ac_model': 'snlinverter',
602602
'aoi_model': 'no_loss', 'spectral_model': 'no_loss',
603603
'temperature_model': 'sapm', 'losses_model': 'no_loss'}
604-
system.module_parameters.pop('A0') # remove a parameter
604+
sapm_dc_snl_ac_system.module_parameters.pop('A0') # remove a parameter
605605
with pytest.raises(ValueError):
606-
ModelChain(system, location, **kwargs)
606+
ModelChain(sapm_dc_snl_ac_system, location, **kwargs)
607607

608608
kwargs['dc_model'] = 'singlediode'
609609
cec_dc_snl_ac_system.module_parameters.pop('a_ref') # remove a parameter
@@ -621,13 +621,13 @@ def test_invalid_dc_model_params(system, cec_dc_snl_ac_system,
621621
'dc_model', 'ac_model', 'aoi_model', 'spectral_model',
622622
'temperature_model', 'losses_model'
623623
])
624-
def test_invalid_models(model, system, location):
624+
def test_invalid_models(model, sapm_dc_snl_ac_system, location):
625625
kwargs = {'dc_model': 'pvwatts', 'ac_model': 'pvwatts',
626626
'aoi_model': 'no_loss', 'spectral_model': 'no_loss',
627627
'temperature_model': 'sapm', 'losses_model': 'no_loss'}
628628
kwargs[model] = 'invalid'
629629
with pytest.raises(ValueError):
630-
ModelChain(system, location, **kwargs)
630+
ModelChain(sapm_dc_snl_ac_system, location, **kwargs)
631631

632632

633633
def test_bad_get_orientation():
@@ -766,9 +766,9 @@ def test_basic_chain_altitude_pressure(sam_data, cec_inverter_parameters,
766766
@pytest.mark.parametrize('strategy, strategy_str', [
767767
('south_at_latitude_tilt', 'south_at_latitude_tilt'),
768768
(None, 'None')]) # GitHub issue 352
769-
def test_ModelChain___repr__(system, location, strategy, strategy_str):
769+
def test_ModelChain___repr__(sapm_dc_snl_ac_system, location, strategy, strategy_str):
770770

771-
mc = ModelChain(system, location, orientation_strategy=strategy,
771+
mc = ModelChain(sapm_dc_snl_ac_system, location, orientation_strategy=strategy,
772772
name='my mc')
773773

774774
expected = '\n'.join([
@@ -791,9 +791,9 @@ def test_ModelChain___repr__(system, location, strategy, strategy_str):
791791

792792

793793
@requires_scipy
794-
def test_complete_irradiance_clean_run(system, location):
794+
def test_complete_irradiance_clean_run(sapm_dc_snl_ac_system, location):
795795
"""The DataFrame should not change if all columns are passed"""
796-
mc = ModelChain(system, location)
796+
mc = ModelChain(sapm_dc_snl_ac_system, location)
797797
times = pd.date_range('2010-07-05 9:00:00', periods=2, freq='H')
798798
i = pd.DataFrame(
799799
{'dni': [2, 3], 'dhi': [4, 6], 'ghi': [9, 5]}, index=times)
@@ -809,9 +809,9 @@ def test_complete_irradiance_clean_run(system, location):
809809

810810

811811
@requires_scipy
812-
def test_complete_irradiance(system, location):
812+
def test_complete_irradiance(sapm_dc_snl_ac_system, location):
813813
"""Check calculations"""
814-
mc = ModelChain(system, location)
814+
mc = ModelChain(sapm_dc_snl_ac_system, location)
815815
times = pd.date_range('2010-07-05 7:00:00-0700', periods=2, freq='H')
816816
i = pd.DataFrame({'dni': [49.756966, 62.153947],
817817
'ghi': [372.103976116, 497.087579068],

0 commit comments

Comments
 (0)