timezone.py 5.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
18 19 20 21 22 23 24 25 26 27
        time_zone_arr = os.popen('timedatectl | grep zone').read(
        ).strip().split(':')
        if len(time_zone_arr) > 1:
            time_zone = time_zone_arr[1].lstrip()
        else:
            # possibly in a docker container
            time_zone_1 = os.popen('ls -l /etc/localtime|awk -F/ \'{print $(NF-1) "/" $NF}\'').read().strip()
            time_zone_2 = os.popen('date "+(%Z, %z)"').read().strip()
            time_zone = time_zone_1 + " " + time_zone_2
            print("expected time zone: " + time_zone)
J
jiacy-jcy 已提交
28

J
jiacy-jcy 已提交
29
        tdLog.printNoPrefix("==========step1:create tables==========")
Z
zhaoyanggh 已提交
30
        tdSql.execute(
J
jiacy-jcy 已提交
31
            '''create table if not exists ntb
Z
zhaoyanggh 已提交
32 33 34
            (ts timestamp, c1 int, c2 float,c3 double)
            '''
        )
J
jiacy-jcy 已提交
35 36 37 38 39 40 41 42 43 44
        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 已提交
45
        tdLog.printNoPrefix("==========step2:insert data==========")
J
jiacy-jcy 已提交
46 47 48 49
        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 已提交
50

J
jiacy-jcy 已提交
51
        tdLog.printNoPrefix("==========step3:query data==========")
J
update  
jiacy-jcy 已提交
52 53 54 55 56 57 58
        
        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 已提交
59
        tdSql.query("select timezone() from stb")
J
jiacy-jcy 已提交
60
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
61
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
62 63
        tdSql.query("select timezone() from db.stb")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
64
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
65 66
        tdSql.query("select timezone() from stb_1")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
67
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
68 69
        tdSql.query("select timezone() from db.stb_1 ")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
70
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
71

J
update  
jiacy-jcy 已提交
72 73
        tdSql.error("select timezone(1) from stb")
        tdSql.error("select timezone(1) from db.stb")
J
jiacy-jcy 已提交
74
        tdSql.error("select timezone(1) from ntb")
J
update  
jiacy-jcy 已提交
75 76 77
        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 已提交
78
        tdSql.error("select timezone(now()) from stb")
J
update  
jiacy-jcy 已提交
79
        tdSql.error("select timezone(now()) from db.stb")
Z
zhaoyanggh 已提交
80

J
jiacy-jcy 已提交
81 82
        tdSql.query(f"select * from ntb where timezone()='{time_zone}'")
        tdSql.checkRows(2)
J
update  
jiacy-jcy 已提交
83 84
        tdSql.query("select timezone()+1 from ntb")
        tdSql.checkRows(2)
J
update  
jiacy-jcy 已提交
85 86 87 88 89 90 91 92 93 94
        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 已提交
95
        tdSql.query("select timezone()+1.5 from ntb")
J
update  
jiacy-jcy 已提交
96
        tdSql.checkRows(2)
J
update  
jiacy-jcy 已提交
97 98
        tdSql.query("select timezone()+1.5 from db.ntb")
        tdSql.checkRows(2)
J
update  
jiacy-jcy 已提交
99 100 101 102 103
        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 已提交
104
        # tdSql.query("select timezone()/0 from ntb")
Z
zhaoyanggh 已提交
105

J
update  
jiacy-jcy 已提交
106

J
update  
jiacy-jcy 已提交
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 136 137 138 139 140 141 142 143
        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 已提交
144 145 146 147
    def stop(self):
        tdSql.close()
        tdLog.success(f"{__file__} successfully executed")

J
jiacy-jcy 已提交
148

Z
zhaoyanggh 已提交
149 150
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())