test:update test case for coverage
This commit is contained in:
parent
9e65d3a29d
commit
9d3ceb1b32
|
@ -16,6 +16,7 @@ class TDTestCase:
|
|||
'2020-5-1 00:00:00.001002001'
|
||||
|
||||
]
|
||||
self.rest_tag = str(conn).lower().split('.')[0].replace("<taos","")
|
||||
self.db_param_precision = ['ms','us','ns']
|
||||
self.time_unit = ['1w','1d','1h','1m','1s','1a','1u','1b']
|
||||
self.error_unit = ['2w','2d','2h','2m','2s','2a','2u','1c','#1']
|
||||
|
@ -101,6 +102,7 @@ class TDTestCase:
|
|||
for i in range(len(self.ts_str)):
|
||||
tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i])-self.subtractor*1000000)))
|
||||
elif precision.lower() == 'ns':
|
||||
if self.rest_tag != 'rest':
|
||||
self.check_tb_type(unit,tb_type)
|
||||
tdSql.checkRows(len(self.ts_str))
|
||||
if unit.lower() == '1w':
|
||||
|
@ -162,10 +164,35 @@ class TDTestCase:
|
|||
date_time = self.get_time.time_transform(self.ts_str,precision)
|
||||
self.data_check(date_time,precision,'ctb')
|
||||
self.data_check(date_time,precision,'stb')
|
||||
def run(self): # sourcery skip: extract-duplicate-method
|
||||
def function_without_param(self):
|
||||
for precision in self.db_param_precision:
|
||||
tdSql.execute(f'drop database if exists {self.dbname}')
|
||||
tdSql.execute(f'create database {self.dbname} precision "{precision}"')
|
||||
tdSql.execute(f'use {self.dbname}')
|
||||
tdSql.execute(f'create table {self.stbname} (ts timestamp,c0 int) tags(t0 int)')
|
||||
tdSql.execute(f'create table {self.ctbname} using {self.stbname} tags(1)')
|
||||
for ts in self.ts_str:
|
||||
tdSql.execute(f'insert into {self.ctbname} values("{ts}",1)')
|
||||
date_time = self.get_time.time_transform(self.ts_str,precision)
|
||||
tdSql.query(f'select timediff(ts,{self.subtractor}) from {self.ctbname}')
|
||||
if precision.lower() == 'ms':
|
||||
for i in range(len(self.ts_str)):
|
||||
tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i])-self.subtractor*1000)))
|
||||
elif precision.lower() == 'us':
|
||||
for i in range(len(self.ts_str)):
|
||||
tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i])-self.subtractor*1000000)))
|
||||
elif precision.lower() == 'ns':
|
||||
for i in range(len(self.ts_str)):
|
||||
tdSql.checkEqual(tdSql.queryResult[i][0],int(((date_time[i])-self.subtractor*1000000000)))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def run(self): # sourcery skip: extract-duplicate-method
|
||||
self.function_check_ntb()
|
||||
self.function_check_stb()
|
||||
self.function_without_param()
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import taos
|
||||
import sys
|
||||
import datetime
|
||||
import inspect
|
||||
|
||||
import numpy as np
|
||||
from util.log import *
|
||||
from util.sql import *
|
||||
from util.cases import *
|
||||
|
||||
from util.sqlset import TDSetSql
|
||||
from util.common import *
|
||||
class TDTestCase:
|
||||
# updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 ,
|
||||
# "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143,
|
||||
|
@ -14,6 +13,51 @@ class TDTestCase:
|
|||
def init(self, conn, logSql):
|
||||
tdLog.debug(f"start to excute {__file__}")
|
||||
tdSql.init(conn.cursor(), False)
|
||||
self.setsql = TDSetSql()
|
||||
self.column_dict = {
|
||||
'ts':'timestamp',
|
||||
'col1': 'tinyint',
|
||||
'col2': 'smallint',
|
||||
'col3': 'int',
|
||||
'col4': 'bigint',
|
||||
'col5': 'tinyint unsigned',
|
||||
'col6': 'smallint unsigned',
|
||||
'col7': 'int unsigned',
|
||||
'col8': 'bigint unsigned',
|
||||
|
||||
}
|
||||
self.dbname = tdCom.getLongName(3,"letters")
|
||||
self.row_num = 10
|
||||
self.ts = 1537146000000
|
||||
def insert_data(self,column_dict,tbname,row_num):
|
||||
insert_sql = self.setsql.set_insertsql(column_dict,tbname)
|
||||
for i in range(row_num):
|
||||
insert_list = []
|
||||
self.setsql.insert_values(column_dict,i,insert_sql,insert_list,self.ts)
|
||||
|
||||
def avg_check_unsigned(self):
|
||||
stbname = f'{self.dbname}.{tdCom.getLongName(5,"letters")}'
|
||||
tag_dict = {
|
||||
't0':'int'
|
||||
}
|
||||
tag_values = [
|
||||
f'1'
|
||||
]
|
||||
tdSql.execute(f"create database if not exists {self.dbname}")
|
||||
tdSql.execute(self.setsql.set_create_stable_sql(stbname,self.column_dict,tag_dict))
|
||||
tdSql.execute(f"create table {stbname}_1 using {stbname} tags({tag_values[0]})")
|
||||
self.insert_data(self.column_dict,f'{stbname}_1',self.row_num)
|
||||
for col in self.column_dict.keys():
|
||||
col_val_list = []
|
||||
if col.lower() != 'ts':
|
||||
tdSql.query(f'select {col} from {stbname}_1')
|
||||
sum_val = 0
|
||||
for col_val in tdSql.queryResult:
|
||||
col_val_list.append(col_val[0])
|
||||
col_avg = np.mean(col_val_list)
|
||||
tdSql.query(f'select avg({col}) from {stbname}_1')
|
||||
tdSql.checkEqual(col_avg,tdSql.queryResult[0][0])
|
||||
tdSql.execute(f'drop database {self.dbname}')
|
||||
|
||||
def prepare_datas(self, dbname="db"):
|
||||
tdSql.execute(
|
||||
|
@ -412,6 +456,7 @@ class TDTestCase:
|
|||
tdLog.printNoPrefix("==========step6: avg filter query ============")
|
||||
|
||||
self.avg_func_filter()
|
||||
self.avg_check_unsigned()
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
###################################################################
|
||||
# Copyright (c) 2016 by TAOS Technologies, Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This file is proprietary and confidential to TAOS Technologies.
|
||||
# No part of this file may be reproduced, stored, transmitted,
|
||||
# disclosed or used in any form or by any means other than as
|
||||
# expressly provided by the written permission from Jianhui Tao
|
||||
#
|
||||
###################################################################
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import random
|
||||
import string
|
||||
import numpy as np
|
||||
from util.log import *
|
||||
from util.cases import *
|
||||
from util.sql import *
|
||||
from util.common import *
|
||||
from util.sqlset import *
|
||||
class TDTestCase:
|
||||
def init(self, conn, logSql):
|
||||
tdLog.debug("start to execute %s" % __file__)
|
||||
tdSql.init(conn.cursor())
|
||||
self.dbname = 'db_test'
|
||||
self.setsql = TDSetSql()
|
||||
self.ntbname = f'{self.dbname}.ntb'
|
||||
self.row_num = 10
|
||||
self.ts = 1537146000000
|
||||
self.column_dict = {
|
||||
'ts':'timestamp',
|
||||
'col1': 'tinyint',
|
||||
'col2': 'smallint',
|
||||
'col3': 'int',
|
||||
'col4': 'bigint',
|
||||
'col5': 'tinyint unsigned',
|
||||
'col6': 'smallint unsigned',
|
||||
'col7': 'int unsigned',
|
||||
'col8': 'bigint unsigned',
|
||||
|
||||
}
|
||||
def insert_data(self,column_dict,tbname,row_num):
|
||||
insert_sql = self.setsql.set_insertsql(column_dict,tbname)
|
||||
for i in range(row_num):
|
||||
insert_list = []
|
||||
self.setsql.insert_values(column_dict,i,insert_sql,insert_list,self.ts)
|
||||
def stddev_check(self):
|
||||
stbname = f'{self.dbname}.{tdCom.getLongName(5,"letters")}'
|
||||
tag_dict = {
|
||||
't0':'int'
|
||||
}
|
||||
tag_values = [
|
||||
f'1'
|
||||
]
|
||||
tdSql.execute(f"create database if not exists {self.dbname}")
|
||||
tdSql.execute(self.setsql.set_create_stable_sql(stbname,self.column_dict,tag_dict))
|
||||
tdSql.execute(f"create table {stbname}_1 using {stbname} tags({tag_values[0]})")
|
||||
self.insert_data(self.column_dict,f'{stbname}_1',self.row_num)
|
||||
for col in self.column_dict.keys():
|
||||
col_val_list = []
|
||||
if col.lower() != 'ts':
|
||||
tdSql.query(f'select {col} from {stbname}_1')
|
||||
for col_val in tdSql.queryResult:
|
||||
col_val_list.append(col_val[0])
|
||||
col_std = np.std(col_val_list)
|
||||
tdSql.query(f'select stddev({col}) from {stbname}_1')
|
||||
tdSql.checkEqual(col_std,tdSql.queryResult[0][0])
|
||||
tdSql.execute(f'drop database {self.dbname}')
|
||||
def run(self):
|
||||
self.stddev_check()
|
||||
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
tdLog.success(f"{__file__} successfully executed")
|
||||
|
||||
tdCases.addLinux(__file__, TDTestCase())
|
||||
tdCases.addWindows(__file__, TDTestCase())
|
|
@ -181,6 +181,7 @@ class TDTestCase:
|
|||
self.data_check(date_time,precision,'ctb')
|
||||
self.data_check(date_time,precision,'stb')
|
||||
|
||||
|
||||
def run(self):
|
||||
self.function_check_ntb()
|
||||
self.function_check_stb()
|
||||
|
|
Loading…
Reference in New Issue