tetst:modify error path and correct checking timestamp data with timezone in windows ci

This commit is contained in:
chenhaoran 2024-09-06 14:26:18 +08:00
parent 2eca52ae2e
commit 32b23885ad
8 changed files with 64 additions and 27 deletions

View File

@ -1,5 +1,6 @@
import csv
import os
import platform
class TDCsv:
def __init__(self):
@ -25,7 +26,11 @@ class TDCsv:
@property
def file(self):
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

View File

@ -24,26 +24,48 @@ from util.log import *
from util.constant import *
import ctypes
import random
# from datetime import timezone
import datetime
import time
from tzlocal import get_localzone
def _parse_ns_timestamp(timestr):
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:])
return tz
def _parse_datetime(timestr):
try:
return datetime.datetime.strptime(timestr, '%Y-%m-%d %H:%M:%S.%f')
except ValueError:
pass
try:
return datetime.datetime.strptime(timestr, '%Y-%m-%d %H:%M:%S')
except ValueError:
pass
# defined timestr formats
formats = [
'%Y-%m-%d %H:%M:%S.%f%z', # 包含微秒和时区偏移
'%Y-%m-%d %H:%M:%S%z', # 不包含微秒但包含时区偏移
'%Y-%m-%d %H:%M:%S.%f', # 包含微秒
'%Y-%m-%d %H:%M:%S' # 不包含微秒
]
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:
def __init__(self):
self.queryRows = 0
self.queryCols = 0
@ -408,6 +430,7 @@ class TDSql:
if self.queryResult[row][col] != data:
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``
if isinstance(data,str) :
if (len(data) >= 28):
@ -419,8 +442,9 @@ class TDSql:
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)
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):
# 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):
tdLog.info("check successfully")
else:

View File

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

View File

@ -165,18 +165,25 @@ class TDTestCase:
if config_name == row[0]:
tdLog.debug("Found variable '{}'".format(row[0]))
return row[1]
def get_server_param_value(self, config_name):
tdSql.query("show dnode 1 variables;")
for row in tdSql.queryResult:
if config_name == row[0]:
tdLog.debug("Found variable '{}'".format(row[0]))
return row[1]
def cli_check(self, name, values, except_values=False):
if not except_values:
for v in values:
tdLog.debug("Set {} to {}".format(name, v))
tdLog.debug("Set client {} to {}".format(name, v))
tdSql.execute(f'alter local "{name} {v}";')
value = self.get_param_value(name)
tdLog.debug("Get {} value: {}".format(name, value))
assert(v == int(value))
else:
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}";')
def svr_check(self, name, alias, values, except_values=False):
@ -190,8 +197,8 @@ class TDTestCase:
if not except_values:
for v in values:
dnode = random.choice(p_list)
tdSql.execute(f'alter {dnode} "{name} {v}";')
value = self.get_param_value(alias)
tdSql.execute(f'alter {dnode} "{name} {v}";',show=True)
value = self.get_server_param_value(name)
if value:
tdLog.debug(f"value: {value}")
assert(value == str(bool(v)).lower() if is_bool else str(v))

View File

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

View File

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

View File

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

View File

@ -140,14 +140,14 @@ class TDTestCase:
tdsql2 = tdCom.newTdSqlWithTimezone(timezone="UTC")
tdsql2.query(f"select * from {dbname}.tzt")
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.query(f"select * from {dbname}.tzt order by ts")
tdsql2.checkRows(2)
tdsql2.checkData(0, 0, "2018-09-17 01:00:00")
tdsql2.checkData(1, 0, "2018-09-17 01:00:01")
tdsql2.checkData(0, 0, "2018-09-17 09:00:00")
tdsql2.checkData(1, 0, "2018-09-17 09:00:01")
tdsql2 = tdCom.newTdSqlWithTimezone(timezone="Asia/Shanghai")
tdsql2.query(f"select * from {dbname}.tzt order by ts")
@ -160,7 +160,7 @@ class TDTestCase:
tdSql.prepare()
self.timeZoneTest()
self.inAndNotinTest()
# self.inAndNotinTest()
def stop(self):
@ -168,4 +168,5 @@ class TDTestCase:
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())