Skip to content

Commit 8a1efcb

Browse files
committed
ENH: TST: use fixture instead of module-level dictionary for test
* dangerous to use module-level dictionary inside test, b/c dictionary values could be changed inadvertently, but not a fixture * add fixture as argument in test * change parametrize to call fixture instead of module-level dictionary
1 parent 3d0deb2 commit 8a1efcb

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

pvlib/test/test_singlediode_methods.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,36 +129,45 @@ def test_brentq_fs_495():
129129
return isc, voc, imp, vmp, pmp, i, v, pvs
130130

131131

132-
# PVsyst parameters for First Solar FS-495 module from PVSyst-6.7.2 database
133-
# I_L_ref derived from Isc_ref conditions:
134-
# I_L_ref = (I_sc_ref + Id + Ish) / (1 - d2mutau/(Vbi*N_s - Vd))
135-
# where
136-
# Vd = I_sc_ref * R_s
137-
# Id = I_o_ref * (exp(Vd / nNsVt) - 1)
138-
# Ish = Vd / R_sh_ref
139-
PVSYST_FS_495 = {
140-
'd2mutau': 1.31, 'alpha_sc': 0.00039, 'gamma_ref': 1.48, 'mu_gamma': 0.001,
141-
'I_o_ref': 9.62e-10, 'R_sh_ref': 5000, 'R_sh_0': 12500, 'R_sh_exp': 3.1,
142-
'R_s': 4.6, 'beta_oc': -0.2116, 'EgRef': 1.5, 'cells_in_series': 108,
143-
'cells_in_parallel': 2, 'I_sc_ref': 1.55, 'V_oc_ref': 86.5,
144-
'I_mp_ref': 1.4, 'V_mp_ref': 67.85, 'temp_ref': 25, 'irrad_ref': 1000,
145-
'I_L_ref': 1.5743233463848496
146-
}
132+
@pytest.fixture
133+
def pvsyst_fs_495():
134+
"""
135+
PVsyst parameters for First Solar FS-495 module from PVSyst-6.7.2 database.
136+
137+
I_L_ref derived from Isc_ref conditions::
138+
139+
I_L_ref = (I_sc_ref + Id + Ish) / (1 - d2mutau/(Vbi*N_s - Vd))
140+
141+
where::
142+
143+
Vd = I_sc_ref * R_s
144+
Id = I_o_ref * (exp(Vd / nNsVt) - 1)
145+
Ish = Vd / R_sh_ref
146+
147+
"""
148+
return {
149+
'd2mutau': 1.31, 'alpha_sc': 0.00039, 'gamma_ref': 1.48,
150+
'mu_gamma': 0.001, 'I_o_ref': 9.62e-10, 'R_sh_ref': 5000,
151+
'R_sh_0': 12500, 'R_sh_exp': 3.1, 'R_s': 4.6, 'beta_oc': -0.2116,
152+
'EgRef': 1.5, 'cells_in_series': 108, 'cells_in_parallel': 2,
153+
'I_sc_ref': 1.55, 'V_oc_ref': 86.5, 'I_mp_ref': 1.4, 'V_mp_ref': 67.85,
154+
'temp_ref': 25, 'irrad_ref': 1000, 'I_L_ref': 1.5743233463848496
155+
}
147156

148157

149158
@pytest.mark.parametrize(
150159
'poa, temp_cell, expected, tol',
151-
[(PVSYST_FS_495['irrad_ref'], PVSYST_FS_495['temp_ref'],
152-
{'pmp': PVSYST_FS_495['I_mp_ref']*PVSYST_FS_495['V_mp_ref'],
153-
'isc': PVSYST_FS_495['I_sc_ref'], 'voc': PVSYST_FS_495['V_oc_ref']},
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']},
154163
(5e-4, 0.04)),
155164
(POA, TCELL, {'pmp': 76.26, 'isc': 1.387, 'voc': 79.29}, (1e-3, 1e-3))]
156165
) # DeSoto @(888[W/m**2], 55[degC]) = {Pmp: 72.71, Isc: 1.402, Voc: 75.42)
157-
def test_pvsyst_recombination_loss(poa, temp_cell, expected, tol):
166+
def test_pvsyst_recombination_loss(pvsyst_fs_495, poa, temp_cell, expected,
167+
tol):
158168
"""test PVSst recombination loss"""
159169
# first evaluate PVSyst model with thin-film recombination loss current
160170
# at reference conditions
161-
pvsyst_fs_495 = PVSYST_FS_495
162171
x = pvsystem.calcparams_pvsyst(
163172
effective_irradiance=poa, temp_cell=temp_cell,
164173
alpha_sc=pvsyst_fs_495['alpha_sc'],

0 commit comments

Comments
 (0)