From b2b293a7c4f02f12961ae86b2dab0b938149a5de Mon Sep 17 00:00:00 2001 From: Eugine Blikh <bigbes@gmail.com> Date: Mon, 16 Sep 2013 17:31:50 +0400 Subject: [PATCH] 1. remove tnt* aliases 2. modify errmsg 3. rewrite Lua - check_type 4. Move try-except importerror to test_suite file --- test/big/sql.result | 12 +++++++++--- test/big/sql.test.py | 3 --- test/box/admin.result | 6 +----- test/box/admin.test.lua | 6 +----- test/box/bad_trigger.result | 4 +++- test/box/lua.result | 36 ++++++++++++++++++++++++++--------- test/box/sql.result | 20 ++++++++++++++----- test/box/sql.test.py | 9 +++++---- test/lib/box_connection.py | 24 ++++++++++++++--------- test/lib/sql_ast.py | 35 +++++++++++++++++----------------- test/lib/tarantool_server.py | 18 +++--------------- test/lib/test_suite.py | 11 +++++++++++ test/replication/swap.test.py | 15 ++++++++------- 13 files changed, 116 insertions(+), 83 deletions(-) diff --git a/test/big/sql.result b/test/big/sql.result index 55cfbcea3b..cc3d549dc5 100644 --- a/test/big/sql.result +++ b/test/big/sql.result @@ -64,14 +64,18 @@ box.space[0]:truncate() # insert into t0 values ('Britney') --- -- error: 'Tuple field count 1 is less than required by a defined index (expected 2)' +- error: + errcode : ER_INDEX_ARITY + errmsg : Tuple field count 1 is less than required by a defined index (expected 2) ... select * from t0 where k1='Anything' --- ... insert into t0 values ('Stephanie') --- -- error: 'Tuple field count 1 is less than required by a defined index (expected 2)' +- error: + errcode : ER_INDEX_ARITY + errmsg : Tuple field count 1 is less than required by a defined index (expected 2) ... select * from t0 where k1='Anything' --- @@ -385,7 +389,9 @@ select * from t0 where k1='Britney' ... replace into t0 values ('Spears') --- -- error: 'Tuple field count 1 is less than required by a defined index (expected 2)' +- error: + errcode : ER_INDEX_ARITY + errmsg : Tuple field count 1 is less than required by a defined index (expected 2) ... select * from t0 where k0='Spears' --- diff --git a/test/big/sql.test.py b/test/big/sql.test.py index fbc91a1b26..54f2797d9c 100644 --- a/test/big/sql.test.py +++ b/test/big/sql.test.py @@ -1,5 +1,3 @@ -# encoding: utf-8 -# sql.sort = True # @@ -203,4 +201,3 @@ sql("delete from t0 where k0=3") admin("box.space[0]:drop()") sql.sort = False -# vim: syntax=python diff --git a/test/box/admin.result b/test/box/admin.result index c6143fe0ab..09d7e3ce45 100644 --- a/test/box/admin.result +++ b/test/box/admin.result @@ -107,11 +107,7 @@ box.delete(0, 1) ... --# setopt delimiter ';' function check_type(arg, typeof) - if type(arg) == typeof then - return true - else - return false - end + return type(arg) == typeof end; --- ... diff --git a/test/box/admin.test.lua b/test/box/admin.test.lua index 45c0514160..2ab841d1ac 100644 --- a/test/box/admin.test.lua +++ b/test/box/admin.test.lua @@ -14,11 +14,7 @@ box.delete(0, 1) --# setopt delimiter ';' function check_type(arg, typeof) - if type(arg) == typeof then - return true - else - return false - end + return type(arg) == typeof end; function test_box_info() diff --git a/test/box/bad_trigger.result b/test/box/bad_trigger.result index 36768396a4..aff0dff60d 100644 --- a/test/box/bad_trigger.result +++ b/test/box/bad_trigger.result @@ -9,7 +9,9 @@ type(box.session.on_connect(function() nosuchfunction() end)) ... select * from t0 where k0=0 --- -- error: 'Lua error: [string "return type(box.session.on_connect(function()..."]:1: attempt to call global 'nosuchfunction' (a nil value)' +- error: + errcode : ER_PROC_LUA + errmsg : Lua error: [string "return type(box.session.on_connect(function()..."]:1: attempt to call global 'nosuchfunction' (a nil value) ... Connection is dead. diff --git a/test/box/lua.result b/test/box/lua.result index efbea0f96c..a800a5692c 100644 --- a/test/box/lua.result +++ b/test/box/lua.result @@ -209,11 +209,15 @@ box.process(22, box.pack('iii', 0, 0, 0)) ... call box.process('abc', 'def') --- -- error: 'Illegal parameters, unsupported command code, check the error log' +- error: + errcode : ER_ILLEGAL_PARAMS + errmsg : Illegal parameters, unsupported command code, check the error log ... call box.pack('test') --- -- error: 'Lua error: box.pack: argument count does not match the format' +- error: + errcode : ER_PROC_LUA + errmsg : Lua error: box.pack: argument count does not match the format ... call box.pack('p', 'this string is 45 characters long 1234567890 ') --- @@ -251,14 +255,18 @@ f1=nil ... call f1() --- -- error: 'Procedure 'f1' is not defined' +- error: + errcode : ER_NO_SUCH_PROC + errmsg : Procedure 'f1' is not defined ... function f1() return f1 end --- ... call f1() --- -- error: 'Return type 'function' is not supported in the binary protocol' +- error: + errcode : ER_PROC_RET + errmsg : Return type 'function' is not supported in the binary protocol ... insert into t0 values (1, 'test box delete') --- @@ -372,7 +380,9 @@ call box.insert('0', 'test', 'old', 'abcd') ... call box.insert('0', 'test', 'old', 'abcd') --- -- error: 'Duplicate key exists in unique index 0' +- error: + errcode : ER_TUPLE_FOUND + errmsg : Duplicate key exists in unique index 0 ... call box.update('0', 'test', '=p=p', '����', 'pass', 1, 'new') --- @@ -1019,28 +1029,36 @@ function f3() return {'hello', {'world'}} end ... call f3() --- -- error: 'Return type 'table' is not supported in the binary protocol' +- error: + errcode : ER_PROC_RET + errmsg : Return type 'table' is not supported in the binary protocol ... function f3() return 'hello', {{'world'}, {'canada'}} end --- ... call f3() --- -- error: 'Return type 'table' is not supported in the binary protocol' +- error: + errcode : ER_PROC_RET + errmsg : Return type 'table' is not supported in the binary protocol ... function f3() return {}, '123', {{}, {}} end --- ... call f3() --- -- error: 'Return type 'table' is not supported in the binary protocol' +- error: + errcode : ER_PROC_RET + errmsg : Return type 'table' is not supported in the binary protocol ... function f3() return { {{'hello'}} } end --- ... call f3() --- -- error: 'Return type 'table' is not supported in the binary protocol' +- error: + errcode : ER_PROC_RET + errmsg : Return type 'table' is not supported in the binary protocol ... function f3() return { box.tuple.new('hello'), {'world'} } end --- diff --git a/test/box/sql.result b/test/box/sql.result index a145cbf3e8..fb8fb83278 100644 --- a/test/box/sql.result +++ b/test/box/sql.result @@ -10,7 +10,9 @@ ping ... select * from t0 --- -- error: 'Invalid key part count in an exact match (expected 1, got 0)' +- error: + errcode : ER_EXACT_MATCH + errmsg : Invalid key part count in an exact match (expected 1, got 0) ... insert into t0 values (1, 'I am a tuple') --- @@ -81,7 +83,9 @@ select * from t0 where k0 = 1 ... update t0 set k1 = 'Huh', k1000 = 'invalid field' where k0=1 --- -- error: 'Field 1000 was not found in the tuple' +- error: + errcode : ER_NO_SUCH_FIELD + errmsg : Field 1000 was not found in the tuple ... select * from t0 where k0 = 1 --- @@ -147,15 +151,21 @@ delete from t0 where k0=4294967295 select * from t1 where k0 = 0 --- -- error: 'Space 1 does not exist' +- error: + errcode : ER_NO_SUCH_SPACE + errmsg : Space 1 does not exist ... select * from t65537 where k0 = 0 --- -- error: 'Space 65537 does not exist' +- error: + errcode : ER_NO_SUCH_SPACE + errmsg : Space 65537 does not exist ... select * from t4294967295 where k0 = 0 --- -- error: 'Space 4294967295 does not exist' +- error: + errcode : ER_NO_SUCH_SPACE + errmsg : Space 4294967295 does not exist ... box.space[0]:drop() --- diff --git a/test/box/sql.test.py b/test/box/sql.test.py index b42576f050..2186a455b8 100644 --- a/test/box/sql.test.py +++ b/test/box/sql.test.py @@ -1,9 +1,10 @@ -sql.py_con.schema = Schema({ +import tarantool +sql.set_schema({ 0 : { - 'default_type': tntSTR, + 'default_type': tarantool.STR, 'fields' : { - 0 : tntNUM, - 1 : tntSTR + 0 : tarantool.NUM, + 1 : tarantool.STR }, 'indexes': { 0 : [0] # HASH diff --git a/test/lib/box_connection.py b/test/lib/box_connection.py index 4829290cb7..17b6989129 100644 --- a/test/lib/box_connection.py +++ b/test/lib/box_connection.py @@ -29,17 +29,23 @@ import socket import struct import warnings +from test_suite import chk_tnt_includes from tarantool_connection import TarantoolConnection -try: - tnt_py = os.path.dirname(os.path.abspath(__file__)) - tnt_py = os.path.join(tnt_py, 'tarantool-python/src') - sys.path.append(tnt_py) - from tarantool import Connection as tnt_connection - from tarantool import Schema -except ImportError: - sys.stderr.write("\n\nNo tarantool-python library found\n") - sys.exit(1) +def chk_tnt_includes(): + try: + tnt_py = os.path.dirname(os.path.abspath(__file__)) + tnt_py = os.path.join(tnt_py, 'tarantool-python/src') + if tnt_py not in sys.path: + sys.path = [tnt_py] + sys.path + import tarantool + except ImportError: + sys.stderr.write("\n\nNo tarantool-python library found\n") + sys.exit(1) + +chk_tnt_includes() +from tarantool import Connection as tnt_connection +from tarantool import Schema class BoxConnection(TarantoolConnection): def __init__(self, host, port): diff --git a/test/lib/sql_ast.py b/test/lib/sql_ast.py index 620da0d198..1a0e62c1c7 100644 --- a/test/lib/sql_ast.py +++ b/test/lib/sql_ast.py @@ -4,21 +4,17 @@ import sys import ctypes import struct -try: - tnt_py = os.path.dirname(os.path.abspath(__file__)) - tnt_py = os.path.join(tnt_py, 'tarantool-python/src') - sys.path.append(tnt_py) - from tarantool.request import ( - RequestPing, - RequestInsert, - RequestSelect, - RequestCall, - RequestUpdate, - RequestDelete, - ) -except ImportError: - sys.stderr.write("\n\nNo tarantool-python library found\n") - sys.exit(1) +from lib.test_suite import chk_tnt_includes + +chk_tnt_includes() +from tarantool.request import ( + RequestPing, + RequestInsert, + RequestSelect, + RequestCall, + RequestUpdate, + RequestDelete, +) ER = { 0: "ER_OK" , @@ -81,9 +77,14 @@ ER = { 57: "ER_NO_SUCH_SPACE" } +errstr = """--- +- error: + errcode : {0} + errmsg : {1} +...""" + def format_error(response): - return "---\n- error: '{1}'\n...".format(ER[response.return_code], - response.return_message) + return errstr.format(ER[response.return_code], response.return_message) def format_yamllike(response): table = ("\n"+"\n".join(["- "+str(list(k)) for k in response])) \ diff --git a/test/lib/tarantool_server.py b/test/lib/tarantool_server.py index 95bda71397..4489c28b98 100644 --- a/test/lib/tarantool_server.py +++ b/test/lib/tarantool_server.py @@ -17,7 +17,7 @@ import ConfigParser from lib.server import Server from lib.box_connection import BoxConnection -from lib.test_suite import FilteredStream, Test +from lib.test_suite import FilteredStream, Test, chk_tnt_includes from lib.admin_connection import AdminConnection from lib.memcached_connection import MemcachedConnection @@ -26,15 +26,8 @@ try: except ImportError: import StringIO -try: - tnt_py = os.path.dirname(os.path.abspath(__file__)) - tnt_py = os.path.join(tnt_py, 'tarantool-python/src') - sys.path.append(tnt_py) - import tarantool - from tarantool import Connection as tnt_connection -except ImportError: - sys.stderr.write("\n\nNo tarantool-python library found\n") - sys.exit(1) +chk_tnt_includes() +import tarantool def check_port(port): """Check if the port we're connecting to is available""" @@ -251,11 +244,6 @@ class LuaTest(FuncTest): class PythonTest(FuncTest): def execute(self, server): - Schema = tarantool.Schema - tntNUM = tarantool.NUM - tntSTR = tarantool.STR - tntNUM64 = tarantool.NUM64 - tntRAW = tarantool.RAW execfile(self.name, dict(locals(), **server.__dict__)) class TarantoolConfigFile: diff --git a/test/lib/test_suite.py b/test/lib/test_suite.py index a00d9d438a..ce39012dd9 100644 --- a/test/lib/test_suite.py +++ b/test/lib/test_suite.py @@ -15,6 +15,17 @@ try: except ImportError: from StringIO import StringIO +def chk_tnt_includes(): + try: + tnt_py = os.path.dirname(os.path.abspath(__file__)) + tnt_py = os.path.join(tnt_py, 'tarantool-python/src') + if tnt_py not in sys.path: + sys.path = [tnt_py] + sys.path + import tarantool + except ImportError: + sys.stderr.write("\n\nNo tarantool-python library found\n") + sys.exit(1) + class FilteredStream: """Helper class to filter .result file output""" def __init__(self, filename): diff --git a/test/replication/swap.test.py b/test/replication/swap.test.py index 9c4d2348a3..19fe91c009 100644 --- a/test/replication/swap.test.py +++ b/test/replication/swap.test.py @@ -1,4 +1,5 @@ import os +import tarantool from lib.tarantool_server import TarantoolServer REPEAT = 20 @@ -24,21 +25,21 @@ replica.deploy("replication/cfg/replica.cfg", replica.find_exe(self.args.builddir), os.path.join(self.args.vardir, "replica")) -schema = Schema({ +schema = { 0 : { - 'default_type': tntSTR, + 'default_type': tarantool.STR, 'fields' : { - 0 : tntNUM, - 1 : tntSTR + 0 : tarantool.NUM, + 1 : tarantool.STR }, 'indexes': { 0 : [0] # HASH } } -}) +} -master.sql.py_con.schema = schema -replica.sql.py_con.schema = schema +master.sql.set_schema(schema) +replica.sql.set_schema(schema) master.admin("box.replace(box.schema.SPACE_ID, 0, 0, 'tweedledum')") master.admin("box.replace(box.schema.INDEX_ID, 0, 0, 'primary', 'hash', 1, 1, 0, 'num')") -- GitLab