Now.py 4.0 KB
Newer Older
J
update  
jiacy-jcy 已提交
1

J
jiacy-jcy 已提交
2 3 4 5
from util.dnodes import *
from util.log import *
from util.sql import *
from util.cases import *
J
jiacy-jcy 已提交
6
from util.sqlset import *
J
jiacy-jcy 已提交
7 8 9 10 11

class TDTestCase:

    def init(self, conn, logSql):
        tdLog.debug(f"start to excute {__file__}")
12
        tdSql.init(conn.cursor(),True)
J
jiacy-jcy 已提交
13 14
        self.setsql = TDSetSql()
        # name of normal table
G
Ganlin Zhao 已提交
15
        self.ntbname = 'ntb'
J
jiacy-jcy 已提交
16
        # name of stable
G
Ganlin Zhao 已提交
17
        self.stbname = 'stb'
J
jiacy-jcy 已提交
18
        # structure of column
G
Ganlin Zhao 已提交
19
        self.column_dict = {
J
jiacy-jcy 已提交
20 21 22 23 24 25
            'ts':'timestamp',
            'c1':'int',
            'c2':'float',
            'c3':'double'
        }
        # structure of tag
G
Ganlin Zhao 已提交
26
        self.tag_dict = {
J
jiacy-jcy 已提交
27 28 29
            't0':'int'
        }
        # number of child tables
G
Ganlin Zhao 已提交
30
        self.tbnum = 2
J
jiacy-jcy 已提交
31
        # values of tag,the number of values should equal to tbnum
G
Ganlin Zhao 已提交
32
        self.tag_values = [
J
jiacy-jcy 已提交
33 34 35 36 37 38 39 40
            f'10',
            f'100'
        ]
        self.values_list = [
            f'now,10,99.99,11.111111',
            f'today(),100,11.111,22.222222'
        ]
        self.time_unit = ['b','u','a','s','m','h','d','w']
41 42
        self.symbol = ['+','-','*','/']
        self.error_values = [1.5,'abc','"abc"','!@','today()']
J
jiacy-jcy 已提交
43
        self.db_percision = ['ms','us','ns']
44 45
    def tbtype_check(self,tb_type):
        if tb_type == 'normal table' or tb_type == 'child table':
G
Ganlin Zhao 已提交
46
            tdSql.checkRows(len(self.values_list))
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
        elif tb_type == 'stable':
            tdSql.checkRows(len(self.values_list) * self.tbnum)
    def data_check(self,tbname,tb_type):
        tdSql.query(f'select now() from {tbname}')
        self.tbtype_check(tb_type)
        for unit in self.time_unit:
            for symbol in self.symbol:
                if symbol in ['+','-']:
                    tdSql.query(f'select now() {symbol}1{unit} from {tbname}')
                    self.tbtype_check(tb_type)
        for k,v in self.column_dict.items():
            if v.lower() != 'timestamp':
                continue
            else:
                tdSql.query(f'select * from {tbname} where {k}>=now()')
                tdSql.checkRows(0)
                tdSql.query(f'select * from {tbname} where {k}<now()')
                self.tbtype_check(tb_type)
        for symbol in self.symbol:
            for param in self.error_values:
                tdSql.error(f'select now() {symbol}{param} from {tbname}')
            tdSql.query(f'select now(){symbol}null from {tbname}')
            self.tbtype_check(tb_type)
            for i in range(len(self.values_list)):
                tdSql.checkData(i,0,None)
J
jiacy-jcy 已提交
72 73

    def now_check_ntb(self):
J
jiacy-jcy 已提交
74 75 76 77 78 79 80 81 82
        for time_unit in self.db_percision:
            tdSql.execute(f'create database db precision "{time_unit}"')
            tdSql.execute('use db')
            tdSql.execute(self.setsql.set_create_normaltable_sql(self.ntbname,self.column_dict))
            for value in self.values_list:
                tdSql.execute(
                    f'insert into {self.ntbname} values({value})')
            self.data_check(self.ntbname,'normal table')
            tdSql.execute('drop database db')
J
jiacy-jcy 已提交
83 84

    def now_check_stb(self):
J
jiacy-jcy 已提交
85 86 87 88 89 90 91 92 93 94 95 96
        for time_unit in self.db_percision:
            tdSql.execute(f'create database db precision "{time_unit}"')
            tdSql.execute('use db')
            tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,self.column_dict,self.tag_dict))
            for i in range(self.tbnum):
                tdSql.execute(f"create table {self.stbname}_{i} using {self.stbname} tags({self.tag_values[0]})")
                for value in self.values_list:
                    tdSql.execute(f'insert into {self.stbname}_{i} values({value})')
            for i in range(self.tbnum):
                self.data_check(f'{self.stbname}_{i}','child table')
            self.data_check(self.stbname,'stable')
            tdSql.execute('drop database db')
97
    def run(self):  # sourcery skip: extract-duplicate-method
J
jiacy-jcy 已提交
98

99 100
        self.now_check_ntb()
        self.now_check_stb()
G
Ganlin Zhao 已提交
101

J
jiacy-jcy 已提交
102 103 104 105 106 107 108
    def stop(self):
        tdSql.close()
        tdLog.success(f"{__file__} successfully executed")


tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())