Skip to content

Commit b90eef6

Browse files
committed
Fix python3 tests and compatibility
1 parent fffdaa7 commit b90eef6

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

tarantool/schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, index_row, space):
2222
self.parts = []
2323
if isinstance(index_row[5], (list, tuple)):
2424
for k, v in index_row[5]:
25-
self.parts.append(k, v)
25+
self.parts.append((k, v))
2626
else:
2727
for i in range(index_row[5]):
2828
self.parts.append((index_row[5 + 1 + i * 2], index_row[5 + 2 + i * 2]))
@@ -100,13 +100,13 @@ def get_index(self, space, index):
100100

101101
index_row = None
102102
try:
103-
index_row = self.con.select(const.SPACE_VSPACE, [_space.sid, index],
103+
index_row = self.con.select(const.SPACE_VINDEX, [_space.sid, index],
104104
index=_index)
105105
except DatabaseError as e:
106106
if e.args[0] != 36:
107107
raise
108108
if index_row is None:
109-
index_row = self.con.select(const.SPACE_SPACE, [_space.sid, index],
109+
index_row = self.con.select(const.SPACE_INDEX, [_space.sid, index],
110110
index=_index)
111111

112112
if len(index_row) > 1:

tarantool/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Greeting:
3737
# Tarantool 1.6.8-132-g82f5424 (Lua console)
3838
result = Greeting()
3939
try:
40-
(product, _, tail) = greeting_buf[0:63].partition(' ')
40+
(product, _, tail) = str(greeting_buf)[0:63].partition(' ')
4141
if product.startswith("Tarantool "):
4242
raise Exception()
4343
# Parse a version string - 1.6.6-83-gc6b2129 or 1.6.7
@@ -64,4 +64,4 @@ class Greeting:
6464
return result
6565
except Exception as e:
6666
print('exx', e)
67-
raise ValueError("Invalid greeting: " + greeting_buf)
67+
raise ValueError("Invalid greeting: " + str(greeting_buf))

tests/suites/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
__tmp = os.getcwd()
55
os.chdir(os.path.abspath(os.path.dirname(__file__)))
66

7-
from test_schema import TestSuite_Schema
8-
from test_dml import Request
7+
from .test_schema import TestSuite_Schema
8+
from .test_dml import TestSuite_Request
9+
from .test_protocol import TestSuite_Protocol
910

10-
test_cases = (TestSuite_Schema, Request)
11+
test_cases = (TestSuite_Schema, TestSuite_Request, TestSuite_Protocol)
1112

1213
def load_tests(loader, tests, pattern):
1314
suite = unittest.TestSuite()
1415
for testc in test_cases:
1516
suite.addTests(loader.loadTestsFromTestCase(testc))
1617
return suite
17-
18+
1819

1920
os.chdir(__tmp)
2021

tests/suites/test_dml.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import yaml
55
import unittest
66
import tarantool
7-
from lib.tarantool_server import TarantoolServer
7+
from .lib.tarantool_server import TarantoolServer
88

9-
class Request(unittest.TestCase):
9+
class TestSuite_Request(unittest.TestCase):
1010
@classmethod
1111
def setUpClass(self):
1212
print(' DML '.center(70, '='))
@@ -134,12 +134,10 @@ def test_07_call(self):
134134
self.assertEqual(self.con.call('json.decode', '[123, 234, 345]'), [[123, 234, 345]])
135135
self.assertEqual(self.con.call('json.decode', ['[123, 234, 345]']), [[123, 234, 345]])
136136
self.assertEqual(self.con.call('json.decode', ('[123, 234, 345]',)), [[123, 234, 345]])
137-
with self.assertRaisesRegexp(tarantool.DatabaseError,
138-
'(32, .*)'):
137+
with self.assertRaisesRegexp(tarantool.DatabaseError, '(32, .*)'):
139138
self.con.call('json.decode')
140-
with self.assertRaisesRegexp(tarantool.DatabaseError,
141-
'(22, .*)'):
142-
self.con.call('json.decode', '{"hello": "world"}')
139+
with self.assertRaisesRegexp(tarantool.DatabaseError, '(32, .*)'):
140+
self.con.call('json.decode', '{[1, 2]: "world"}')
143141
ans = self.con.call('fiber.time')
144142
self.assertEqual(len(ans), 1)
145143
self.assertEqual(len(ans[0]), 1)

tests/suites/test_protocol.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
import uuid
66

77
class TestSuite_Protocol(unittest.TestCase):
8+
@classmethod
9+
def setUpClass(self):
10+
print(' PROTOCOL '.center(70, '='))
11+
print('-' * 70)
812

913
def test_00_greeting_1_6(self):
1014
buf = "Tarantool 1.6.6 \n" + \
1115
"AtQnb9SAIaKazZZy9lJKvK3urtbjCEJndhRVbslSPGc= \n";
12-
greeting = greeting_decode(buf)
16+
greeting = greeting_decode(buf.encode())
1317
self.assertEqual(greeting.version_id, version_id(1, 6, 6))
1418
self.assertEqual(greeting.protocol, "Binary")
1519
self.assertIsNone(greeting.uuid)
@@ -18,7 +22,7 @@ def test_00_greeting_1_6(self):
1822
def test_01_greeting_1_6_with_tag(self):
1923
buf = "Tarantool 1.6.6-232-gcf47324 \n" + \
2024
"AtQnb9SAIaKazZZy9lJKvK3urtbjCEJndhRVbslSPGc= \n";
21-
greeting = greeting_decode(buf)
25+
greeting = greeting_decode(buf.encode())
2226
self.assertEqual(greeting.version_id, version_id(1, 6, 6))
2327
self.assertEqual(greeting.protocol, "Binary")
2428
self.assertIsNone(greeting.uuid)
@@ -27,7 +31,7 @@ def test_01_greeting_1_6_with_tag(self):
2731
def test_02_greeting_1_6_console(self):
2832
buf = "Tarantool 1.6.6-132-g82f5424 (Lua console) \n" + \
2933
"type 'help' for interactive help \n";
30-
greeting = greeting_decode(buf)
34+
greeting = greeting_decode(buf.encode())
3135
self.assertEqual(greeting.version_id, version_id(1, 6, 6))
3236
self.assertEqual(greeting.protocol, "Lua console")
3337
self.assertIsNone(greeting.uuid)
@@ -36,7 +40,7 @@ def test_02_greeting_1_6_console(self):
3640
def test_03_greeting_1_6_7(self):
3741
buf = "Tarantool 1.6.7 (Binary) 52dc2837-8001-48fe-bdce-c493c04599ce \n" + \
3842
"Z+2F+VRlyK1nKT82xQtxqEggMtkTK5RtPYf27JryRas= \n";
39-
greeting = greeting_decode(buf)
43+
greeting = greeting_decode(buf.encode())
4044
self.assertEqual(greeting.version_id, version_id(1, 6, 7))
4145
self.assertEqual(greeting.protocol, "Binary")
4246
self.assertEqual(greeting.uuid,

tests/suites/test_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import unittest
44
import tarantool
5-
from lib.tarantool_server import TarantoolServer
5+
from .lib.tarantool_server import TarantoolServer
66

77
class TestSuite_Schema(unittest.TestCase):
88
@classmethod

0 commit comments

Comments
 (0)