Merge pull request #27726 from taosdata/test/3.0/windows-full-ci

tetst:modify error path and correct checking timestamp  data with timzone in windows ci
This commit is contained in:
Feng Chao 2024-09-25 08:02:38 +08:00 committed by GitHub
commit ac8f72dcaf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 53 additions and 23 deletions

View File

@ -1,5 +1,6 @@
import csv import csv
import os import os
import platform
class TDCsv: class TDCsv:
def __init__(self): def __init__(self):
@ -25,7 +26,11 @@ class TDCsv:
@property @property
def file(self): def file(self):
if self.file_name and self.file_path: if self.file_name and self.file_path:
return os.path.join(self.file_path, self.file_name) print(f"self.file_path {self.file_path}, self.file_name {self.file_name}")
csv_file = os.path.join(self.file_path, self.file_name)
if platform.system().lower() == 'windows':
csv_file = csv_file.replace("\\", "/")
return csv_file
return None return None

View File

@ -24,26 +24,48 @@ from util.log import *
from util.constant import * from util.constant import *
import ctypes import ctypes
import random import random
# from datetime import timezone import datetime
import time import time
from tzlocal import get_localzone
def _parse_ns_timestamp(timestr): def _parse_ns_timestamp(timestr):
dt_obj = datetime.datetime.strptime(timestr[:len(timestr)-3], "%Y-%m-%d %H:%M:%S.%f") dt_obj = datetime.datetime.strptime(timestr[:len(timestr)-3], "%Y-%m-%d %H:%M:%S.%f")
tz = int(int((dt_obj-datetime.datetime.fromtimestamp(0,dt_obj.tzinfo)).total_seconds())*1e9) + int(dt_obj.microsecond * 1000) + int(timestr[-3:]) tz = int(int((dt_obj-datetime.datetime.fromtimestamp(0,dt_obj.tzinfo)).total_seconds())*1e9) + int(dt_obj.microsecond * 1000) + int(timestr[-3:])
return tz return tz
def _parse_datetime(timestr): def _parse_datetime(timestr):
try: # defined timestr formats
return datetime.datetime.strptime(timestr, '%Y-%m-%d %H:%M:%S.%f') formats = [
except ValueError: '%Y-%m-%d %H:%M:%S.%f%z', # 包含微秒和时区偏移
pass '%Y-%m-%d %H:%M:%S%z', # 不包含微秒但包含时区偏移
try: '%Y-%m-%d %H:%M:%S.%f', # 包含微秒
return datetime.datetime.strptime(timestr, '%Y-%m-%d %H:%M:%S') '%Y-%m-%d %H:%M:%S' # 不包含微秒
except ValueError: ]
pass
for fmt in formats:
try:
# try to parse the string with the current format
dt = datetime.datetime.strptime(timestr, fmt)
# 如果字符串包含时区信息,则返回 aware 对象
# if sting contains timezone info, return aware object
if dt.tzinfo is not None:
return dt
else:
# if sting does not contain timezone info, assume it is in local timezone
# get local timezone
local_timezone = get_localzone()
# print("Timezone:", local_timezone)
return dt.replace(tzinfo=local_timezone)
except ValueError:
continue # if the current format does not match, try the next format
# 如果所有格式都不匹配,返回 None
# if none of the formats match, return
raise ValueError(f"input format does not match. correct formats include: '{', '.join(formats)}'")
class TDSql: class TDSql:
def __init__(self): def __init__(self):
self.queryRows = 0 self.queryRows = 0
self.queryCols = 0 self.queryCols = 0
@ -408,6 +430,7 @@ class TDSql:
if self.queryResult[row][col] != data: if self.queryResult[row][col] != data:
if self.cursor.istype(col, "TIMESTAMP"): if self.cursor.istype(col, "TIMESTAMP"):
# tdLog.debug(f"self.queryResult[row][col]:{self.queryResult[row][col]}, data:{data},len(data):{len(data)}, isinstance(data,str) :{isinstance(data,str)}")
# suppose user want to check nanosecond timestamp if a longer data passed`` # suppose user want to check nanosecond timestamp if a longer data passed``
if isinstance(data,str) : if isinstance(data,str) :
if (len(data) >= 28): if (len(data) >= 28):
@ -419,8 +442,9 @@ class TDSql:
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data) args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args) tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args)
else: else:
# tdLog.info(f"datetime.timezone.utc:{datetime.timezone.utc},data:{data},_parse_datetime(data).astimezone(datetime.timezone.utc):{_parse_datetime(data).astimezone(datetime.timezone.utc)}")
if self.queryResult[row][col].astimezone(datetime.timezone.utc) == _parse_datetime(data).astimezone(datetime.timezone.utc): if self.queryResult[row][col].astimezone(datetime.timezone.utc) == _parse_datetime(data).astimezone(datetime.timezone.utc):
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}") # tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col].astimezone(datetime.timezone.utc)} == expect:{_parse_datetime(data).astimezone(datetime.timezone.utc)}")
if(show): if(show):
tdLog.info("check successfully") tdLog.info("check successfully")
else: else:

