Skip to content

Commit

Permalink
Skip SQL tests if tarantool version < 2.0.0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ylobankov committed Nov 11, 2021
1 parent 6140342 commit 051ca05
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
22 changes: 22 additions & 0 deletions test/suites/lib/skip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import functools
import pkg_resources

SQL_SUPPORT_TNT_VERSION = '2.0.0'


def skip_or_run_sql_test(func):
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
tnt_version = pkg_resources.parse_version(self.tnt_version)
sql_support_tnt_version = pkg_resources.parse_version(
SQL_SUPPORT_TNT_VERSION
)

if tnt_version < sql_support_tnt_version:
self.skipTest(
'Tarantool %s does not support SQL' % self.tnt_version
)
else:
func(self, *args, **kwargs)

return wrapper
45 changes: 45 additions & 0 deletions test/suites/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import tarantool
from tarantool import dbapi
from .lib.tarantool_server import TarantoolServer
from .lib.skip import skip_or_run_sql_test


class TestSuite_DBAPI(dbapi20.DatabaseAPI20Test):
Expand All @@ -33,6 +34,9 @@ def setUpClass(self):
self.connect_kw_args = dict(
host=self.srv.host,
port=self.srv.args['primary'])
self.tnt_version = '.'.join(
self.srv.admin('box.info.version')[0].split('-')[0].split('.')[:3]
)

def setUp(self):
# prevent a remote tarantool from clean our session
Expand All @@ -50,6 +54,47 @@ def tearDownClass(self):
self.srv.stop()
self.srv.clean()

@skip_or_run_sql_test
def test_None(self):
super(TestSuite_DBAPI, self).test_None()

@skip_or_run_sql_test
def test_cursor_isolation(self):
super(TestSuite_DBAPI, self).test_cursor_isolation()

@skip_or_run_sql_test
def test_execute(self):
super(TestSuite_DBAPI, self).test_execute()

@skip_or_run_sql_test
def test_executemany(self):
super(TestSuite_DBAPI, self).test_executemany()

@skip_or_run_sql_test
def test_fetchall(self):
super(TestSuite_DBAPI, self).test_fetchall()

@skip_or_run_sql_test
def test_fetchmany(self):
super(TestSuite_DBAPI, self).test_fetchmany()

@skip_or_run_sql_test
def test_fetchone(self):
super(TestSuite_DBAPI, self).test_fetchone()

@skip_or_run_sql_test
def test_mixedfetch(self):
super(TestSuite_DBAPI, self).test_mixedfetch()

@skip_or_run_sql_test
def test_setinputsizes(self):
super(TestSuite_DBAPI, self).test_setinputsizes()

@skip_or_run_sql_test
def test_setoutputsize_basic(self):
super(TestSuite_DBAPI, self).test_setoutputsize_basic()

@skip_or_run_sql_test
def test_rowcount(self):
con = self._connect()
try:
Expand Down
8 changes: 7 additions & 1 deletion test/suites/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import tarantool
from .lib.tarantool_server import TarantoolServer
from .lib.skip import skip_or_run_sql_test


class TestSuite_Execute(unittest.TestCase):
ddl = 'create table %s (id INTEGER PRIMARY KEY AUTOINCREMENT, ' \
'name varchar(20))'
'name varchar(20))'

dml_params = [
{'id': None, 'name': 'Michael'},
Expand All @@ -29,6 +30,9 @@ def setUpClass(self):
self.srv.script = 'test/suites/box.lua'
self.srv.start()
self.con = tarantool.Connection(self.srv.host, self.srv.args['primary'])
self.tnt_version = '.'.join(
self.srv.admin('box.info.version')[0].split('-')[0].split('.')[:3]
)

def setUp(self):
# prevent a remote tarantool from clean our session
Expand All @@ -54,6 +58,7 @@ def _populate_data(self, table_name):
def _create_table(self, table_name):
return self.con.execute(self.ddl % table_name)

@skip_or_run_sql_test
def test_dml_response(self):
table_name = 'foo'
response = self._create_table(table_name)
Expand All @@ -75,6 +80,7 @@ def test_dml_response(self):
self.assertEqual(response.affected_row_count, 2)
self.assertEqual(response.data, None)

@skip_or_run_sql_test
def test_dql_response(self):
table_name = 'bar'
self._create_table(table_name)
Expand Down

0 comments on commit 051ca05

Please sign in to comment.