未验证 提交 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
def taos_get_client_info():
# type: () -> str
"""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
......@@ -113,7 +113,7 @@ _libtaos.taos_get_server_info.argtypes = (c_void_p,)
def taos_get_server_info(connection):
# type: (c_void_p) -> str
"""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
......
......@@ -144,7 +144,7 @@ def _crow_nchar_to_python(data, num_of_rows, nbytes=None, precision=FieldType.C_
try:
if num_of_rows >= 0:
tmpstr = ctypes.c_char_p(data)
res.append(tmpstr.value.decode())
res.append(tmpstr.value.decode("utf-8"))
else:
res.append(
(
......@@ -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':
res.append(None)
else:
res.append(cast(buffer, c_char_p).value.decode())
res.append(cast(buffer, c_char_p).value.decode("utf-8"))
return res
......@@ -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:
res.append(None)
else:
res.append(cast(buffer, c_char_p).value.decode())
res.append(cast(buffer, c_char_p).value.decode("utf-8"))
return res
......
......@@ -3,6 +3,8 @@ from .cinterface import *
# from .connection import TaosConnection
from .error import *
from ctypes import c_void_p
class TaosResult(object):
"""TDengine result interface"""
......@@ -12,7 +14,11 @@ class TaosResult(object):
# to make the __del__ order right
self._conn = conn
self._close_after = close_after
if isinstance(result, c_void_p):
self._result = result
else:
self._result = c_void_p(result)
self._fields = None
self._field_count = None
self._precision = None
......
......@@ -36,7 +36,6 @@ def test_insert_lines(conn):
conn.insert_lines(lines)
print("inserted")
result = conn.query("select * from st")
print(*result.fields)
all = result.rows_iter()
for row in all:
print(row)
......
# encoding:UTF-8
from taos import *
from ctypes import *
......
......@@ -20,7 +20,8 @@ def stream_callback(p_param, p_result, p_row):
result = TaosResult(p_result)
row = TaosRow(result, p_row)
try:
ts, count = row()
ts, count = row.as_tuple()
print(ts, count)
p = cast(p_param, POINTER(Counter))
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))
......
......@@ -21,78 +21,91 @@ import json
import random
import time
import datetime
import multiprocessing
from multiprocessing import Manager, Pool, Lock
from multipledispatch import dispatch
from concurrent.futures import ThreadPoolExecutor, wait, ALL_COMPLETED
@dispatch(str, str)
def v_print(msg: str, arg: str):
def v_print(msg, arg):
# type: (str, str) -> None
if verbose:
print(msg % arg)
@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:
print(msg % (arg1, arg2))
@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:
print(msg % (arg1, arg2, arg3))
@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:
print(msg % (arg1, arg2, arg3, arg4))
@dispatch(str, int)
def v_print(msg: str, arg: int):
def v_print(msg, arg):
# type: (str, int) -> None
if verbose:
print(msg % int(arg))
@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:
print(msg % (int(arg1), str(arg2)))
@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:
print(msg % (arg1, int(arg2)))
@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:
print(msg % (int(arg1), int(arg2)))
@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:
print(msg % (int(arg1), int(arg2), str(arg3)))
@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:
print(msg % (int(arg1), int(arg2), int(arg3)))
@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:
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)
v_print("restful_execute - cmd: %s", cmd)
......@@ -112,7 +125,8 @@ def restful_execute(host: str, port: int, user: str, password: str, cmd: str):
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)
if oneMoreHost != "NotSupported" and random.randint(
......@@ -133,7 +147,8 @@ def query_func(process: int, thread: int, cmd: str):
host, port, user, password, cmd)
def query_data_process(cmd: str):
def query_data_process(cmd):
# type: (str) -> None
# establish connection if native
if native:
v_print("host:%s, user:%s passwd:%s configDir:%s ", host, user, password, configDir)
......@@ -256,7 +271,8 @@ def drop_databases():
(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)
# generate uuid
......@@ -374,7 +390,8 @@ def create_tb():
(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()
tasks = end - begin
v_print("insert_data_process:%d table from %d to %d, tasks %d", i, begin, end, tasks)
......@@ -675,7 +692,10 @@ if __name__ == "__main__":
printConfig()
if not skipPrompt:
try:
input("Press any key to continue..")
except SyntaxError:
pass
# establish connection first if native
if native:
......
......@@ -19,4 +19,3 @@ python .\test.py -f query\filterFloatAndDouble.py
python .\test.py -f query\filterOtherTypes.py
python .\test.py -f query\querySort.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
from uiautomation import WindowControl
from util.cases import *
from util.sql import *
import clipboard
class TDTestCase:
......@@ -55,16 +56,22 @@ class TDTestCase:
sql = "insert into db.tb values(now,'%s');" % temp
window.SendKeys(sql)
window.SendKeys('{Enter}')
window.SendKeys('{Ctrl}A')
window.SendKeys('{Ctrl}C')
# 获取剪切板里面的复制内容
result = clipboard.paste()
window.SendKeys('{Ctrl}C')
window.SendKeys('exit')
window.SendKeys('{Enter}')
return result
def run(self):
tdSql.prepare()
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.checkRows(1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册