View File

@ -133,7 +133,7 @@ class TDTestCase:
def run(self): def run(self):
self.topic_name_check() self.topic_name_check()
self.db_name_check() self.db_name_check()
if platform.system().lower() == 'windows': if platform.system().lower() != 'windows':
self.stream_name_check() self.stream_name_check()
self.table_name_check() self.table_name_check()
self.view_name_check() self.view_name_check()

View File

@ -203,7 +203,7 @@ class TDTestCase:
assert str(v) == str(value) assert str(v) == str(value)
else: else:
for v in values: for v in values:
tdLog.debug("Set {} to {}".format(name, v)) tdLog.debug("Set client {} to {}".format(name, v))
tdSql.error(f'alter local "{name} {v}";') tdSql.error(f'alter local "{name} {v}";')
def svr_check(self, item, except_values=False): def svr_check(self, item, except_values=False):

View File

@ -4,6 +4,7 @@ from util.log import *
from util.sql import * from util.sql import *
from util.cases import * from util.cases import *
from util.csv import * from util.csv import *
import platform
import os import os
import taos import taos
import json import json
@ -56,7 +57,6 @@ class TDTestCase:
tdSql.init(conn.cursor(), True) tdSql.init(conn.cursor(), True)
self.testcasePath = os.path.split(__file__)[0] self.testcasePath = os.path.split(__file__)[0]
self.testcasePath = self.testcasePath.replace('\\', '//')
self.testcaseFilename = os.path.split(__file__)[-1] self.testcaseFilename = os.path.split(__file__)[-1]
os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename))
# tdSql.execute(f"insert into db4096.ctb00 file '{self.testcasePath}//tableColumn4096csvLength64k.csv'") # tdSql.execute(f"insert into db4096.ctb00 file '{self.testcasePath}//tableColumn4096csvLength64k.csv'")

View File

@ -285,7 +285,7 @@ class TDTestCase:
self.drop_table_with_check() self.drop_table_with_check()
self.drop_table_with_check_tsma() self.drop_table_with_check_tsma()
self.drop_topic_check() self.drop_topic_check()
if platform.system().lower() == 'windows': if platform.system().lower() != 'windows':
self.drop_stream_check() self.drop_stream_check()
pass pass
def stop(self): def stop(self):

View File

@ -1,6 +1,5 @@
import queue import queue
import random import random
from fabric2.runners import threading
from pandas._libs import interval from pandas._libs import interval
import taos import taos
import sys import sys
@ -9,6 +8,7 @@ from util.common import TDCom
from util.log import * from util.log import *
from util.sql import * from util.sql import *
from util.cases import * from util.cases import *
import threading

View File

@ -140,14 +140,14 @@ class TDTestCase:
tdsql2 = tdCom.newTdSqlWithTimezone(timezone="UTC") tdsql2 = tdCom.newTdSqlWithTimezone(timezone="UTC")
tdsql2.query(f"select * from {dbname}.tzt") tdsql2.query(f"select * from {dbname}.tzt")
tdsql2.checkRows(1) tdsql2.checkRows(1)
tdsql2.checkData(0, 0, "2018-09-17 01:00:00") # checkData:The expected date and time is the local time zone of the machine where the test case is executed.
tdsql2.checkData(0, 0, "2018-09-17 09:00:00")
tdsql2.execute(f'insert into {dbname}.tzt values({self.ts + 1000}, 2)') tdsql2.execute(f'insert into {dbname}.tzt values({self.ts + 1000}, 2)')
tdsql2.query(f"select * from {dbname}.tzt order by ts") tdsql2.query(f"select * from {dbname}.tzt order by ts")
tdsql2.checkRows(2) tdsql2.checkRows(2)
tdsql2.checkData(0, 0, "2018-09-17 01:00:00") tdsql2.checkData(0, 0, "2018-09-17 09:00:00")
tdsql2.checkData(1, 0, "2018-09-17 01:00:01") tdsql2.checkData(1, 0, "2018-09-17 09:00:01")
tdsql2 = tdCom.newTdSqlWithTimezone(timezone="Asia/Shanghai") tdsql2 = tdCom.newTdSqlWithTimezone(timezone="Asia/Shanghai")
tdsql2.query(f"select * from {dbname}.tzt order by ts") tdsql2.query(f"select * from {dbname}.tzt order by ts")
@ -160,7 +160,7 @@ class TDTestCase:
tdSql.prepare() tdSql.prepare()
self.timeZoneTest() self.timeZoneTest()
self.inAndNotinTest() # self.inAndNotinTest()
def stop(self): def stop(self):
@ -168,4 +168,5 @@ class TDTestCase:
tdLog.success("%s successfully executed" % __file__) tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase()) tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase())