timezone.py 5.2 KB
Newer Older
J
update  
jiacy-jcy 已提交
1

Z
zhaoyanggh 已提交
2 3 4 5
from util.log import *
from util.sql import *
from util.cases import *

J
jiacy-jcy 已提交
6
import os
Z
zhaoyanggh 已提交
7 8 9 10 11 12 13 14 15 16


class TDTestCase:

    def init(self, conn, logSql):
        tdLog.debug(f"start to excute {__file__}")
        tdSql.init(conn.cursor())

    def run(self):  # sourcery skip: extract-duplicate-method
        tdSql.prepare()
J
jiacy-jcy 已提交
17
        # get system timezone
J
jiacy-jcy 已提交
18 19 20
        time_zone = os.popen('timedatectl | grep zone').read(
        ).strip().split(':')[1].lstrip()

J
jiacy-jcy 已提交
21
        tdLog.printNoPrefix("==========step1:create tables==========")
Z
zhaoyanggh 已提交
22
        tdSql.execute(
J
jiacy-jcy 已提交
23
            '''create table if not exists ntb
Z
zhaoyanggh 已提交
24 25 26
            (ts timestamp, c1 int, c2 float,c3 double)
            '''
        )
J
jiacy-jcy 已提交
27 28 29 30 31 32 33 34 35 36
        tdSql.execute(
            '''create table if not exists stb
            (ts timestamp, c1 int, c2 float,c3 double) tags(t0 int)
            '''
        )
        tdSql.execute(
            '''create table if not exists stb_1 using stb tags(100)
            '''
        )

J
jiacy-jcy 已提交
37
        tdLog.printNoPrefix("==========step2:insert data==========")
J
jiacy-jcy 已提交
38 39 40 41
        tdSql.execute(
            "insert into ntb values(now,10,99.99,11.111111)(today(),100,11.111,22.222222)")
        tdSql.execute(
            "insert into stb_1 values(now,111,99.99,11.111111)(today(),1,11.111,22.222222)")
Z
zhaoyanggh 已提交
42

J
jiacy-jcy 已提交
43
        tdLog.printNoPrefix("==========step3:query data==========")
J
update  
jiacy-jcy 已提交
44 45 46 47 48 49 50
        
        tdSql.query("select timezone() from ntb")
        tdSql.checkRows(2)
        tdSql.checkData(0, 0, time_zone)
        tdSql.query("select timezone() from db.ntb")
        tdSql.checkRows(2)
        tdSql.checkData(0, 0, time_zone)
J
update  
jiacy-jcy 已提交
51
        tdSql.query("select timezone() from stb")
J
jiacy-jcy 已提交
52
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
53
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
54 55
        tdSql.query("select timezone() from db.stb")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
56
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
57 58
        tdSql.query("select timezone() from stb_1")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
59
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
60 61
        tdSql.query("select timezone() from db.stb_1 ")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
62
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
63

J
update  
jiacy-jcy 已提交
64 65
        tdSql.error("select timezone(1) from stb")
        tdSql.error("select timezone(1) from db.stb")
J
jiacy-jcy 已提交
66
        tdSql.error("select timezone(1) from ntb")
J
update  
jiacy-jcy 已提交
67 68 69
        tdSql.error("select timezone(1) from db.ntb")
        tdSql.error("select timezone(1) from stb_1")
        tdSql.error("select timezone(1) from db.stb_1")
J
jiacy-jcy 已提交
70
        tdSql.error("select timezone(now()) from stb")
J
update  
jiacy-jcy 已提交
71
        tdSql.error("select timezone(now()) from db.stb")
Z
zhaoyanggh 已提交
72

J
jiacy-jcy 已提交
73 74
        tdSql.query(f"select * from ntb where timezone()='{time_zone}'")
        tdSql.checkRows(2)
J
update  
jiacy-jcy 已提交
75 76
        tdSql.query("select timezone()+1 from ntb")
        tdSql.checkRows(2)
J
update  
jiacy-jcy 已提交
77 78 79 80 81 82 83 84 85 86
        tdSql.query("select timezone()+1 from db.ntb")
        tdSql.checkRows(2)
        tdSql.query("select timezone()+1 from stb")
        tdSql.checkRows(2)
        tdSql.query("select timezone()+1 from db.stb")
        tdSql.checkRows(2)
        tdSql.query("select timezone()+1 from stb_1")
        tdSql.checkRows(2)
        tdSql.query("select timezone()+1 from db.stb_1")
        tdSql.checkRows(2)
J
update  
jiacy-jcy 已提交
87
        tdSql.query("select timezone()+1.5 from ntb")
J
update  
jiacy-jcy 已提交
88
        tdSql.checkRows(2)
J
update  
jiacy-jcy 已提交
89 90
        tdSql.query("select timezone()+1.5 from db.ntb")
        tdSql.checkRows(2)
J
update  
jiacy-jcy 已提交
91 92 93 94 95
        tdSql.query("select timezone()-100 from ntb")
        tdSql.checkRows(2)
        tdSql.query("select timezone()*100 from ntb")
        tdSql.checkRows(2)
        tdSql.query("select timezone()/10 from ntb")
J
jiacy-jcy 已提交
96
        # tdSql.query("select timezone()/0 from ntb")
Z
zhaoyanggh 已提交
97

J
update  
jiacy-jcy 已提交
98

J
update  
jiacy-jcy 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
        tdSql.query("select timezone()+null from ntb")
        tdSql.checkRows(2)
        tdSql.checkData(0,0,None)
        tdSql.query("select timezone()-null from ntb")
        tdSql.checkRows(2)
        tdSql.checkData(0,0,None)
        tdSql.query("select timezone()*null from ntb")
        tdSql.checkRows(2)
        tdSql.checkData(0,0,None)
        tdSql.query("select timezone()/null from ntb")
        tdSql.checkRows(2)
        tdSql.checkData(0,0,None)
        # tdSql.query("select timezone()")
        tdSql.query("select timezone()+null from stb")
        tdSql.checkRows(2)
        tdSql.checkData(0,0,None)
        tdSql.query("select timezone()-null from stb")
        tdSql.checkRows(2)
        tdSql.checkData(0,0,None)
        tdSql.query("select timezone()*null from stb")
        tdSql.checkRows(2)
        tdSql.checkData(0,0,None)
        tdSql.query("select timezone()/null from stb")
        tdSql.checkRows(2)
        tdSql.checkData(0,0,None)
        tdSql.query("select timezone()+null from stb_1")
        tdSql.checkRows(2)
        tdSql.checkData(0,0,None)
        tdSql.query("select timezone()-null from stb_1")
        tdSql.checkRows(2)
        tdSql.checkData(0,0,None)
        tdSql.query("select timezone()*null from stb_1")
        tdSql.checkRows(2)
        tdSql.checkData(0,0,None)
        tdSql.query("select timezone()/null from stb_1")
        tdSql.checkRows(2)
        tdSql.checkData(0,0,None)
Z
zhaoyanggh 已提交
136 137 138 139
    def stop(self):
        tdSql.close()
        tdLog.success(f"{__file__} successfully executed")

J
jiacy-jcy 已提交
140

Z
zhaoyanggh 已提交
141 142
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())