singlestoredb 0.7.1__tar.gz → 0.7.3__tar.gz

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.

Potentially problematic release.


This version of singlestoredb might be problematic. Click here for more details.

Files changed (87) hide show
  1. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/PKG-INFO +1 -1
  2. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/setup.cfg +1 -1
  3. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/__init__.py +1 -1
  4. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/config.py +7 -0
  5. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/_auth.py +3 -1
  6. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/accel.c +3 -3
  7. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/connection.py +2 -1
  8. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/protocol.py +2 -1
  9. singlestoredb-0.7.3/singlestoredb/pytest.py +283 -0
  10. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/test_basics.py +54 -0
  11. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb.egg-info/PKG-INFO +1 -1
  12. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb.egg-info/SOURCES.txt +1 -0
  13. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/LICENSE +0 -0
  14. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/README.md +0 -0
  15. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/setup.py +0 -0
  16. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/auth.py +0 -0
  17. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/connection.py +0 -0
  18. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/converters.py +0 -0
  19. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/exceptions.py +0 -0
  20. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/http/__init__.py +0 -0
  21. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/http/connection.py +0 -0
  22. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/management/__init__.py +0 -0
  23. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/management/cluster.py +0 -0
  24. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/management/manager.py +0 -0
  25. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/management/region.py +0 -0
  26. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/management/utils.py +0 -0
  27. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/management/workspace.py +0 -0
  28. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/__init__.py +0 -0
  29. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/charset.py +0 -0
  30. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/constants/CLIENT.py +0 -0
  31. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/constants/COMMAND.py +0 -0
  32. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/constants/CR.py +0 -0
  33. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/constants/ER.py +0 -0
  34. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/constants/FIELD_TYPE.py +0 -0
  35. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/constants/FLAG.py +0 -0
  36. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/constants/SERVER_STATUS.py +0 -0
  37. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/constants/__init__.py +0 -0
  38. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/converters.py +0 -0
  39. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/cursors.py +0 -0
  40. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/err.py +0 -0
  41. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/optionfile.py +0 -0
  42. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/__init__.py +0 -0
  43. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/base.py +0 -0
  44. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/conftest.py +0 -0
  45. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/test_DictCursor.py +0 -0
  46. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/test_SSCursor.py +0 -0
  47. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/test_basic.py +0 -0
  48. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/test_connection.py +0 -0
  49. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/test_converters.py +0 -0
  50. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/test_cursor.py +0 -0
  51. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/test_err.py +0 -0
  52. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/test_issues.py +0 -0
  53. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/test_load_local.py +0 -0
  54. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/test_nextset.py +0 -0
  55. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/test_optionfile.py +0 -0
  56. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/thirdparty/__init__.py +0 -0
  57. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/thirdparty/test_MySQLdb/__init__.py +0 -0
  58. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/thirdparty/test_MySQLdb/capabilities.py +0 -0
  59. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/thirdparty/test_MySQLdb/dbapi20.py +0 -0
  60. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_capabilities.py +0 -0
  61. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_dbapi20.py +0 -0
  62. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_nonstandard.py +0 -0
  63. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/mysql/times.py +0 -0
  64. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/__init__.py +0 -0
  65. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/empty.sql +0 -0
  66. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/local_infile.csv +0 -0
  67. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/test.sql +0 -0
  68. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/test_config.py +0 -0
  69. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/test_connection.py +0 -0
  70. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/test_dbapi.py +0 -0
  71. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/test_exceptions.py +0 -0
  72. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/test_http.py +0 -0
  73. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/test_management.py +0 -0
  74. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/test_results.py +0 -0
  75. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/test_types.py +0 -0
  76. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/test_xdict.py +0 -0
  77. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/tests/utils.py +0 -0
  78. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/types.py +0 -0
  79. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/utils/__init__.py +0 -0
  80. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/utils/config.py +0 -0
  81. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/utils/convert_rows.py +0 -0
  82. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/utils/debug.py +0 -0
  83. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/utils/results.py +0 -0
  84. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb/utils/xdict.py +0 -0
  85. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb.egg-info/dependency_links.txt +0 -0
  86. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb.egg-info/requires.txt +0 -0
  87. {singlestoredb-0.7.1 → singlestoredb-0.7.3}/singlestoredb.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: singlestoredb
3
- Version: 0.7.1
3
+ Version: 0.7.3
4
4
  Summary: Interface to the SingleStore database and cluster management APIs
5
5
  Home-page: https://github.com/singlestore-labs/singlestoredb-python
6
6
  Author: SingleStore
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = singlestoredb
3
- version = 0.7.1
3
+ version = 0.7.3
4
4
  description = Interface to the SingleStore database and cluster management APIs
