Skip to content

Commit 0f95f28

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. Fixes #194
1 parent 6140342 commit 0f95f28

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

Diff for: test/suites/lib/skip.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 tests depending on the tarantool
10+
version.
11+
12+
Tarantool supports SQL-related stuff only since 2.0.0 version. So this
13+
decorator should wrap every SQL-related test to skip it if the tarantool
14+
version < 2.0.0 is used for testing.
15+
16+
Also, it can be used with the 'setUp' method for skipping the whole test
17+
suite.
18+
"""
19+
20+
@functools.wraps(func)
21+
def wrapper(self, *args, **kwargs):
22+
if func.__name__ == 'setUp':
23+
func(self, *args, **kwargs)
24+
25+
if not hasattr(self, 'tnt_version'):
26+
self.__class__.tnt_version = re.match(
27+
r'[\d.]+', self.srv.admin('box.info.version')[0]
28+
).group()
29+
30+
tnt_version = pkg_resources.parse_version(self.tnt_version)
31+
sql_support_tnt_version = pkg_resources.parse_version(
32+
SQL_SUPPORT_TNT_VERSION
33+
)
34+
35+
if tnt_version < sql_support_tnt_version:
36+
self.skipTest(
37+
'Tarantool %s does not support SQL' % self.tnt_version
38+
)
39+
40+
if func.__name__ != 'setUp':
41+
func(self, *args, **kwargs)
42+
43+
return wrapper

Diff for: test/suites/test_dbapi.py

+2
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):
@@ -34,6 +35,7 @@ def setUpClass(self):
3435
host=self.srv.host,
3536
port=self.srv.args['primary'])
3637

38+
@skip_or_run_sql_test
3739
def setUp(self):
3840
# prevent a remote tarantool from clean our session
3941
if self.srv.is_started():

Diff for: test/suites/test_execute.py

+3-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'},
@@ -30,6 +31,7 @@ def setUpClass(self):
3031
self.srv.start()
3132
self.con = tarantool.Connection(self.srv.host, self.srv.args['primary'])
3233

34+
@skip_or_run_sql_test
3335
def setUp(self):
3436
# prevent a remote tarantool from clean our session
3537
if self.srv.is_started():

0 commit comments

Comments
 (0)