Skip to content

Commit

Permalink
Merge pull request #22919 from taosdata/case/TS-3897-MAIN
Browse files Browse the repository at this point in the history
test: sql.py remove successful print and add diff case
  • Loading branch information
DuanKuanJun committed Sep 20, 2023
2 parents 6e46224 + 30c24eb commit b29929a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
27 changes: 17 additions & 10 deletions tests/pytest/util/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def checkDataType(self, row, col, dataType):
return self.cursor.istype(col, dataType)


def checkData(self, row, col, data):
def checkData(self, row, col, data, show = False):
if row >= self.queryRows:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row+1, self.queryRows)
Expand All @@ -275,16 +275,17 @@ def checkData(self, row, col, data):
if isinstance(data,str) :
if (len(data) >= 28):
if self.queryResult[row][col] == _parse_ns_timestamp(data):
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{pd.to_datetime(resultData)} == expect:{data}")
tdLog.info("check successfully")
if(show):
tdLog.info("check successfully")
else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
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:
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("check successfully")
if(show):
tdLog.info("check successfully")
else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
Expand Down Expand Up @@ -317,7 +318,8 @@ def checkData(self, row, col, data):
if data == self.queryResult[row][col]:
success = True
if success:
tdLog.info("check successfully")
if(show):
tdLog.info("check successfully")
else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
Expand All @@ -328,7 +330,8 @@ def checkData(self, row, col, data):
delt_data = data-datetime.datetime.fromtimestamp(0,data.tzinfo)
delt_result = self.queryResult[row][col] - datetime.datetime.fromtimestamp(0,self.queryResult[row][col].tzinfo)
if delt_data == delt_result:
tdLog.info("check successfully")
if(show):
tdLog.info("check successfully")
else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
Expand All @@ -341,16 +344,19 @@ def checkData(self, row, col, data):

if str(self.queryResult[row][col]) == str(data):
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
tdLog.info("check successfully")
if(show):
tdLog.info("check successfully")
return

elif isinstance(data, float):
if abs(data) >= 1 and abs((self.queryResult[row][col] - data) / data) <= 0.000001:
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
tdLog.info("check successfully")
if(show):
tdLog.info("check successfully")
elif abs(data) < 1 and abs(self.queryResult[row][col] - data) <= 0.000001:
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
tdLog.info("check successfully")
if(show):
tdLog.info("check successfully")

else:
caller = inspect.getframeinfo(inspect.stack()[1][0])
Expand All @@ -361,7 +367,8 @@ def checkData(self, row, col, data):
caller = inspect.getframeinfo(inspect.stack()[1][0])
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.info("check successfully")
if(show):
tdLog.info("check successfully")

# return true or false replace exit, no print out
def checkRowColNoExit(self, row, col):
Expand Down
13 changes: 8 additions & 5 deletions tests/system-test/0-others/walRetention.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,14 @@ def load(self, path):
# load config
tdLog.info(f' meta-ver file={metaFile}')
if metaFile != "":
jsonVer = jsonFromFile(metaFile)
metaNode = jsonVer["meta"]
self.snapVer = int(metaNode["snapshotVer"])
self.firstVer = int(metaNode["firstVer"])
self.lastVer = int(metaNode["lastVer"])
try:
jsonVer = jsonFromFile(metaFile)
metaNode = jsonVer["meta"]
self.snapVer = int(metaNode["snapshotVer"])
self.firstVer = int(metaNode["firstVer"])
self.lastVer = int(metaNode["lastVer"])
except Exception as e:
tdLog.info(f' read json file except.')

# sort with startVer
self.walFiles = sorted(self.walFiles, key=lambda x : x.startVer, reverse=True)
Expand Down
29 changes: 29 additions & 0 deletions tests/system-test/2-query/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,39 @@ def init(self, conn, logSql, replicaVar=1):
def check_result(self):
for i in range(self.rowNum):
tdSql.checkData(i, 0, 1);

def full_datatype_test(self):
tdSql.execute("use db;")
sql = "create table db.st(ts timestamp, c1 bool, c2 float, c3 double,c4 tinyint, c5 smallint, c6 int, c7 bigint, c8 tinyint unsigned, c9 smallint unsigned, c10 int unsigned, c11 bigint unsigned) tags( area int);"
tdSql.execute(sql)

sql = "create table db.t1 using db.st tags(1);"
tdSql.execute(sql)

ts = 1694000000000
rows = 126
for i in range(rows):
ts += 1
sql = f"insert into db.t1 values({ts},true,{i},{i},{i%127},{i%32767},{i},{i},{i%127},{i%32767},{i},{i});"
tdSql.execute(sql)

sql = "select diff(ts),diff(c1),diff(c3),diff(c4),diff(c5),diff(c6),diff(c7),diff(c8),diff(c9),diff(c10),diff(c11) from db.t1"
tdSql.query(sql)
tdSql.checkRows(rows - 1)
for i in range(rows - 1):
for j in range(10):
if j == 1: # bool
tdSql.checkData(i, j, 0)
else:
tdSql.checkData(i, j, 1)

def run(self):
tdSql.prepare()
dbname = "db"

# full type test
self.full_datatype_test()

tdSql.execute(
f"create table {dbname}.ntb(ts timestamp,c1 int,c2 double,c3 float)")
tdSql.execute(
Expand Down

0 comments on commit b29929a

Please sign in to comment.