timezone.py 4.6 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
        tdSql.query("select timezone()+1.5 from ntb")
J
update  
jiacy-jcy 已提交
78 79 80 81 82 83
        tdSql.checkRows(2)
        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")
Z
zhaoyanggh 已提交
84

J
update  
jiacy-jcy 已提交
85

J
update  
jiacy-jcy 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
        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 已提交
123 124 125 126
    def stop(self):
        tdSql.close()
        tdLog.success(f"{__file__} successfully executed")

J
jiacy-jcy 已提交
127

Z
zhaoyanggh 已提交
128 129
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())