5
5
  long_description = file: README.md
6
6
  long_description_content_type = text/markdown
@@ -13,7 +13,7 @@ Examples
13
13
 
14
14
  """
15
15
 
16
- __version__ = '0.7.1'
16
+ __version__ = '0.7.3'
17
17
 
18
18
  from .config import options, get_option, set_option, describe_option
19
19
  from .connection import connect, apilevel, threadsafety, paramstyle
@@ -230,3 +230,10 @@ register_option(
230
230
  'Print queries and parameters to stderr.',
231
231
  environ='SINGLESTOREDB_DEBUG_QUERIES',
232
232
  )
233
+
234
+
235
+ register_option(
236
+ 'debug.connection', 'bool', check_bool, False,
237
+ 'Print connection tracing information.',
238
+ environ='SINGLESTOREDB_DEBUG_CONNECTION',
239
+ )
@@ -16,8 +16,10 @@ except ImportError:
16
16
  from functools import partial
17
17
  import hashlib
18
18
 
19
+ from ..config import get_option
19
20
 
20
- DEBUG = False
21
+
22
+ DEBUG = get_option('debug.connection')
21
23
  SCRAMBLE_LENGTH = 20
22
24
  sha1_new = partial(hashlib.new, 'sha1')
23
25
 
@@ -1031,10 +1031,10 @@ static unsigned long long read_length_encoded_integer(
1031
1031
  if (is_null) *is_null = 1;
1032
1032
  return 0;
1033
1033
  }
1034
- uint16_t low = **(uint8_t**)data;
1035
- *data += 1; *data_l -= 1;
1036
- uint16_t high = **(uint16_t**)data;
1034
+ uint16_t low = **(uint16_t**)data;
1037
1035
  *data += 2; *data_l -= 2;
1036
+ uint8_t high = **(uint8_t**)data;
1037
+ *data += 1; *data_l -= 1;
1038
1038
  return low + (high << 16);
1039
1039
  }
1040
1040
 
@@ -46,6 +46,7 @@ from .protocol import (
46
46
  LoadLocalPacketWrapper,
47
47
  )
48
48
  from . import err
49
+ from ..config import get_option
49
50
  from ..connection import Connection as BaseConnection
50
51
 
51
52
  try:
@@ -65,7 +66,7 @@ except (ImportError, KeyError):
65
66
  # KeyError occurs when there's no entry in OS database for a current user.
66
67
  DEFAULT_USER = None
67
68
 
68
- DEBUG = False
69
+ DEBUG = get_option('debug.connection')
69
70
 
70
71
  TEXT_TYPES = {
71
72
  FIELD_TYPE.BIT,
@@ -5,13 +5,14 @@ import struct
5
5
  import sys
6
6
 
7
7
  from . import err
8
+ from ..config import get_option
8
9
  from ..utils.results import Description
9
10
  from .charset import MBLENGTH
10
11
  from .constants import FIELD_TYPE
11
12
  from .constants import SERVER_STATUS
12
13
 
13
14
 
14
- DEBUG = False
15
+ DEBUG = get_option('debug.connection')
15
16
 
16
17
  NULL_COLUMN = 251
17
18
  UNSIGNED_CHAR_COLUMN = 251
@@ -0,0 +1,283 @@
1
+ #!/usr/bin/env python
2
+ """Pytest plugin"""
3
+ import logging
4
+ import os
5
+ import subprocess
6
+ import time
7
+ from enum import Enum
8
+ from typing import Iterator
9
+ from typing import Optional
10
+
11
+ import pytest
12
+
13
+ from . import connect
14
+ from .connection import Connection
15
+ from .connection import Cursor
16
+
17
+
18
+ logger = logging.getLogger(__name__)
19
+
20
+
21
+ # How many times to attempt to connect to the container
22
+ STARTUP_CONNECT_ATTEMPTS = 10
23
+ # How long to wait between connection attempts
24
+ STARTUP_CONNECT_TIMEOUT_SECONDS = 2
25
+ # How many times to check if all connections are closed
26
+ TEARDOWN_WAIT_ATTEMPTS = 20
27
+ # How long to wait between checking connections
28
+ TEARDOWN_WAIT_SECONDS = 2
29
+
30
+
31
+ class ExecutionMode(Enum):
32
+ SEQUENTIAL = 1
33
+ LEADER = 2
34
+ FOLLOWER = 3
35
+
36
+
37
+ @pytest.fixture(scope='session')
38
+ def execution_mode() -> ExecutionMode:
39
+ """Determine the pytest mode for this process"""
40
+
41
+ worker = os.environ.get('PYTEST_XDIST_WORKER')
42
+ worker_count = os.environ.get('PYTEST_XDIST_WORKER_COUNT')
43
+
44
+ # If we're not in pytest-xdist, the mode is Sequential
45
+ if worker is None or worker_count is None:
46
+ logger.debug('XDIST environment vars not found')
47
+ return ExecutionMode.SEQUENTIAL
48
+
49
+ logger.debug(f'PYTEST_XDIST_WORKER == {worker}')
50
+ logger.debug(f'PYTEST_XDIST_WORKER_COUNT == {worker_count}')
51
+
52
+ # If we're the only worker, than the mode is Sequential
53
+ if worker_count == '1':
54
+ return ExecutionMode.SEQUENTIAL
55
+ else:
56
+ # The first worker (named "gw0") is the leader
57
+ # if there are multiple workers
58
+ if worker == 'gw0':
59
+ return ExecutionMode.LEADER
60
+ else:
61
+ return ExecutionMode.FOLLOWER
62
+
63
+
64
+ @pytest.fixture(scope='session')
65
+ def node_name() -> Iterator[str]:
66
+ """Determine the name of this worker node"""
67
+
68
+ worker = os.environ.get('PYTEST_XDIST_WORKER')
69
+
70
+ if worker is None:
71
+ logger.debug('XDIST environment vars not found')
72
+ yield 'master'
73
+ else:
74
+ logger.debug(f'PYTEST_XDIST_WORKER == {worker}')
75
+ yield worker
76
+
77
+
78
+ class _TestContainerManager():
79
+ """Manages the setup and teardown of a SingleStoreDB Dev Container"""
80
+
81
+ def __init__(self) -> None:
82
+ self.container_name = 'singlestoredb-test-container'
83
+ self.dev_image_name = 'ghcr.io/singlestore-labs/singlestoredb-dev'
84
+
85
+ assert 'SINGLESTORE_LICENSE' in os.environ, 'SINGLESTORE_LICENSE not set'
86
+
87
+ self.root_password = 'Q8r4D7yXR8oqn'
88
+ self.environment_vars = {
89
+ 'SINGLESTORE_LICENSE': None,
90
+ 'ROOT_PASSWORD': f"\"{self.root_password}\"",
91
+ 'SINGLESTORE_SET_GLOBAL_DEFAULT_PARTITIONS_PER_LEAF': '1',
92
+ }
93
+
94
+ self.ports = ['3306', '8080', '9000']
95
+
96
+ self.url = f'root:{self.root_password}@127.0.0.1:3306'
97
+
98
+ def start(self) -> None:
99
+ command = ' '.join(self._start_command())
100
+
101
+ logger.info(f'Starting container {self.container_name}')
102
+ try:
103
+ license = os.environ['SINGLESTORE_LICENSE']
104
+ env = {
105
+ 'SINGLESTORE_LICENSE': license,
106
+ }
107
+ subprocess.check_call(command, shell=True, env=env)
108
+ except Exception as e:
109
+ logger.exception(e)
110
+ raise RuntimeError(
111
+ 'Failed to start container. '
112
+ 'Is one already running?',
113
+ ) from e
114
+ logger.debug('Container started')
115
+
116
+ def _start_command(self) -> Iterator[str]:
117
+ yield 'docker run -d --name'
118
+ yield self.container_name
119
+ for key, value in self.environment_vars.items():
120
+ yield '-e'
121
+ if value is None:
122
+ yield key
123
+ else:
124
+ yield f'{key}={value}'
125
+
126
+ for port in self.ports:
127
+ yield '-p'
128
+ yield f'{port}:{port}'
129
+
130
+ yield self.dev_image_name
131
+
132
+ def print_logs(self) -> None:
133
+ logs_command = ['docker', 'logs', self.container_name]
134
+ logger.info('Getting logs')
135
+ logger.info(subprocess.check_output(logs_command))
136
+
137
+ def connect(self) -> Connection:
138
+ # Run all but one attempts trying again if they fail
139
+ for i in range(STARTUP_CONNECT_ATTEMPTS - 1):
140
+ try:
141
+ return connect(self.url)
142
+ except Exception:
143
+ logger.debug(f'Database not available yet (attempt #{i}).')
144
+ time.sleep(STARTUP_CONNECT_TIMEOUT_SECONDS)
145
+ else:
146
+ # Try one last time and report error if it fails
147
+ try:
148
+ return connect(self.url)
149
+ except Exception as e:
150
+ logger.error('Timed out while waiting to connect to database.')
151
+ logger.exception(e)
152
+ self.print_logs()
153
+ raise RuntimeError('Failed to connect to database') from e
154
+
155
+ def wait_till_connections_closed(self) -> None:
156
+ heart_beat = connect(self.url)
157
+ for i in range(TEARDOWN_WAIT_ATTEMPTS):
158
+ connections = self.get_open_connections(heart_beat)
159
+ if connections is None:
160
+ raise RuntimeError('Could not determine the number of open connections.')
161
+ logger.debug(
162
+ f'Waiting for other connections (n={connections-1}) '
163
+ f'to close (attempt #{i})',
164
+ )
165
+ time.sleep(TEARDOWN_WAIT_SECONDS)
166
+ else:
167
+ logger.warning('Timed out while waiting for other connections to close')
168
+ self.print_logs()
169
+
170
+ def get_open_connections(self, conn: Connection) -> Optional[int]:
171
+ for row in conn.show.status(extended=True):
172
+ name = row['Name']
173
+ value = row['Value']
174
+ logger.info(f'{name} = {value}')
175
+ if name == 'Threads_connected':
176
+ return int(value)
177
+
178
+ return None
179
+
180
+ def stop(self) -> None:
181
+ logger.info('Cleaning up SingleStore DB dev container')
182
+ logger.debug('Stopping container')
183
+ try:
184
+ subprocess.check_call(f'docker stop {self.container_name}', shell=True)
185
+ except Exception as e:
186
+ logger.exception(e)
187
+ raise RuntimeError('Failed to stop container.') from e
188
+
189
+ logger.debug('Removing container')
190
+ try:
191
+ subprocess.check_call(f'docker rm {self.container_name}', shell=True)
192
+ except Exception as e:
193
+ logger.exception(e)
194
+ raise RuntimeError('Failed to stop container.') from e
195
+
196
+
197
+ @pytest.fixture(scope='session')
198
+ def singlestoredb_test_container(
199
+ execution_mode: ExecutionMode,
200
+ ) -> Iterator[_TestContainerManager]:
201
+ """Sets up and tears down the test container"""
202
+
203
+ if not isinstance(execution_mode, ExecutionMode):
204
+ raise TypeError(f"Invalid execution mode '{execution_mode}'")
205
+
206
+ container_manager = _TestContainerManager()
207
+
208
+ # In sequential operation do all the steps
209
+ if execution_mode == ExecutionMode.SEQUENTIAL:
210
+ logger.debug('Not distributed')
211
+ container_manager.start()
212
+ yield container_manager
213
+ container_manager.stop()
214
+
215
+ # In distributed execution as leader,
216
+ # do the steps but wait for other workers before stopping
217
+ elif execution_mode == ExecutionMode.LEADER:
218
+ logger.debug('Distributed leader')
219
+ container_manager.start()
220
+ yield container_manager
221
+ container_manager.wait_till_connections_closed()
222
+ container_manager.stop()
223
+
224
+ # In distributed exeuction as a non-leader,
225
+ # don't worry about the container lifecycle
226
+ elif execution_mode == ExecutionMode.FOLLOWER:
227
+ logger.debug('Distributed follower')
228
+ yield container_manager
229
+
230
+
231
+ @pytest.fixture(scope='session')
232
+ def singlestoredb_connection(
233
+ singlestoredb_test_container: _TestContainerManager,
234
+ ) -> Iterator[Connection]:
235
+ """Creates and closes the connection"""
236
+
237
+ connection = singlestoredb_test_container.connect()
238
+ logger.debug('Connected to database.')
239
+
240
+ yield connection
241
+
242
+ logger.debug('Closing connection')
243
+ connection.close()
244
+
245
+
246
+ class _NameAllocator():
247
+ """Generates unique names for each database"""
248
+
249
+ def __init__(self, id: str) -> None:
250
+ self.id = id
251
+ self.names = 0
252
+
253
+ def get_name(self) -> str:
254
+ name = f'x_db_{self.id}_{self.names}'
255
+ self.names += 1
256
+ return name
257
+
258
+
259
+ @pytest.fixture(scope='session')
260
+ def name_allocator(node_name: str) -> Iterator[_NameAllocator]:
261
+ """Makes a worker-local name allocator using the node name"""
262
+
263
+ yield _NameAllocator(node_name)
264
+
265
+
266
+ @pytest.fixture
267
+ def singlestoredb_tempdb(
268
+ singlestoredb_connection: Connection, name_allocator: _NameAllocator,
269
+ ) -> Iterator[Cursor]:
270
+ """Provides a connection to a unique temporary test database"""
271
+
272
+ assert singlestoredb_connection.is_connected(), 'Database is no longer connected'
273
+ db = name_allocator.get_name()
274
+
275
+ with singlestoredb_connection.cursor() as cursor:
276
+ logger.debug(f"Creating temporary DB \"{db}\"")
277
+ cursor.execute(f'CREATE DATABASE {db}')
278
+ cursor.execute(f'USE {db}')
279
+
280
+ yield cursor
281
+
282
+ logger.debug(f"Dropping temporary DB \"{db}\"")
283
+ cursor.execute(f'DROP DATABASE {db}')
@@ -4,6 +4,7 @@
4
4
  import datetime
5
5
  import decimal
6
6
  import os
7
+ import string
7
8
  import unittest
8
9
 
9
10
  try:
@@ -1105,6 +1106,59 @@ class TestBasics(unittest.TestCase):
1105
1106
  self.cur.execute(f"SELECT 1999 :> YEAR, '{string}'")
1106
1107
  self.assertEqual((1999, string), self.cur.fetchone())
1107
1108
 
1109
+ def test_character_lengths(self):
1110
+ if self.conn.driver in ['http', 'https']:
1111
+ self.skipTest('Response size too big for http')
1112
+
1113
+ test_id = id(self)
1114
+ self.cur.execute(rf'''
1115
+ CREATE TABLE `test_character_lengths_{test_id}` (
1116
+ `id` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
1117
+ `char_col` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
1118
+ `int_col` INT,
1119
+ PRIMARY KEY (`id`),
1120
+ SORT KEY `id` (`id`)
1121
+ ) AUTOSTATS_CARDINALITY_MODE=INCREMENTAL
1122
+ AUTOSTATS_HISTOGRAM_MODE=CREATE
1123
+ AUTOSTATS_SAMPLING=ON
1124
+ SQL_MODE='STRICT_ALL_TABLES'
1125
+ ''')
1126
+ CHAR_STR = string.ascii_letters * 1
1127
+ SHORT_STR = string.ascii_letters * 10
1128
+ INT24_STR = string.ascii_letters * 1500
1129
+ INT64_STR = string.ascii_letters * 1500000
1130
+ data = [
1131
+ ['CHAR', CHAR_STR, 123456],
1132
+ ['SHORT', SHORT_STR, 123456],
1133
+ ['INT24', INT24_STR, 123456],
1134
+ ['INT64', INT64_STR, 123456],
1135
+ ]
1136
+ self.cur.executemany(
1137
+ f'INSERT INTO test_character_lengths_{test_id}(id, char_col, int_col) '
1138
+ 'VALUES (%s, %s, %s)', data,
1139
+ )
1140
+ self.cur.execute(
1141
+ f'SELECT id, char_col, int_col FROM test_character_lengths_{test_id} '
1142
+ 'WHERE id = "CHAR"',
1143
+ )
1144
+ assert data[0] == list(list(self.cur)[0])
1145
+ self.cur.execute(
1146
+ f'SELECT id, char_col, int_col FROM test_character_lengths_{test_id} '
1147
+ 'WHERE id = "SHORT"',
1148
+ )
1149
+ assert data[1] == list(list(self.cur)[0])
1150
+ self.cur.execute(
1151
+ f'SELECT id, char_col, int_col FROM test_character_lengths_{test_id} '
1152
+ 'WHERE id = "INT24"',
1153
+ )
1154
+ assert data[2] == list(list(self.cur)[0])
1155
+ self.cur.execute(
1156
+ f'SELECT id, char_col, int_col FROM test_character_lengths_{test_id} '
1157
+ 'WHERE id = "INT64"',
1158
+ )
1159
+ assert data[3] == list(list(self.cur)[0])
1160
+ self.cur.execute(rf'DROP TABLE `test_character_lengths_{test_id}`')
1161
+
1108
1162
 
1109
1163
  if __name__ == '__main__':
1110
1164
  import nose2
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: singlestoredb
3
- Version: 0.7.1
3
+ Version: 0.7.3
4
4
  Summary: Interface to the SingleStore database and cluster management APIs
5
5
  Home-page: https://github.com/singlestore-labs/singlestoredb-python
6
6
  Author: SingleStore
@@ -8,6 +8,7 @@ singlestoredb/config.py
8
8
  singlestoredb/connection.py
9
9
  singlestoredb/converters.py
10
10
  singlestoredb/exceptions.py
11
+ singlestoredb/pytest.py
11
12
  singlestoredb/types.py
12
13
  singlestoredb.egg-info/PKG-INFO
13
14
  singlestoredb.egg-info/SOURCES.txt
File without changes
File without changes
File without changes