Changeset: e258c3027805 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e258c3027805 Added Files: testing/utils.py Modified Files: testing/CMakeLists.txt testing/sqllogictest.py Branch: mtest Log Message:
error code or mesage or sqllogic statement error diffs (102 lines): diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -153,6 +153,7 @@ if(PYTHON3_LIBDIR) malmapi.py helpers.py sqltest.py + utils.py DESTINATION ${PYTHON3_LIBDIR}/MonetDBtesting COMPONENT pytesting) endif() diff --git a/testing/sqllogictest.py b/testing/sqllogictest.py --- a/testing/sqllogictest.py +++ b/testing/sqllogictest.py @@ -30,6 +30,7 @@ import hashlib import re import sys import importlib +import MonetDBtesting.utils as utils skipidx = re.compile(r'create index .* \b(asc|desc)\b', re.I) @@ -143,16 +144,29 @@ class SQLLogic: except pymonetdb.Error: pass - def exec_statement(self, statement, expectok, err_stmt=None): + def exec_statement(self, statement, expectok, err_stmt=None, expected_err_code=None, expected_err_msg=None): if skipidx.search(statement) is not None: # skip creation of ascending or descending index return try: self.crs.execute(statement) except (pymonetdb.Error, ValueError) as e: + msg = e.args[0] if not expectok: + if expected_err_code or expected_err_msg: + # check whether failed as expected + err_code_received, err_msg_received = utils.parse_mapi_err_msg(msg) + if expected_err_code: + if expected_err_code == err_code_received: + return + if expected_err_msg: + if expected_err_msg.lower() == err_msg_received.lower(): + return + msg = "statement was expected to fail with" \ + + (" error code {}".format(expected_err_code) if expected_err_code else '')\ + + (", error message {}".format(expected_err_msg) if expected_err_msg else '') + self.query_error(err_stmt or statement, msg, str(e)) return - msg = e.args[0] else: if expectok: return @@ -370,7 +384,11 @@ class SQLLogic: if line[0] == 'hash-threshold': pass elif line[0] == 'statement': + expected_err_code = None + expected_err_msg = None expectok = line[1] == 'ok' + if len(line) > 2: + expected_err_code, expected_err_msg = utils.parse_mapi_err_msg(line[2]) statement = [] self.qline = self.line + 1 while True: @@ -381,9 +399,9 @@ class SQLLogic: if not skipping: if is_copyfrom_stmt(statement): stmt, stmt_less_data = prepare_copyfrom_stmt(statement) - self.exec_statement(stmt, expectok, err_stmt=stmt_less_data) + self.exec_statement(stmt, expectok, err_stmt=stmt_less_data, expected_err_code=expected_err_code, expected_err_msg=expected_err_msg) else: - self.exec_statement('\n'.join(statement), expectok) + self.exec_statement('\n'.join(statement), expectok, expected_err_code=expected_err_code, expected_err_msg=expected_err_msg) elif line[0] == 'query': columns = line[1] pyscript = None diff --git a/testing/utils.py b/testing/utils.py new file mode 100644 --- /dev/null +++ b/testing/utils.py @@ -0,0 +1,19 @@ + +def parse_mapi_err_msg(error:str=''): + """Parse error string and returns (err_code, err_msg) tuple + """ + err_code = None + err_msg = None + tmp = error.split('!') + if len(tmp) > 1: + try: + err_code = tmp[0].strip() + except (ValueError, TypeError): + pass + # reconstruct + err_msg = ('!'.join(tmp[1:])).strip() + elif len(tmp) == 1: + if tmp[0]: + err_msg = tmp[0].strip() + return err_code, err_msg + _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list