pycel
pycel copied to clipboard
Wrong result if lookup_value is string for "match" function.
Problem description
When I match the string value, the result is incorrect.
What actually happened
============================= test session starts =============================
collecting ... collected 3 items
test_lookup.py::test_match_for_string[1-lookup_array0-1-3]
test_lookup.py::test_match_for_string[B-lookup_array1-1-3] PASSED [ 33%]FAILED [ 66%]
tests\lib\test_lookup.py:403 (test_match_for_string[B-lookup_array1-1-3])
5 != 3
Expected :3
Actual :5
<Click to see difference>
lookup_value = 'B', lookup_array = ['A', None, 'B', None, 'C', None, ...]
match_type = 1, expected = 3
@pytest.mark.parametrize(
'lookup_value, lookup_array, match_type, expected', (
(1, [None, None, 1, 3.3, 5, None, None], 1, 3),
('B', ['A', None, 'B', None, 'C', None, 'D'], 1, 3),
(1, [2, None, 1, 3.3, 5, None, None], 1, 3),
))
def test_match_for_string(lookup_value, lookup_array, match_type, expected):
lookup_row = (tuple(lookup_array),)
lookup_col = tuple((i,) for i in lookup_array)
> assert match(lookup_value, lookup_row, match_type) == expected
E AssertionError: assert 5 == 3
E + where 5 = match('B', (('A', None, 'B', None, 'C', None, ...),), 1)
test_lookup.py:413: AssertionError
PASSED [100%]
test_lookup.py::test_match_for_string[1-lookup_array2-1-3]
=================== 1 failed, 2 passed, 1 warning in 0.29s ====================
It looks not a problem, it's a misuse of "bisect_right()"
array
Out[13]: ('A', None, 'B', None, 'C', None, 'D')
value
Out[14]: ExcelCmp(cmp_type=1, value='A', empty='')
bisect_right(array, value, lo=0, hi=len(array))
Out[15]: 6