Skip to content

Commit 06c3c14

Browse files
committed
Skip SQL tests if tarantool version < 2.0.0
Problem: all SQL-related tests fail with the following error if tarantool < 2.0.0 is used: tarantool.error.DatabaseError: (48, 'Unknown request type 11') Tarantool supports SQL-related stuff only since the 2.0.0 version. So this patch adds a special decorator that will skip the test if tarantool version < 2.0.0 is used.
1 parent 6140342 commit 06c3c14

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

test/suites/lib/skip.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import functools
2+
import pkg_resources
3+
import re
4+
5+
SQL_SUPPORT_TNT_VERSION = '2.0.0'
6+
7+
8+
def skip_or_run_sql_test(func):
9+
"""Decorator to skip or run SQL-related test depending on tarantool version.
10+
11+
Tarantool supports SQL-related stuff only since 2.0.0 version. So this
12+
decorator should wrap every SQL-related test to skip it if the tarantool
13+
version < 2.0.0 is used for testing.
14+
"""
15+
16+
@functools.wraps(func)
17+
def wrapper(self, *args, **kwargs):
18+
if not hasattr(self, 'tnt_version'):
19+
self.__class__.tnt_version = re.match(
20+
r'[\d.]+', self.srv.admin('box.info.version')[0]
21+
).group()
22+
23+
tnt_version = pkg_resources.parse_version(self.tnt_version)
24+
sql_support_tnt_version = pkg_resources.parse_version(
25+
SQL_SUPPORT_TNT_VERSION
26+
)
27+
28+
if tnt_version < sql_support_tnt_version:
29+
self.skipTest(
30+
'Tarantool %s does not support SQL' % self.tnt_version
31+
)
32+
else:
33+
func(self, *args, **kwargs)
34+
35+
return wrapper

test/suites/test_dbapi.py

+42
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import tarantool
1111
from tarantool import dbapi
1212
from .lib.tarantool_server import TarantoolServer
13+
from .lib.skip import skip_or_run_sql_test
1314

1415

1516
class TestSuite_DBAPI(dbapi20.DatabaseAPI20Test):
@@ -50,6 +51,47 @@ def tearDownClass(self):
5051
self.srv.stop()
5152
self.srv.clean()
5253

54+
@skip_or_run_sql_test
55+
def test_None(self):
56+
super(TestSuite_DBAPI, self).test_None()
57+
58+
@skip_or_run_sql_test
59+
def test_cursor_isolation(self):
60+
super(TestSuite_DBAPI, self).test_cursor_isolation()
61+
62+
@skip_or_run_sql_test
63+
def test_execute(self):
64+
super(TestSuite_DBAPI, self).test_execute()
65+
66+
@skip_or_run_sql_test
67+
def test_executemany(self):
68+
super(TestSuite_DBAPI, self).test_executemany()
69+
70+
@skip_or_run_sql_test
71+
def test_fetchall(self):
72+
super(TestSuite_DBAPI, self).test_fetchall()
73+
74+
@skip_or_run_sql_test
75+
def test_fetchmany(self):
76+
super(TestSuite_DBAPI, self).test_fetchmany()
77+
78+
@skip_or_run_sql_test
79+
def test_fetchone(self):
80+
super(TestSuite_DBAPI, self).test_fetchone()
81+
82+
@skip_or_run_sql_test
83+
def test_mixedfetch(self):
84+
super(TestSuite_DBAPI, self).test_mixedfetch()
85+
86+
@skip_or_run_sql_test
87+
def test_setinputsizes(self):
88+
super(TestSuite_DBAPI, self).test_setinputsizes()
89+
90+
@skip_or_run_sql_test
91+
def test_setoutputsize_basic(self):
92+
super(TestSuite_DBAPI, self).test_setoutputsize_basic()
93+
94+
@skip_or_run_sql_test
5395
def test_rowcount(self):
5496
con = self._connect()
5597
try:

test/suites/test_execute.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
import tarantool
99
from .lib.tarantool_server import TarantoolServer
10+
from .lib.skip import skip_or_run_sql_test
1011

1112

1213
class TestSuite_Execute(unittest.TestCase):
1314
ddl = 'create table %s (id INTEGER PRIMARY KEY AUTOINCREMENT, ' \
14-
'name varchar(20))'
15+
'name varchar(20))'
1516

1617
dml_params = [
1718
{'id': None, 'name': 'Michael'},
@@ -54,6 +55,7 @@ def _populate_data(self, table_name):
5455
def _create_table(self, table_name):
5556
return self.con.execute(self.ddl % table_name)
5657

58+
@skip_or_run_sql_test
5759
def test_dml_response(self):
5860
table_name = 'foo'
5961
response = self._create_table(table_name)
@@ -75,6 +77,7 @@ def test_dml_response(self):
7577
self.assertEqual(response.affected_row_count, 2)
7678
self.assertEqual(response.data, None)
7779

80+
@skip_or_run_sql_test
7881
def test_dql_response(self):
7982
table_name = 'bar'
8083
self._create_table(table_name)

0 commit comments

Comments
 (0)