@@ -2648,18 +2648,47 @@ def test_max_power_point_mismatched(inputs):
26482648 print (result )
26492649
26502650
2651- def test_max_power_point_mismatched_exception ():
2651+ @pytest .mark .parametrize (
2652+ 'inputs' ,
2653+ [
2654+ {
2655+ "photocurrent" : - 6.2 , # This is bad.
2656+ "saturation_current" : 1.0e-8 ,
2657+ "n" : 1.1 ,
2658+ "resistance_series" : 0.0001 ,
2659+ "resistance_shunt" : 5000.0 ,
2660+ "Ns" : 60 ,
2661+ "T" : 25.0 ,
2662+ },
2663+ {
2664+ "photocurrent" : - 6.2 , # This is bad.
2665+ "saturation_current" : 1.0e-8 ,
2666+ "n" : 1.1 ,
2667+ "resistance_series" : 0.0001 ,
2668+ "resistance_shunt" : 5000.0 ,
2669+ "Ns" : 60 ,
2670+ "T" : 25.0 ,
2671+ "i_mp_ic" : 5.6 ,
2672+ },
2673+ ]
2674+ )
2675+ def test_max_power_point_mismatched_exception (inputs , monkeypatch ):
26522676 """
26532677 Test errored max power point computation for mismatched devices in series.
26542678 """
2655- photocurrent = - 6.2 # This is bad.
2656- saturation_current = 1.0e-8
2657- resistance_series = 0.0001
2658- resistance_shunt = 5000.0
2679+ # Monkey patch the objective function to force thrown exception.
2680+ monkeypatch .setattr (
2681+ "pvlib.pvsystem._negative_total_power" , ZeroDivisionError
2682+ )
2683+
2684+ photocurrent = inputs ["photocurrent" ]
2685+ saturation_current = inputs ["saturation_current" ]
2686+ resistance_series = inputs ["resistance_series" ]
2687+ resistance_shunt = inputs ["resistance_shunt" ]
26592688 q_C = scipy .constants .value ("elementary charge" )
26602689 k_B_J_per_K = scipy .constants .value ("Boltzmann constant" )
2661- T_K = scipy .constants .convert_temperature (25.0 , "Celsius" , "Kelvin" )
2662- nNsVth = 1.1 * 60 * k_B_J_per_K * T_K / q_C
2690+ T_K = scipy .constants .convert_temperature (inputs [ "T" ] , "Celsius" , "Kelvin" )
2691+ nNsVth = inputs [ "n" ] * inputs [ "Ns" ] * k_B_J_per_K * T_K / q_C
26632692
26642693 with pytest .raises (RuntimeError ) as e_info :
26652694 pvsystem .max_power_point_mismatched (
0 commit comments