Skip to content

Commit c2ac022

Browse files
authored
Fix Windows/Conda CI error in test_singlediode.py (#2007)
* Update test_singlediode.py * Linter 🔧 * Update test_singlediode.py * Change approach completely. Now we are mocking. 👷 * Thanks ruff for the formatting 💚
1 parent 71da245 commit c2ac022

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

pvlib/tests/test_singlediode.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
bishop88, bishop88_i_from_v, bishop88_v_from_i)
1111
from pvlib._deprecation import pvlibDeprecationWarning
1212
import pytest
13+
from numpy.testing import assert_array_equal
1314
from .conftest import DATA_DIR
1415

1516
POA = 888
@@ -167,17 +168,24 @@ def test_singlediode_precision(method, precise_iv_curves):
167168
assert np.allclose(pc['i_xx'], outs['i_xx'], atol=1e-6, rtol=0)
168169

169170

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
176183

177184
# 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])
181189

182190

183191
@pytest.mark.parametrize('method', ['lambertw'])

0 commit comments

Comments
 (0)