2
2
3
3
import ydb
4
4
5
- from datetime import date , datetime , timedelta , timezone
5
+ from datetime import date , datetime , timedelta
6
6
7
7
8
8
@pytest .fixture
@@ -31,37 +31,27 @@ def settings_off():
31
31
return settings
32
32
33
33
34
- test_td = timedelta (microseconds = - 100 )
35
- test_now = datetime .utcnow ()
36
- test_today = test_now .date ()
37
- test_dt_today = datetime .today ()
38
- tz4h = timezone (timedelta (hours = 4 ))
39
-
40
-
41
34
params = pytest .mark .parametrize (
42
- "value,ydb_type,casted_result,uncasted_type " ,
35
+ "value,ydb_type,casted_result,uncasted_result " ,
43
36
[
44
- (test_today , "Date" , test_today , int ),
45
- (365 , "Date" , date (1971 , 1 , 1 ), int ),
46
- (3600 * 24 * 365 , "Datetime" , datetime (1971 , 1 , 1 , 0 , 0 ), int ),
47
- (datetime (1970 , 1 , 1 , 4 , 0 , tzinfo = tz4h ), "Timestamp" , datetime (1970 , 1 , 1 , 0 , 0 ), int ),
48
- (test_td , "Interval" , test_td , int ),
49
- (test_now , "Timestamp" , test_now , int ),
37
+ (365 , "Date" , date (1971 , 1 , 1 ), 365 ),
38
+ (3600 * 24 * 365 , "Datetime" , datetime (1971 , 1 , 1 , 0 , 0 ), 3600 * 24 * 365 ),
39
+ (timedelta (seconds = 1 ), "Interval" , timedelta (seconds = 1 ), 1000000 ),
50
40
(
51
41
1511789040123456 ,
52
42
"Timestamp" ,
53
43
datetime .fromisoformat ("2017-11-27 13:24:00.123456" ),
54
- int ,
44
+ 1511789040123456 ,
55
45
),
56
- ('{"foo": "bar"}' , "Json" , {"foo" : "bar" }, str ),
57
- ('{"foo": "bar"}' , "JsonDocument" , {"foo" : "bar" }, str ),
46
+ ('{"foo": "bar"}' , "Json" , {"foo" : "bar" }, '{"foo": "bar"}' ),
47
+ ('{"foo": "bar"}' , "JsonDocument" , {"foo" : "bar" }, '{"foo":"bar"}' ),
58
48
],
59
49
)
60
50
61
51
62
52
class TestQueryClientSettings :
63
53
@params
64
- def test_driver_turn_on (self , driver_sync , settings_on , value , ydb_type , casted_result , uncasted_type ):
54
+ def test_driver_turn_on (self , driver_sync , settings_on , value , ydb_type , casted_result , uncasted_result ):
65
55
driver_sync ._driver_config .query_client_settings = settings_on
66
56
pool = ydb .QuerySessionPool (driver_sync )
67
57
result = pool .execute_with_retries (
@@ -72,18 +62,18 @@ def test_driver_turn_on(self, driver_sync, settings_on, value, ydb_type, casted_
72
62
pool .stop ()
73
63
74
64
@params
75
- def test_driver_turn_off (self , driver_sync , settings_off , value , ydb_type , casted_result , uncasted_type ):
65
+ def test_driver_turn_off (self , driver_sync , settings_off , value , ydb_type , casted_result , uncasted_result ):
76
66
driver_sync ._driver_config .query_client_settings = settings_off
77
67
pool = ydb .QuerySessionPool (driver_sync )
78
68
result = pool .execute_with_retries (
79
69
f"DECLARE $param as { ydb_type } ; SELECT $param as value" ,
80
70
{"$param" : (value , getattr (ydb .PrimitiveType , ydb_type ))},
81
71
)
82
- assert type ( result [0 ].rows [0 ].value ) == uncasted_type
72
+ assert result [0 ].rows [0 ].value == uncasted_result
83
73
pool .stop ()
84
74
85
75
@params
86
- def test_session_pool_turn_on (self , driver_sync , settings_on , value , ydb_type , casted_result , uncasted_type ):
76
+ def test_session_pool_turn_on (self , driver_sync , settings_on , value , ydb_type , casted_result , uncasted_result ):
87
77
pool = ydb .QuerySessionPool (driver_sync , query_client_settings = settings_on )
88
78
result = pool .execute_with_retries (
89
79
f"DECLARE $param as { ydb_type } ; SELECT $param as value" ,
@@ -93,18 +83,18 @@ def test_session_pool_turn_on(self, driver_sync, settings_on, value, ydb_type, c
93
83
pool .stop ()
94
84
95
85
@params
96
- def test_session_pool_turn_off (self , driver_sync , settings_off , value , ydb_type , casted_result , uncasted_type ):
86
+ def test_session_pool_turn_off (self , driver_sync , settings_off , value , ydb_type , casted_result , uncasted_result ):
97
87
pool = ydb .QuerySessionPool (driver_sync , query_client_settings = settings_off )
98
88
result = pool .execute_with_retries (
99
89
f"DECLARE $param as { ydb_type } ; SELECT $param as value" ,
100
90
{"$param" : (value , getattr (ydb .PrimitiveType , ydb_type ))},
101
91
)
102
- assert type ( result [0 ].rows [0 ].value ) == uncasted_type
92
+ assert result [0 ].rows [0 ].value == uncasted_result
103
93
pool .stop ()
104
94
105
95
@pytest .mark .asyncio
106
96
@params
107
- async def test_driver_async_turn_on (self , driver , settings_on , value , ydb_type , casted_result , uncasted_type ):
97
+ async def test_driver_async_turn_on (self , driver , settings_on , value , ydb_type , casted_result , uncasted_result ):
108
98
driver ._driver_config .query_client_settings = settings_on
109
99
pool = ydb .aio .QuerySessionPool (driver )
110
100
result = await pool .execute_with_retries (
@@ -116,19 +106,21 @@ async def test_driver_async_turn_on(self, driver, settings_on, value, ydb_type,
116
106
117
107
@pytest .mark .asyncio
118
108
@params
119
- async def test_driver_async_turn_off (self , driver , settings_off , value , ydb_type , casted_result , uncasted_type ):
109
+ async def test_driver_async_turn_off (self , driver , settings_off , value , ydb_type , casted_result , uncasted_result ):
120
110
driver ._driver_config .query_client_settings = settings_off
121
111
pool = ydb .aio .QuerySessionPool (driver )
122
112
result = await pool .execute_with_retries (
123
113
f"DECLARE $param as { ydb_type } ; SELECT $param as value" ,
124
114
{"$param" : (value , getattr (ydb .PrimitiveType , ydb_type ))},
125
115
)
126
- assert type ( result [0 ].rows [0 ].value ) == uncasted_type
116
+ assert result [0 ].rows [0 ].value == uncasted_result
127
117
await pool .stop ()
128
118
129
119
@pytest .mark .asyncio
130
120
@params
131
- async def test_session_pool_async_turn_on (self , driver , settings_on , value , ydb_type , casted_result , uncasted_type ):
121
+ async def test_session_pool_async_turn_on (
122
+ self , driver , settings_on , value , ydb_type , casted_result , uncasted_result
123
+ ):
132
124
pool = ydb .aio .QuerySessionPool (driver , query_client_settings = settings_on )
133
125
result = await pool .execute_with_retries (
134
126
f"DECLARE $param as { ydb_type } ; SELECT $param as value" ,
@@ -140,12 +132,12 @@ async def test_session_pool_async_turn_on(self, driver, settings_on, value, ydb_
140
132
@pytest .mark .asyncio
141
133
@params
142
134
async def test_session_pool_async_turn_off (
143
- self , driver , settings_off , value , ydb_type , casted_result , uncasted_type
135
+ self , driver , settings_off , value , ydb_type , casted_result , uncasted_result
144
136
):
145
137
pool = ydb .aio .QuerySessionPool (driver , query_client_settings = settings_off )
146
138
result = await pool .execute_with_retries (
147
139
f"DECLARE $param as { ydb_type } ; SELECT $param as value" ,
148
140
{"$param" : (value , getattr (ydb .PrimitiveType , ydb_type ))},
149
141
)
150
- assert type ( result [0 ].rows [0 ].value ) == uncasted_type
142
+ assert result [0 ].rows [0 ].value == uncasted_result
151
143
await pool .stop ()
0 commit comments