|
10 | 10 | bishop88, bishop88_i_from_v, bishop88_v_from_i)
|
11 | 11 | from pvlib._deprecation import pvlibDeprecationWarning
|
12 | 12 | import pytest
|
| 13 | +from numpy.testing import assert_array_equal |
13 | 14 | from .conftest import DATA_DIR
|
14 | 15 |
|
15 | 16 | POA = 888
|
@@ -167,17 +168,24 @@ def test_singlediode_precision(method, precise_iv_curves):
|
167 | 168 | assert np.allclose(pc['i_xx'], outs['i_xx'], atol=1e-6, rtol=0)
|
168 | 169 |
|
169 | 170 |
|
170 |
| -def test_singlediode_lambert_negative_voc(): |
171 |
| - |
172 |
| - # Those values result in a negative v_oc out of `_lambertw_v_from_i` |
173 |
| - x = np.array([0., 1.480501e-11, 0.178, 8000., 1.797559]) |
174 |
| - outs = pvsystem.singlediode(*x, method='lambertw') |
175 |
| - assert outs['v_oc'] == 0 |
| 171 | +def test_singlediode_lambert_negative_voc(mocker): |
| 172 | + """Tests approximation to zero of v_oc when it is negative and small. |
| 173 | + See singlediode.py:_lambertw > comment 'Set small elements <0 in v_oc to 0' |
| 174 | + """ |
| 175 | + # Next values should result in a negative v_oc out of `_lambertw_v_from_i` |
| 176 | + # however, we can't ensure that the output belongs to (-1e-12, 0), so we |
| 177 | + # mock it. It depends on the platform and Python distro. See issue #2000. |
| 178 | + patcher = mocker.patch("pvlib.singlediode._lambertw_v_from_i") |
| 179 | + x = np.array([0.0, 1.480501e-11, 0.178, 8000.0, 1.797559]) |
| 180 | + patcher.return_value = -9.999e-13 |
| 181 | + outs = pvsystem.singlediode(*x, method="lambertw") |
| 182 | + assert outs["v_oc"] == 0 |
176 | 183 |
|
177 | 184 | # Testing for an array
|
178 |
| - x = np.array([x, x]).T |
179 |
| - outs = pvsystem.singlediode(*x, method='lambertw') |
180 |
| - assert np.array_equal(outs['v_oc'], [0, 0]) |
| 185 | + patcher.return_value = np.array([-9.999e-13, -1.001e-13]) |
| 186 | + x = np.array([x, x]).T |
| 187 | + outs = pvsystem.singlediode(*x, method="lambertw") |
| 188 | + assert_array_equal(outs["v_oc"], [0, 0]) |
181 | 189 |
|
182 | 190 |
|
183 | 191 | @pytest.mark.parametrize('method', ['lambertw'])
|
|
0 commit comments