Skip to content

Commit 9feaada

Browse files
committed
Add string length tests
1 parent e7582dc commit 9feaada

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

singlestoredb/tests/test_basics.py

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import decimal
66
import math
77
import os
8-
import string
98
import unittest
109

1110
from requests.exceptions import InvalidJSONError
@@ -1202,9 +1201,11 @@ def test_character_lengths(self):
12021201
if 'http' in self.conn.driver:
12031202
self.skipTest('Character lengths too long for HTTP interface')
12041203

1204+
tbl_id = str(id(self))
1205+
12051206
self.cur.execute('DROP TABLE IF EXISTS test_character_lengths')
1206-
self.cur.execute(r'''
1207-
CREATE TABLE `test_character_lengths` (
1207+
self.cur.execute(rf'''
1208+
CREATE TABLE `test_character_lengths_{tbl_id}` (
12081209
`id` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
12091210
`char_col` longtext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
12101211
`int_col` INT,
@@ -1216,46 +1217,43 @@ def test_character_lengths(self):
12161217
SQL_MODE='STRICT_ALL_TABLES'
12171218
''')
12181219

1219-
CHAR_STR = string.ascii_letters * 1
1220-
SHORT_STR = string.ascii_letters * 10
1221-
INT24_STR = string.ascii_letters * 1500
1222-
INT64_STR = string.ascii_letters * 1500000
1220+
CHAR_STR_SHORT = 'a'
1221+
CHAR_STR_LONG = 'a' * (2**8-1)
1222+
SHORT_STR_SHORT = 'a' * ((2**8-1) + 1)
1223+
SHORT_STR_LONG = 'a' * (2**16-1)
1224+
INT24_STR_SHORT = 'a' * ((2**16-1) + 1)
1225+
INT24_STR_LONG = 'a' * (2**24-1)
1226+
INT64_STR_SHORT = 'a' * ((2**24-1) + 1)
1227+
INT64_STR_LONG = 'a' * ((2**24-1) + 100000)
12231228

12241229
data = [
1225-
['CHAR', CHAR_STR, 123456],
1226-
['SHORT', SHORT_STR, 123456],
1227-
['INT24', INT24_STR, 123456],
1228-
['INT64', INT64_STR, 123456],
1230+
['CHAR_SHORT', CHAR_STR_SHORT, 123456],
1231+
['CHAR_LONG', CHAR_STR_LONG, 123456],
1232+
['SHORT_SHORT', SHORT_STR_SHORT, 123456],
1233+
['SHORT_LONG', SHORT_STR_LONG, 123456],
1234+
['INT24_SHORT', INT24_STR_SHORT, 123456],
1235+
['INT24_LONG', INT24_STR_LONG, 123456],
1236+
['INT64_SHORT', INT64_STR_SHORT, 123456],
1237+
['INT64_LONG', INT64_STR_LONG, 123456],
12291238
]
12301239

12311240
self.cur.executemany(
1232-
'INSERT INTO test_character_lengths(id, char_col, int_col) '
1241+
f'INSERT INTO test_character_lengths_{tbl_id}(id, char_col, int_col) '
12331242
'VALUES (%s, %s, %s)', data,
12341243
)
12351244

1236-
self.cur.execute(
1237-
'SELECT id, char_col, int_col FROM test_character_lengths '
1238-
'WHERE id = "CHAR"',
1239-
)
1240-
assert data[0] == list(list(self.cur)[0])
1241-
1242-
self.cur.execute(
1243-
'SELECT id, char_col, int_col FROM test_character_lengths '
1244-
'WHERE id = "SHORT"',
1245-
)
1246-
assert data[1] == list(list(self.cur)[0])
1247-
1248-
self.cur.execute(
1249-
'SELECT id, char_col, int_col FROM test_character_lengths '
1250-
'WHERE id = "INT24"',
1251-
)
1252-
assert data[2] == list(list(self.cur)[0])
1245+
for i, row in enumerate(data):
1246+
self.cur.execute(
1247+
f'SELECT id, char_col, int_col FROM test_character_lengths_{tbl_id} '
1248+
'WHERE id = %s',
1249+
[row[0]],
1250+
)
1251+
assert data[i] == list(list(self.cur)[0])
12531252

1254-
self.cur.execute(
1255-
'SELECT id, char_col, int_col FROM test_character_lengths '
1256-
'WHERE id = "INT64"',
1257-
)
1258-
assert data[3] == list(list(self.cur)[0])
1253+
try:
1254+
self.cur.execute(f'DROP TABLE test_character_lengths_{tbl_id}')
1255+
except Exception:
1256+
pass
12591257

12601258

12611259
if __name__ == '__main__':

0 commit comments

Comments
 (0)