|
| 1 | +import pytest |
| 2 | +import ydb |
| 3 | + |
| 4 | + |
| 5 | +query = """SELECT $a AS value""" |
| 6 | + |
| 7 | + |
| 8 | +def test_select_implicit_int(pool: ydb.QuerySessionPool): |
| 9 | + expected_value = 111 |
| 10 | + res = pool.execute_with_retries(query, parameters={'$a': expected_value}) |
| 11 | + actual_value = res[0].rows[0]['value'] |
| 12 | + assert expected_value == actual_value |
| 13 | + |
| 14 | + |
| 15 | +def test_select_implicit_float(pool: ydb.QuerySessionPool): |
| 16 | + expected_value = 11.1 |
| 17 | + res = pool.execute_with_retries(query, parameters={'$a': expected_value}) |
| 18 | + actual_value = res[0].rows[0]['value'] |
| 19 | + assert expected_value == pytest.approx(actual_value) |
| 20 | + |
| 21 | + |
| 22 | +def test_select_implicit_bool(pool: ydb.QuerySessionPool): |
| 23 | + expected_value = False |
| 24 | + res = pool.execute_with_retries(query, parameters={'$a': expected_value}) |
| 25 | + actual_value = res[0].rows[0]['value'] |
| 26 | + assert expected_value == actual_value |
| 27 | + |
| 28 | + |
| 29 | +def test_select_implicit_str(pool: ydb.QuerySessionPool): |
| 30 | + expected_value = "text" |
| 31 | + res = pool.execute_with_retries(query, parameters={'$a': expected_value}) |
| 32 | + actual_value = res[0].rows[0]['value'] |
| 33 | + assert expected_value == actual_value |
| 34 | + |
| 35 | + |
| 36 | +def test_select_explicit_primitive(pool: ydb.QuerySessionPool): |
| 37 | + expected_value = 111 |
| 38 | + res = pool.execute_with_retries(query, parameters={'$a': (expected_value, ydb.PrimitiveType.Int64)}) |
| 39 | + actual_value = res[0].rows[0]['value'] |
| 40 | + assert expected_value == actual_value |
| 41 | + |
| 42 | + |
| 43 | +def test_select_explicit_list(pool: ydb.QuerySessionPool): |
| 44 | + expected_value = [1, 2, 3] |
| 45 | + type_ = ydb.ListType(ydb.PrimitiveType.Int64) |
| 46 | + res = pool.execute_with_retries(query, parameters={'$a': (expected_value, type_)}) |
| 47 | + actual_value = res[0].rows[0]['value'] |
| 48 | + assert expected_value == actual_value |
| 49 | + |
| 50 | + |
| 51 | +def test_select_explicit_dict(pool: ydb.QuerySessionPool): |
| 52 | + expected_value = {'key': 'value'} |
| 53 | + type_ = ydb.DictType(ydb.PrimitiveType.Utf8, ydb.PrimitiveType.Utf8) |
| 54 | + res = pool.execute_with_retries(query, parameters={'$a': (expected_value, type_)}) |
| 55 | + actual_value = res[0].rows[0]['value'] |
| 56 | + assert expected_value == actual_value |
0 commit comments