未验证 提交 d1a3242e 编写于 作者: L Linhe Huo 提交者: GitHub

[TD-11634]<fix>: make tests and examples code compatible with python2 (#8932)

* [TD-11634]<fix>: fix python2 compatibility in master

* [TD-11634]<fix>: make tests and examples code compatible with python2

* [TD-11851]add some print to debug

* remove windows_input.py
Co-authored-by: Nliuyq-617 <yqliu@taosdata.com>
上级 35f5fb25
...@@ -103,7 +103,7 @@ _libtaos.taos_get_client_info.restype = c_char_p ...@@ -103,7 +103,7 @@ _libtaos.taos_get_client_info.restype = c_char_p
def taos_get_client_info(): def taos_get_client_info():
# type: () -> str # type: () -> str
"""Get client version info.""" """Get client version info."""
return _libtaos.taos_get_client_info().decode() return _libtaos.taos_get_client_info().decode("utf-8")
_libtaos.taos_get_server_info.restype = c_char_p _libtaos.taos_get_server_info.restype = c_char_p
...@@ -113,7 +113,7 @@ _libtaos.taos_get_server_info.argtypes = (c_void_p,) ...@@ -113,7 +113,7 @@ _libtaos.taos_get_server_info.argtypes = (c_void_p,)
def taos_get_server_info(connection): def taos_get_server_info(connection):
# type: (c_void_p) -> str # type: (c_void_p) -> str
"""Get server version as string.""" """Get server version as string."""
return _libtaos.taos_get_server_info(connection).decode() return _libtaos.taos_get_server_info(connection).decode("utf-8")
_libtaos.taos_close.restype = None _libtaos.taos_close.restype = None
......
...@@ -144,7 +144,7 @@ def _crow_nchar_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_ ...@@ -144,7 +144,7 @@ def _crow_nchar_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_
try: try:
if num_of_rows >= 0: if num_of_rows >= 0:
tmpstr = ctypes.c_char_p(data) tmpstr = ctypes.c_char_p(data)
res.append(tmpstr.value.decode()) res.append(tmpstr.value.decode("utf-8"))
else: else:
res.append( res.append(
( (
...@@ -172,7 +172,7 @@ def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, precision=Field ...@@ -172,7 +172,7 @@ def _crow_binary_to_python_block(data, num_of_rows, nbytes=None, precision=Field
if rbyte == 1 and buffer[0] == b'\xff': if rbyte == 1 and buffer[0] == b'\xff':
res.append(None) res.append(None)
else: else:
res.append(cast(buffer, c_char_p).value.decode()) res.append(cast(buffer, c_char_p).value.decode("utf-8"))
return res return res
...@@ -188,7 +188,7 @@ def _crow_nchar_to_python_block(data, num_of_rows, nbytes=None, precision=FieldT ...@@ -188,7 +188,7 @@ def _crow_nchar_to_python_block(data, num_of_rows, nbytes=None, precision=FieldT
if rbyte == 4 and buffer[:4] == b'\xff'*4: if rbyte == 4 and buffer[:4] == b'\xff'*4:
res.append(None) res.append(None)
else: else:
res.append(cast(buffer, c_char_p).value.decode()) res.append(cast(buffer, c_char_p).value.decode("utf-8"))
return res return res
......
...@@ -3,6 +3,8 @@ from .cinterface import * ...@@ -3,6 +3,8 @@ from .cinterface import *
# from .connection import TaosConnection # from .connection import TaosConnection
from .error import * from .error import *
from ctypes import c_void_p
class TaosResult(object): class TaosResult(object):
"""TDengine result interface""" """TDengine result interface"""
...@@ -12,7 +14,11 @@ class TaosResult(object): ...@@ -12,7 +14,11 @@ class TaosResult(object):
# to make the __del__ order right # to make the __del__ order right
self._conn = conn self._conn = conn
self._close_after = close_after self._close_after = close_after
self._result = result if isinstance(result, c_void_p):
self._result = result
else:
self._result = c_void_p(result)
self._fields = None self._fields = None
self._field_count = None self._field_count = None
self._precision = None self._precision = None
......
...@@ -36,7 +36,6 @@ def test_insert_lines(conn): ...@@ -36,7 +36,6 @@ def test_insert_lines(conn):
conn.insert_lines(lines) conn.insert_lines(lines)
print("inserted") print("inserted")
result = conn.query("select * from st") result = conn.query("select * from st")
print(*result.fields)
all = result.rows_iter() all = result.rows_iter()
for row in all: for row in all:
print(row) print(row)
......
# encoding:UTF-8
from taos import * from taos import *
from ctypes import * from ctypes import *
......
...@@ -20,7 +20,8 @@ def stream_callback(p_param, p_result, p_row): ...@@ -20,7 +20,8 @@ def stream_callback(p_param, p_result, p_row):
result = TaosResult(p_result) result = TaosResult(p_result)
row = TaosRow(result, p_row) row = TaosRow(result, p_row)
try: try:
ts, count = row() ts, count = row.as_tuple()
print(ts, count)
p = cast(p_param, POINTER(Counter)) p = cast(p_param, POINTER(Counter))
p.contents.count += count p.contents.count += count
print("[%s] inserted %d in 5s, total count: %d" % (ts.strftime("%Y-%m-%d %H:%M:%S"), count, p.contents.count)) print("[%s] inserted %d in 5s, total count: %d" % (ts.strftime("%Y-%m-%d %H:%M:%S"), count, p.contents.count))
......
...@@ -21,78 +21,91 @@ import json ...@@ -21,78 +21,91 @@ import json
import random import random
import time import time
import datetime import datetime
import multiprocessing
from multiprocessing import Manager, Pool, Lock from multiprocessing import Manager, Pool, Lock
from multipledispatch import dispatch from multipledispatch import dispatch
from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED
@dispatch(str, str) @dispatch(str, str)
def v_print(msg: str, arg: str): def v_print(msg, arg):
# type: (str, str) -> None
if verbose: if verbose:
print(msg % arg) print(msg % arg)
@dispatch(str, str, str) @dispatch(str, str, str)
def v_print(msg: str, arg1: str, arg2: str): def v_print(msg, arg1, arg2):
# type: (str, str, str) -> None
if verbose: if verbose:
print(msg % (arg1, arg2)) print(msg % (arg1, arg2))
@dispatch(str, str, str, str) @dispatch(str, str, str, str)
def v_print(msg: str, arg1: str, arg2: str, arg3: str): def v_print(msg, arg1, arg2, arg3):
# type: (str, str, str, str) -> None
if verbose: if verbose:
print(msg % (arg1, arg2, arg3)) print(msg % (arg1, arg2, arg3))
@dispatch(str, str, str, str, str) @dispatch(str, str, str, str, str)
def v_print(msg: str, arg1: str, arg2: str, arg3: str, arg4: str): def v_print(msg, arg1, arg2, arg3, arg4):
# type: (str, str, str, str, str) -> None
if verbose: if verbose:
print(msg % (arg1, arg2, arg3, arg4)) print(msg % (arg1, arg2, arg3, arg4))
@dispatch(str, int) @dispatch(str, int)
def v_print(msg: str, arg: int): def v_print(msg, arg):
# type: (str, int) -> None
if verbose: if verbose:
print(msg % int(arg)) print(msg % int(arg))
@dispatch(str, int, str) @dispatch(str, int, str)
def v_print(msg: str, arg1: int, arg2: str): def v_print(msg, arg1, arg2):
# type: (str, int, str) -> None
if verbose: if verbose:
print(msg % (int(arg1), str(arg2))) print(msg % (int(arg1), str(arg2)))
@dispatch(str, str, int) @dispatch(str, str, int)
def v_print(msg: str, arg1: str, arg2: int): def v_print(msg, arg1, arg2):
# type: (str, str, int) -> None
if verbose: if verbose:
print(msg % (arg1, int(arg2))) print(msg % (arg1, int(arg2)))
@dispatch(str, int, int) @dispatch(str, int, int)
def v_print(msg: str, arg1: int, arg2: int): def v_print(msg, arg1, arg2):
# type: (str, int, int) -> None
if verbose: if verbose:
print(msg % (int(arg1), int(arg2))) print(msg % (int(arg1), int(arg2)))
@dispatch(str, int, int, str) @dispatch(str, int, int, str)
def v_print(msg: str, arg1: int, arg2: int, arg3: str): def v_print(msg, arg1, arg2, arg3):
# type: (str, int, int, str) -> None
if verbose: if verbose:
print(msg % (int(arg1), int(arg2), str(arg3))) print(msg % (int(arg1), int(arg2), str(arg3)))
@dispatch(str, int, int, int) @dispatch(str, int, int, int)
def v_print(msg: str, arg1: int, arg2: int, arg3: int): def v_print(msg, arg1, arg2, arg3):
# type: (str, int, int, int) -> None
if verbose: if verbose:
print(msg % (int(arg1), int(arg2), int(arg3))) print(msg % (int(arg1), int(arg2), int(arg3)))
@dispatch(str, int, int, int, int) @dispatch(str, int, int, int, int)
def v_print(msg: str, arg1: int, arg2: int, arg3: int, arg4: int): def v_print(msg, arg1, arg2, arg3, arg4):
# type: (str, int, int, int, int) -> None
if verbose: if verbose:
print(msg % (int(arg1), int(arg2), int(arg3), int(arg4))) print(msg % (int(arg1), int(arg2), int(arg3), int(arg4)))
def restful_execute(host: str, port: int, user: str, password: str, cmd: str): def restful_execute(host, port, user, password, cmd):
# type: (str, int, str, str, str) -> None
url = "http://%s:%d/rest/sql" % (host, restPort) url = "http://%s:%d/rest/sql" % (host, restPort)
v_print("restful_execute - cmd: %s", cmd) v_print("restful_execute - cmd: %s", cmd)
...@@ -112,7 +125,8 @@ def restful_execute(host: str, port: int, user: str, password: str, cmd: str): ...@@ -112,7 +125,8 @@ def restful_execute(host: str, port: int, user: str, password: str, cmd: str):
print("resp: %s" % json.dumps(resp.json())) print("resp: %s" % json.dumps(resp.json()))
def query_func(process: int, thread: int, cmd: str): def query_func(process, thread, cmd):
# type: (int, int, str) -> None
v_print("%d process %d thread cmd: %s", process, thread, cmd) v_print("%d process %d thread cmd: %s", process, thread, cmd)
if oneMoreHost != "NotSupported" and random.randint( if oneMoreHost != "NotSupported" and random.randint(
...@@ -133,7 +147,8 @@ def query_func(process: int, thread: int, cmd: str): ...@@ -133,7 +147,8 @@ def query_func(process: int, thread: int, cmd: str):
host, port, user, password, cmd) host, port, user, password, cmd)
def query_data_process(cmd: str): def query_data_process(cmd):
# type: (str) -> None
# establish connection if native # establish connection if native
if native: if native:
v_print("host:%s, user:%s passwd:%s configDir:%s ", host, user, password, configDir) v_print("host:%s, user:%s passwd:%s configDir:%s ", host, user, password, configDir)
...@@ -256,7 +271,8 @@ def drop_databases(): ...@@ -256,7 +271,8 @@ def drop_databases():
(dbName, i)) (dbName, i))
def insert_func(process: int, thread: int): def insert_func(process, thread):
# type: (int, int) -> None
v_print("%d process %d thread, insert_func ", process, thread) v_print("%d process %d thread, insert_func ", process, thread)
# generate uuid # generate uuid
...@@ -374,7 +390,8 @@ def create_tb(): ...@@ -374,7 +390,8 @@ def create_tb():
(tbName, j)) (tbName, j))
def insert_data_process(lock, i: int, begin: int, end: int): def insert_data_process(lock, i, begin, end):
# type: (multiprocessing._LockType, int, int, int) -> None
lock.acquire() lock.acquire()
tasks = end - begin tasks = end - begin
v_print("insert_data_process:%d table from %d to %d, tasks %d", i, begin, end, tasks) v_print("insert_data_process:%d table from %d to %d, tasks %d", i, begin, end, tasks)
...@@ -675,7 +692,10 @@ if __name__ == "__main__": ...@@ -675,7 +692,10 @@ if __name__ == "__main__":
printConfig() printConfig()
if not skipPrompt: if not skipPrompt:
input("Press any key to continue..") try:
input("Press any key to continue..")
except SyntaxError:
pass
# establish connection first if native # establish connection first if native
if native: if native:
......
...@@ -19,4 +19,3 @@ python .\test.py -f query\filterFloatAndDouble.py ...@@ -19,4 +19,3 @@ python .\test.py -f query\filterFloatAndDouble.py
python .\test.py -f query\filterOtherTypes.py python .\test.py -f query\filterOtherTypes.py
python .\test.py -f query\querySort.py python .\test.py -f query\querySort.py
python .\test.py -f query\queryJoin.py python .\test.py -f query\queryJoin.py
python .\test.py -f tools\windows_input.py
\ No newline at end of file
...@@ -15,6 +15,7 @@ import os ...@@ -15,6 +15,7 @@ import os
from uiautomation import WindowControl from uiautomation import WindowControl
from util.cases import * from util.cases import *
from util.sql import * from util.sql import *
import clipboard
class TDTestCase: class TDTestCase:
...@@ -55,16 +56,22 @@ class TDTestCase: ...@@ -55,16 +56,22 @@ class TDTestCase:
sql = "insert into db.tb values(now,'%s');" % temp sql = "insert into db.tb values(now,'%s');" % temp
window.SendKeys(sql) window.SendKeys(sql)
window.SendKeys('{Enter}') window.SendKeys('{Enter}')
window.SendKeys('{Ctrl}A')
window.SendKeys('{Ctrl}C')
# 获取剪切板里面的复制内容
result = clipboard.paste()
window.SendKeys('{Ctrl}C') window.SendKeys('{Ctrl}C')
window.SendKeys('exit') window.SendKeys('exit')
window.SendKeys('{Enter}') window.SendKeys('{Enter}')
return result
def run(self): def run(self):
tdSql.prepare() tdSql.prepare()
ret = tdSql.execute('create table tb (ts timestamp, i binary(300))') ret = tdSql.execute('create table tb (ts timestamp, i binary(300))')
self.win_input_test() result = self.win_input_test()
tdLog.info(result)
tdSql.query("select * from tb") tdSql.query("select * from tb")
tdSql.checkRows(1) tdSql.checkRows(1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册