Skip to content

Commit adfe600

Browse files
committed
BUG: add UT to conver_value for this use case (pandas-dev#39189)
1 parent 558a585 commit adfe600

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import pytest
2+
from typing import Any
3+
from unittest.mock import patch, PropertyMock
4+
from pandas.core.computation.pytables import BinOp, TermValue
5+
from pandas.core.series import Series
6+
7+
8+
@patch('pandas.core.computation.pytables.BinOp.kind', new_callable=PropertyMock, return_value='integer')
9+
@patch('pandas.core.computation.pytables.BinOp.meta', new_callable=PropertyMock, return_value='category')
10+
@patch('pandas.core.computation.pytables.BinOp.metadata', new_callable=PropertyMock, return_value=Series(data=['a', 'b', 's']))
11+
@pytest.mark.parametrize("value, expected_results",
12+
[('q',
13+
TermValue(-1, -1, 'integer')),
14+
('a',
15+
TermValue(0, 0, 'integer'))])
16+
def test_convert_value(mock_kind,
17+
mock_meta,
18+
mock_metadata,
19+
value: Any,
20+
expected_results: TermValue):
21+
22+
with patch.object(BinOp, "__init__", lambda p1, p2, p3, p4, p5, p6: None):
23+
bin_op = BinOp(None, None, None, None, None)
24+
bin_op.encoding = 'UTF-8'
25+
26+
result = bin_op.convert_value(value)
27+
28+
assert result.kind == expected_results.kind and\
29+
result.value == expected_results.value and\
30+
result.converted == expected_results.converted

0 commit comments

Comments
 (0)