Skip to content

Commit 9d2cf65

Browse files
WIP on gh-105-unpack-binary: 0f95f28 Skip SQL tests if tarantool version < 2.0.0
2 parents 0f95f28 + fd7deaf commit 9d2cf65

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

test/suites/test_dml.py

+86
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
import sys
66
import unittest
7+
78
import tarantool
89

910
from .lib.tarantool_server import TarantoolServer
1011

12+
1113
class TestSuite_Request(unittest.TestCase):
1214
@classmethod
1315
def setUpClass(self):
@@ -31,17 +33,65 @@ def setUpClass(self):
3133
parts = {2, 'num', 3, 'str'},
3234
unique = false})
3335
""".replace('\n', ' '))
36+
3437
self.space_created = self.adm("box.schema.create_space('space_2')")
3538
self.adm("""
3639
box.space['space_2']:create_index('primary', {
3740
type = 'hash',
3841
parts = {1, 'num'},
3942
unique = true})
4043
""".replace('\n', ' '))
44+
45+
self.adm("box.schema.create_space('space_str')")
46+
self.adm("""
47+
box.space['space_str']:create_index('primary', {
48+
type = 'tree',
49+
parts = {1, 'str'},
50+
unique = true})
51+
""".replace('\n', ' '))
52+
53+
self.adm("box.schema.create_space('space_varbin')")
54+
self.adm("""
55+
box.space['space_varbin']:create_index('primary', {
56+
type = 'tree',
57+
parts = {1, 'varbinary'},
58+
unique = true})
59+
""".replace('\n', ' '))
60+
self.adm("""
61+
buffer = require('buffer')
62+
ffi = require('ffi')
63+
64+
function encode_bin(bytes)
65+
local tmpbuf = buffer.ibuf()
66+
local p = tmpbuf:alloc(3 + #bytes)
67+
p[0] = 0x91
68+
p[1] = 0xC4
69+
p[2] = #bytes
70+
for i, c in pairs(bytes) do
71+
p[i + 3 - 1] = c
72+
end
73+
return tmpbuf
74+
end
75+
76+
function bintuple_insert(space, bytes)
77+
local tmpbuf = encode_bin(bytes)
78+
ffi.cdef[[
79+
int box_insert(uint32_t space_id, const char *tuple, const char *tuple_end, box_tuple_t **result);
80+
]]
81+
ffi.C.box_insert(space.id, tmpbuf.rpos, tmpbuf.wpos, nil)
82+
end
83+
""")
4184
self.adm("json = require('json')")
4285
self.adm("fiber = require('fiber')")
4386
self.adm("uuid = require('uuid')")
4487

88+
@classmethod
89+
def assertNotRaises(self, func, *args, **kwargs):
90+
try:
91+
func(*args, **kwargs)
92+
except Exception as e:
93+
self.fail(f'Function raised Exception: {repr(e)}')
94+
4595
def setUp(self):
4696
# prevent a remote tarantool from clean our session
4797
if self.srv.is_started():
@@ -299,6 +349,42 @@ def test_12_update_fields(self):
299349
[[2, 'help', 7]]
300350
)
301351

352+
def test_13_string_insert_default_behavior(self):
353+
self.assertNotRaises(self.con.insert, 'space_str', [ 'test_13_string_insert_default_behavior' ])
354+
355+
def test_14_string_select_default_behavior(self):
356+
self.adm(r"box.space['space_str']:insert{test_14_string_select_default_behavior}")
357+
# resp = self.con.select('space_str', ['test_14_string_select_default_behavior'])
358+
# self.assertIsInstance(resp, str)
359+
self.assertSequenceEqual(
360+
self.con.select('space_str', ['test_14_string_select_default_behavior']),
361+
[['test_14_string_select_default_behavior']])
362+
363+
364+
# def test_14_utf_string_select_default_behavior(self):
365+
# self.assertNotRaises(self.con.insert, 'space_str', [ 'test_13_string_insert_default_behavior' ])
366+
367+
# self.assertSequenceEqual(
368+
# self.con.insert('space_varbin', [ b'test_13_binary_default_behavior' ]),
369+
# [[ b'test_13_binary_default_behavior' ]])
370+
371+
# def test_14_string_select_default_behavior(self):
372+
# self.adm(r"""
373+
# bintuple_insert(box.space['space_varbin'], {0x13})
374+
# """)]
375+
# self.assertSequenceEqual(
376+
# self.con.insert('space_str', [ 'test_13_binary_default_behavior' ]),
377+
# [[ 'test_13_binary_default_behavior' ]])
378+
379+
# self.assertSequenceEqual(
380+
# self.con.insert('space_varbin', [ b'test_13_binary_default_behavior' ]),
381+
# [[ b'test_13_binary_default_behavior' ]])
382+
383+
# def test_14_binary_binary_mode_behavior(self):
384+
# self.adm(r"""
385+
# bintuple_insert(box.space['space_varbin'], {0x14})
386+
# """)
387+
302388
@classmethod
303389
def tearDownClass(self):
304390
self.con.close()

0 commit comments

Comments
 (0)