From 0f95f2828895bdcd9a4ba8cf3eb5c67cf7fa4396 Mon Sep 17 00:00:00 2001 From: Yaroslav Lobankov Date: Thu, 11 Nov 2021 17:33:01 +0300 Subject: [PATCH] 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 --- test/suites/lib/skip.py | 43 +++++++++++++++++++++++++++++++++++++ test/suites/test_dbapi.py | 2 ++ test/suites/test_execute.py | 4 +++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 test/suites/lib/skip.py diff --git a/test/suites/lib/skip.py b/test/suites/lib/skip.py new file mode 100644 index 00000000..495a716c --- /dev/null +++ b/test/suites/lib/skip.py @@ -0,0 +1,43 @@ +import functools +import pkg_resources +import re + +SQL_SUPPORT_TNT_VERSION = '2.0.0' + + +def skip_or_run_sql_test(func): + """Decorator to skip or run SQL-related tests depending on the tarantool + version. + + Tarantool supports SQL-related stuff only since 2.0.0 version. So this + decorator should wrap every SQL-related test to skip it if the tarantool + version < 2.0.0 is used for testing. + + Also, it can be used with the 'setUp' method for skipping the whole test + suite. + """ + + @functools.wraps(func) + def wrapper(self, *args, **kwargs): + if func.__name__ == 'setUp': + func(self, *args, **kwargs) + + if not hasattr(self, 'tnt_version'): + self.__class__.tnt_version = re.match( + r'[\d.]+', self.srv.admin('box.info.version')[0] + ).group() + + 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 + ) + + if func.__name__ != 'setUp': + func(self, *args, **kwargs) + + return wrapper diff --git a/test/suites/test_dbapi.py b/test/suites/test_dbapi.py index 074620f1..1435bb4f 100644 --- a/test/suites/test_dbapi.py +++ b/test/suites/test_dbapi.py @@ -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): @@ -34,6 +35,7 @@ def setUpClass(self): host=self.srv.host, port=self.srv.args['primary']) + @skip_or_run_sql_test def setUp(self): # prevent a remote tarantool from clean our session if self.srv.is_started(): diff --git a/test/suites/test_execute.py b/test/suites/test_execute.py index e10c0073..53fd9f2e 100644 --- a/test/suites/test_execute.py +++ b/test/suites/test_execute.py @@ -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'}, @@ -30,6 +31,7 @@ def setUpClass(self): self.srv.start() self.con = tarantool.Connection(self.srv.host, self.srv.args['primary']) + @skip_or_run_sql_test def setUp(self): # prevent a remote tarantool from clean our session if self.srv.is_started():