crate 1.0.0.dev1__py3-none-any.whl → 1.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crate/client/__init__.py +4 -3
- crate/client/blob.py +9 -7
- crate/client/connection.py +58 -52
- crate/client/converter.py +15 -10
- crate/client/cursor.py +55 -51
- crate/client/exceptions.py +5 -3
- crate/client/http.py +192 -160
- crate/testing/__init__.py +0 -1
- crate/testing/layer.py +140 -102
- crate/testing/util.py +80 -5
- {crate-1.0.0.dev1.dist-info → crate-1.0.1.dist-info}/LICENSE +0 -70
- {crate-1.0.0.dev1.dist-info → crate-1.0.1.dist-info}/METADATA +14 -16
- {crate-1.0.0.dev1.dist-info → crate-1.0.1.dist-info}/NOTICE +1 -1
- crate-1.0.1.dist-info/RECORD +17 -0
- {crate-1.0.0.dev1.dist-info → crate-1.0.1.dist-info}/WHEEL +1 -1
- crate/client/test_connection.py +0 -98
- crate/client/test_cursor.py +0 -341
- crate/client/test_exceptions.py +0 -14
- crate/client/test_http.py +0 -678
- crate/client/test_util.py +0 -69
- crate/client/tests.py +0 -340
- crate/testing/settings.py +0 -51
- crate/testing/test_datetime_old.py +0 -90
- crate/testing/test_layer.py +0 -290
- crate/testing/tests.py +0 -34
- crate-1.0.0.dev1-py3.9-nspkg.pth +0 -1
- crate-1.0.0.dev1.dist-info/RECORD +0 -29
- crate-1.0.0.dev1.dist-info/namespace_packages.txt +0 -1
- {crate-1.0.0.dev1.dist-info → crate-1.0.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
crate/client/__init__.py,sha256=hefR2KxiciqgwZ6dd5fR4wwPHuS3Kgup-gpc7jxFNlU,1344
|
2
|
+
crate/client/_pep440.py,sha256=iwY5wopxbgbwsT0ImANrwN3V_ZYQHhSr7lEdVT5dQRM,42
|
3
|
+
crate/client/blob.py,sha256=aMo6ZNHGT3Zq_yR3gcpd3CKrJvfqUAhExhKtHUwC5Io,3460
|
4
|
+
crate/client/connection.py,sha256=80v9_--YilDAaIQpejf3G_TWGz9iwUkixwHAL66sDm0,8098
|
5
|
+
crate/client/converter.py,sha256=Qci0MNcpz1jAnjquG8Ld9LI84_iHVInrv4HMb8r5zzg,4313
|
6
|
+
crate/client/cursor.py,sha256=Mlk-TVLzM4zSSr7GxcHK4Mjbt1KQeMfNFNrPBtGjk-c,10741
|
7
|
+
crate/client/exceptions.py,sha256=wMyJmOB3RP5kuPeW9f0fEb-1AKZcGSTyIGvN0HqpqUw,2557
|
8
|
+
crate/client/http.py,sha256=ddp_VSTcrMNStPjSG0CmdtRUO8dgaQZfNR_ltfs9DxI,22625
|
9
|
+
crate/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
10
|
+
crate/testing/layer.py,sha256=jvHRWTRE4Zal211UO0HWPFcbprAcaGB3WyAUDR7BKFQ,13376
|
11
|
+
crate/testing/util.py,sha256=BPEZ8DavXwyOTCmOQnP5QjQlapEw3harzKK4w2HOTA4,3264
|
12
|
+
crate-1.0.1.dist-info/LICENSE,sha256=s_w3FXmAYQuatqsgvyYLnGyC_13KOqp3W1DUEXO9RpY,10175
|
13
|
+
crate-1.0.1.dist-info/METADATA,sha256=nvUareNPApcQKA8AcNrTepTjFvDc72QbjzgHEUCo5Oc,5351
|
14
|
+
crate-1.0.1.dist-info/NOTICE,sha256=jfWOHkoZKjNATGXMfgpMJdL38ki_ZZTgR6M9CUUJxrM,1159
|
15
|
+
crate-1.0.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
16
|
+
crate-1.0.1.dist-info/top_level.txt,sha256=2wP2HlpxdhgTLMl9ipi168xkm6FMq9_2bf0xGGxF_OI,6
|
17
|
+
crate-1.0.1.dist-info/RECORD,,
|
crate/client/test_connection.py
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
import datetime
|
2
|
-
|
3
|
-
from urllib3 import Timeout
|
4
|
-
|
5
|
-
from .connection import Connection
|
6
|
-
from .http import Client
|
7
|
-
from crate.client import connect
|
8
|
-
from unittest import TestCase
|
9
|
-
|
10
|
-
from ..testing.settings import crate_host
|
11
|
-
|
12
|
-
|
13
|
-
class ConnectionTest(TestCase):
|
14
|
-
|
15
|
-
def test_connection_mock(self):
|
16
|
-
"""
|
17
|
-
For testing purposes it is often useful to replace the client used for
|
18
|
-
communication with the CrateDB server with a stub or mock.
|
19
|
-
|
20
|
-
This can be done by passing an object of the Client class when calling the
|
21
|
-
``connect`` method.
|
22
|
-
"""
|
23
|
-
|
24
|
-
class MyConnectionClient:
|
25
|
-
active_servers = ["localhost:4200"]
|
26
|
-
|
27
|
-
def __init__(self):
|
28
|
-
pass
|
29
|
-
|
30
|
-
def server_infos(self, server):
|
31
|
-
return ("localhost:4200", "my server", "0.42.0")
|
32
|
-
|
33
|
-
connection = connect([crate_host], client=MyConnectionClient())
|
34
|
-
self.assertIsInstance(connection, Connection)
|
35
|
-
self.assertEqual(connection.client.server_infos("foo"), ('localhost:4200', 'my server', '0.42.0'))
|
36
|
-
|
37
|
-
def test_lowest_server_version(self):
|
38
|
-
infos = [(None, None, '0.42.3'),
|
39
|
-
(None, None, '0.41.8'),
|
40
|
-
(None, None, 'not a version')]
|
41
|
-
|
42
|
-
client = Client(servers="localhost:4200 localhost:4201 localhost:4202")
|
43
|
-
client.server_infos = lambda server: infos.pop()
|
44
|
-
connection = connect(client=client)
|
45
|
-
self.assertEqual((0, 41, 8), connection.lowest_server_version.version)
|
46
|
-
connection.close()
|
47
|
-
|
48
|
-
def test_invalid_server_version(self):
|
49
|
-
client = Client(servers="localhost:4200")
|
50
|
-
client.server_infos = lambda server: (None, None, "No version")
|
51
|
-
connection = connect(client=client)
|
52
|
-
self.assertEqual((0, 0, 0), connection.lowest_server_version.version)
|
53
|
-
connection.close()
|
54
|
-
|
55
|
-
def test_context_manager(self):
|
56
|
-
with connect('localhost:4200') as conn:
|
57
|
-
pass
|
58
|
-
self.assertEqual(conn._closed, True)
|
59
|
-
|
60
|
-
def test_with_timezone(self):
|
61
|
-
"""
|
62
|
-
Verify the cursor objects will return timezone-aware `datetime` objects when requested to.
|
63
|
-
When switching the time zone at runtime on the connection object, only new cursor objects
|
64
|
-
will inherit the new time zone.
|
65
|
-
"""
|
66
|
-
|
67
|
-
tz_mst = datetime.timezone(datetime.timedelta(hours=7), name="MST")
|
68
|
-
connection = connect('localhost:4200', time_zone=tz_mst)
|
69
|
-
cursor = connection.cursor()
|
70
|
-
self.assertEqual(cursor.time_zone.tzname(None), "MST")
|
71
|
-
self.assertEqual(cursor.time_zone.utcoffset(None), datetime.timedelta(seconds=25200))
|
72
|
-
|
73
|
-
connection.time_zone = datetime.timezone.utc
|
74
|
-
cursor = connection.cursor()
|
75
|
-
self.assertEqual(cursor.time_zone.tzname(None), "UTC")
|
76
|
-
self.assertEqual(cursor.time_zone.utcoffset(None), datetime.timedelta(0))
|
77
|
-
|
78
|
-
def test_timeout_float(self):
|
79
|
-
"""
|
80
|
-
Verify setting the timeout value as a scalar (float) works.
|
81
|
-
"""
|
82
|
-
with connect('localhost:4200', timeout=2.42) as conn:
|
83
|
-
self.assertEqual(conn.client._pool_kw["timeout"], 2.42)
|
84
|
-
|
85
|
-
def test_timeout_string(self):
|
86
|
-
"""
|
87
|
-
Verify setting the timeout value as a scalar (string) works.
|
88
|
-
"""
|
89
|
-
with connect('localhost:4200', timeout="2.42") as conn:
|
90
|
-
self.assertEqual(conn.client._pool_kw["timeout"], 2.42)
|
91
|
-
|
92
|
-
def test_timeout_object(self):
|
93
|
-
"""
|
94
|
-
Verify setting the timeout value as a Timeout object works.
|
95
|
-
"""
|
96
|
-
timeout = Timeout(connect=2.42, read=0.01)
|
97
|
-
with connect('localhost:4200', timeout=timeout) as conn:
|
98
|
-
self.assertEqual(conn.client._pool_kw["timeout"], timeout)
|
crate/client/test_cursor.py
DELETED
@@ -1,341 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8; -*-
|
2
|
-
#
|
3
|
-
# Licensed to CRATE Technology GmbH ("Crate") under one or more contributor
|
4
|
-
# license agreements. See the NOTICE file distributed with this work for
|
5
|
-
# additional information regarding copyright ownership. Crate licenses
|
6
|
-
# this file to you under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License. You may
|
8
|
-
# obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
14
|
-
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
15
|
-
# License for the specific language governing permissions and limitations
|
16
|
-
# under the License.
|
17
|
-
#
|
18
|
-
# However, if you have executed another commercial license agreement
|
19
|
-
# with Crate these terms will supersede the license and you may use the
|
20
|
-
# software solely pursuant to the terms of the relevant commercial agreement.
|
21
|
-
|
22
|
-
import datetime
|
23
|
-
from ipaddress import IPv4Address
|
24
|
-
from unittest import TestCase
|
25
|
-
from unittest.mock import MagicMock
|
26
|
-
try:
|
27
|
-
import zoneinfo
|
28
|
-
except ImportError:
|
29
|
-
from backports import zoneinfo
|
30
|
-
|
31
|
-
import pytz
|
32
|
-
|
33
|
-
from crate.client import connect
|
34
|
-
from crate.client.converter import DataType, DefaultTypeConverter
|
35
|
-
from crate.client.http import Client
|
36
|
-
from crate.client.test_util import ClientMocked
|
37
|
-
|
38
|
-
|
39
|
-
class CursorTest(TestCase):
|
40
|
-
|
41
|
-
@staticmethod
|
42
|
-
def get_mocked_connection():
|
43
|
-
client = MagicMock(spec=Client)
|
44
|
-
return connect(client=client)
|
45
|
-
|
46
|
-
def test_create_with_timezone_as_datetime_object(self):
|
47
|
-
"""
|
48
|
-
Verify the cursor returns timezone-aware `datetime` objects when requested to.
|
49
|
-
Switching the time zone at runtime on the cursor object is possible.
|
50
|
-
Here: Use a `datetime.timezone` instance.
|
51
|
-
"""
|
52
|
-
|
53
|
-
connection = self.get_mocked_connection()
|
54
|
-
|
55
|
-
tz_mst = datetime.timezone(datetime.timedelta(hours=7), name="MST")
|
56
|
-
cursor = connection.cursor(time_zone=tz_mst)
|
57
|
-
|
58
|
-
self.assertEqual(cursor.time_zone.tzname(None), "MST")
|
59
|
-
self.assertEqual(cursor.time_zone.utcoffset(None), datetime.timedelta(seconds=25200))
|
60
|
-
|
61
|
-
cursor.time_zone = datetime.timezone.utc
|
62
|
-
self.assertEqual(cursor.time_zone.tzname(None), "UTC")
|
63
|
-
self.assertEqual(cursor.time_zone.utcoffset(None), datetime.timedelta(0))
|
64
|
-
|
65
|
-
def test_create_with_timezone_as_pytz_object(self):
|
66
|
-
"""
|
67
|
-
Verify the cursor returns timezone-aware `datetime` objects when requested to.
|
68
|
-
Here: Use a `pytz.timezone` instance.
|
69
|
-
"""
|
70
|
-
connection = self.get_mocked_connection()
|
71
|
-
cursor = connection.cursor(time_zone=pytz.timezone('Australia/Sydney'))
|
72
|
-
self.assertEqual(cursor.time_zone.tzname(None), "Australia/Sydney")
|
73
|
-
|
74
|
-
# Apparently, when using `pytz`, the timezone object does not return an offset.
|
75
|
-
# Nevertheless, it works, as demonstrated per doctest in `cursor.txt`.
|
76
|
-
self.assertEqual(cursor.time_zone.utcoffset(None), None)
|
77
|
-
|
78
|
-
def test_create_with_timezone_as_zoneinfo_object(self):
|
79
|
-
"""
|
80
|
-
Verify the cursor returns timezone-aware `datetime` objects when requested to.
|
81
|
-
Here: Use a `zoneinfo.ZoneInfo` instance.
|
82
|
-
"""
|
83
|
-
connection = self.get_mocked_connection()
|
84
|
-
cursor = connection.cursor(time_zone=zoneinfo.ZoneInfo('Australia/Sydney'))
|
85
|
-
self.assertEqual(cursor.time_zone.key, 'Australia/Sydney')
|
86
|
-
|
87
|
-
def test_create_with_timezone_as_utc_offset_success(self):
|
88
|
-
"""
|
89
|
-
Verify the cursor returns timezone-aware `datetime` objects when requested to.
|
90
|
-
Here: Use a UTC offset in string format.
|
91
|
-
"""
|
92
|
-
connection = self.get_mocked_connection()
|
93
|
-
cursor = connection.cursor(time_zone="+0530")
|
94
|
-
self.assertEqual(cursor.time_zone.tzname(None), "+0530")
|
95
|
-
self.assertEqual(cursor.time_zone.utcoffset(None), datetime.timedelta(seconds=19800))
|
96
|
-
|
97
|
-
connection = self.get_mocked_connection()
|
98
|
-
cursor = connection.cursor(time_zone="-1145")
|
99
|
-
self.assertEqual(cursor.time_zone.tzname(None), "-1145")
|
100
|
-
self.assertEqual(cursor.time_zone.utcoffset(None), datetime.timedelta(days=-1, seconds=44100))
|
101
|
-
|
102
|
-
def test_create_with_timezone_as_utc_offset_failure(self):
|
103
|
-
"""
|
104
|
-
Verify the cursor croaks when trying to create it with invalid UTC offset strings.
|
105
|
-
"""
|
106
|
-
connection = self.get_mocked_connection()
|
107
|
-
with self.assertRaises(AssertionError) as ex:
|
108
|
-
connection.cursor(time_zone="foobar")
|
109
|
-
self.assertEqual(str(ex.exception), "Time zone 'foobar' is given in invalid UTC offset format")
|
110
|
-
|
111
|
-
connection = self.get_mocked_connection()
|
112
|
-
with self.assertRaises(ValueError) as ex:
|
113
|
-
connection.cursor(time_zone="+abcd")
|
114
|
-
self.assertEqual(str(ex.exception), "Time zone '+abcd' is given in invalid UTC offset format: "
|
115
|
-
"invalid literal for int() with base 10: '+ab'")
|
116
|
-
|
117
|
-
def test_create_with_timezone_connection_cursor_precedence(self):
|
118
|
-
"""
|
119
|
-
Verify that the time zone specified on the cursor object instance
|
120
|
-
takes precedence over the one specified on the connection instance.
|
121
|
-
"""
|
122
|
-
client = MagicMock(spec=Client)
|
123
|
-
connection = connect(client=client, time_zone=pytz.timezone('Australia/Sydney'))
|
124
|
-
cursor = connection.cursor(time_zone="+0530")
|
125
|
-
self.assertEqual(cursor.time_zone.tzname(None), "+0530")
|
126
|
-
self.assertEqual(cursor.time_zone.utcoffset(None), datetime.timedelta(seconds=19800))
|
127
|
-
|
128
|
-
def test_execute_with_args(self):
|
129
|
-
client = MagicMock(spec=Client)
|
130
|
-
conn = connect(client=client)
|
131
|
-
c = conn.cursor()
|
132
|
-
statement = 'select * from locations where position = ?'
|
133
|
-
c.execute(statement, 1)
|
134
|
-
client.sql.assert_called_once_with(statement, 1, None)
|
135
|
-
conn.close()
|
136
|
-
|
137
|
-
def test_execute_with_bulk_args(self):
|
138
|
-
client = MagicMock(spec=Client)
|
139
|
-
conn = connect(client=client)
|
140
|
-
c = conn.cursor()
|
141
|
-
statement = 'select * from locations where position = ?'
|
142
|
-
c.execute(statement, bulk_parameters=[[1]])
|
143
|
-
client.sql.assert_called_once_with(statement, None, [[1]])
|
144
|
-
conn.close()
|
145
|
-
|
146
|
-
def test_execute_with_converter(self):
|
147
|
-
client = ClientMocked()
|
148
|
-
conn = connect(client=client)
|
149
|
-
|
150
|
-
# Use the set of data type converters from `DefaultTypeConverter`
|
151
|
-
# and add another custom converter.
|
152
|
-
converter = DefaultTypeConverter(
|
153
|
-
{DataType.BIT: lambda value: value is not None and int(value[2:-1], 2) or None})
|
154
|
-
|
155
|
-
# Create a `Cursor` object with converter.
|
156
|
-
c = conn.cursor(converter=converter)
|
157
|
-
|
158
|
-
# Make up a response using CrateDB data types `TEXT`, `IP`,
|
159
|
-
# `TIMESTAMP`, `BIT`.
|
160
|
-
conn.client.set_next_response({
|
161
|
-
"col_types": [4, 5, 11, 25],
|
162
|
-
"cols": ["name", "address", "timestamp", "bitmask"],
|
163
|
-
"rows": [
|
164
|
-
["foo", "10.10.10.1", 1658167836758, "B'0110'"],
|
165
|
-
[None, None, None, None],
|
166
|
-
],
|
167
|
-
"rowcount": 1,
|
168
|
-
"duration": 123
|
169
|
-
})
|
170
|
-
|
171
|
-
c.execute("")
|
172
|
-
result = c.fetchall()
|
173
|
-
self.assertEqual(result, [
|
174
|
-
['foo', IPv4Address('10.10.10.1'), datetime.datetime(2022, 7, 18, 18, 10, 36, 758000), 6],
|
175
|
-
[None, None, None, None],
|
176
|
-
])
|
177
|
-
|
178
|
-
conn.close()
|
179
|
-
|
180
|
-
def test_execute_with_converter_and_invalid_data_type(self):
|
181
|
-
client = ClientMocked()
|
182
|
-
conn = connect(client=client)
|
183
|
-
converter = DefaultTypeConverter()
|
184
|
-
|
185
|
-
# Create a `Cursor` object with converter.
|
186
|
-
c = conn.cursor(converter=converter)
|
187
|
-
|
188
|
-
# Make up a response using CrateDB data types `TEXT`, `IP`,
|
189
|
-
# `TIMESTAMP`, `BIT`.
|
190
|
-
conn.client.set_next_response({
|
191
|
-
"col_types": [999],
|
192
|
-
"cols": ["foo"],
|
193
|
-
"rows": [
|
194
|
-
["n/a"],
|
195
|
-
],
|
196
|
-
"rowcount": 1,
|
197
|
-
"duration": 123
|
198
|
-
})
|
199
|
-
|
200
|
-
c.execute("")
|
201
|
-
with self.assertRaises(ValueError) as ex:
|
202
|
-
c.fetchone()
|
203
|
-
self.assertEqual(ex.exception.args, ("999 is not a valid DataType",))
|
204
|
-
|
205
|
-
def test_execute_array_with_converter(self):
|
206
|
-
client = ClientMocked()
|
207
|
-
conn = connect(client=client)
|
208
|
-
converter = DefaultTypeConverter()
|
209
|
-
cursor = conn.cursor(converter=converter)
|
210
|
-
|
211
|
-
conn.client.set_next_response({
|
212
|
-
"col_types": [4, [100, 5]],
|
213
|
-
"cols": ["name", "address"],
|
214
|
-
"rows": [["foo", ["10.10.10.1", "10.10.10.2"]]],
|
215
|
-
"rowcount": 1,
|
216
|
-
"duration": 123
|
217
|
-
})
|
218
|
-
|
219
|
-
cursor.execute("")
|
220
|
-
result = cursor.fetchone()
|
221
|
-
self.assertEqual(result, [
|
222
|
-
'foo',
|
223
|
-
[IPv4Address('10.10.10.1'), IPv4Address('10.10.10.2')],
|
224
|
-
])
|
225
|
-
|
226
|
-
def test_execute_array_with_converter_and_invalid_collection_type(self):
|
227
|
-
client = ClientMocked()
|
228
|
-
conn = connect(client=client)
|
229
|
-
converter = DefaultTypeConverter()
|
230
|
-
cursor = conn.cursor(converter=converter)
|
231
|
-
|
232
|
-
# Converting collections only works for `ARRAY`s. (ID=100).
|
233
|
-
# When using `DOUBLE` (ID=6), it should croak.
|
234
|
-
conn.client.set_next_response({
|
235
|
-
"col_types": [4, [6, 5]],
|
236
|
-
"cols": ["name", "address"],
|
237
|
-
"rows": [["foo", ["10.10.10.1", "10.10.10.2"]]],
|
238
|
-
"rowcount": 1,
|
239
|
-
"duration": 123
|
240
|
-
})
|
241
|
-
|
242
|
-
cursor.execute("")
|
243
|
-
|
244
|
-
with self.assertRaises(ValueError) as ex:
|
245
|
-
cursor.fetchone()
|
246
|
-
self.assertEqual(ex.exception.args, ("Data type 6 is not implemented as collection type",))
|
247
|
-
|
248
|
-
def test_execute_nested_array_with_converter(self):
|
249
|
-
client = ClientMocked()
|
250
|
-
conn = connect(client=client)
|
251
|
-
converter = DefaultTypeConverter()
|
252
|
-
cursor = conn.cursor(converter=converter)
|
253
|
-
|
254
|
-
conn.client.set_next_response({
|
255
|
-
"col_types": [4, [100, [100, 5]]],
|
256
|
-
"cols": ["name", "address_buckets"],
|
257
|
-
"rows": [["foo", [["10.10.10.1", "10.10.10.2"], ["10.10.10.3"], [], None]]],
|
258
|
-
"rowcount": 1,
|
259
|
-
"duration": 123
|
260
|
-
})
|
261
|
-
|
262
|
-
cursor.execute("")
|
263
|
-
result = cursor.fetchone()
|
264
|
-
self.assertEqual(result, [
|
265
|
-
'foo',
|
266
|
-
[[IPv4Address('10.10.10.1'), IPv4Address('10.10.10.2')], [IPv4Address('10.10.10.3')], [], None],
|
267
|
-
])
|
268
|
-
|
269
|
-
def test_executemany_with_converter(self):
|
270
|
-
client = ClientMocked()
|
271
|
-
conn = connect(client=client)
|
272
|
-
converter = DefaultTypeConverter()
|
273
|
-
cursor = conn.cursor(converter=converter)
|
274
|
-
|
275
|
-
conn.client.set_next_response({
|
276
|
-
"col_types": [4, 5],
|
277
|
-
"cols": ["name", "address"],
|
278
|
-
"rows": [["foo", "10.10.10.1"]],
|
279
|
-
"rowcount": 1,
|
280
|
-
"duration": 123
|
281
|
-
})
|
282
|
-
|
283
|
-
cursor.executemany("", [])
|
284
|
-
result = cursor.fetchall()
|
285
|
-
|
286
|
-
# ``executemany()`` is not intended to be used with statements returning result
|
287
|
-
# sets. The result will always be empty.
|
288
|
-
self.assertEqual(result, [])
|
289
|
-
|
290
|
-
def test_execute_with_timezone(self):
|
291
|
-
client = ClientMocked()
|
292
|
-
conn = connect(client=client)
|
293
|
-
|
294
|
-
# Create a `Cursor` object with `time_zone`.
|
295
|
-
tz_mst = datetime.timezone(datetime.timedelta(hours=7), name="MST")
|
296
|
-
c = conn.cursor(time_zone=tz_mst)
|
297
|
-
|
298
|
-
# Make up a response using CrateDB data type `TIMESTAMP`.
|
299
|
-
conn.client.set_next_response({
|
300
|
-
"col_types": [4, 11],
|
301
|
-
"cols": ["name", "timestamp"],
|
302
|
-
"rows": [
|
303
|
-
["foo", 1658167836758],
|
304
|
-
[None, None],
|
305
|
-
],
|
306
|
-
})
|
307
|
-
|
308
|
-
# Run execution and verify the returned `datetime` object is timezone-aware,
|
309
|
-
# using the designated timezone object.
|
310
|
-
c.execute("")
|
311
|
-
result = c.fetchall()
|
312
|
-
self.assertEqual(result, [
|
313
|
-
[
|
314
|
-
'foo',
|
315
|
-
datetime.datetime(2022, 7, 19, 1, 10, 36, 758000,
|
316
|
-
tzinfo=datetime.timezone(datetime.timedelta(seconds=25200), 'MST')),
|
317
|
-
],
|
318
|
-
[
|
319
|
-
None,
|
320
|
-
None,
|
321
|
-
],
|
322
|
-
])
|
323
|
-
self.assertEqual(result[0][1].tzname(), "MST")
|
324
|
-
|
325
|
-
# Change timezone and verify the returned `datetime` object is using it.
|
326
|
-
c.time_zone = datetime.timezone.utc
|
327
|
-
c.execute("")
|
328
|
-
result = c.fetchall()
|
329
|
-
self.assertEqual(result, [
|
330
|
-
[
|
331
|
-
'foo',
|
332
|
-
datetime.datetime(2022, 7, 18, 18, 10, 36, 758000, tzinfo=datetime.timezone.utc),
|
333
|
-
],
|
334
|
-
[
|
335
|
-
None,
|
336
|
-
None,
|
337
|
-
],
|
338
|
-
])
|
339
|
-
self.assertEqual(result[0][1].tzname(), "UTC")
|
340
|
-
|
341
|
-
conn.close()
|
crate/client/test_exceptions.py
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import unittest
|
2
|
-
|
3
|
-
from crate.client import Error
|
4
|
-
|
5
|
-
|
6
|
-
class ErrorTestCase(unittest.TestCase):
|
7
|
-
|
8
|
-
def test_error_with_msg(self):
|
9
|
-
err = Error("foo")
|
10
|
-
self.assertEqual(str(err), "foo")
|
11
|
-
|
12
|
-
def test_error_with_error_trace(self):
|
13
|
-
err = Error("foo", error_trace="### TRACE ###")
|
14
|
-
self.assertEqual(str(err), "foo\n### TRACE ###")
|