timezone.py 2.7 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
        
        tdSql.query("select timezone() from ntb")
        tdSql.checkRows(2)
        tdSql.checkData(0, 0, time_zone)
            
J
jiacy-jcy 已提交
49

J
update  
jiacy-jcy 已提交
50 51 52 53 54
        
        tdSql.query("select timezone() from db.ntb")
        tdSql.checkRows(2)
        tdSql.checkData(0, 0, time_zone)
        
J
update  
jiacy-jcy 已提交
55
        tdSql.query("select timezone() from stb")
J
jiacy-jcy 已提交
56
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
57
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
58 59
        tdSql.query("select timezone() from db.stb")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
60
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
61

J
jiacy-jcy 已提交
62 63
        tdSql.query("select timezone() from stb_1")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
64
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
65 66
        tdSql.query("select timezone() from db.stb_1 ")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
67
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
68

J
jiacy-jcy 已提交
69 70
        tdSql.error("select timezone(1) from ntb")
        tdSql.error("select timezone(now()) from stb")
Z
zhaoyanggh 已提交
71

J
jiacy-jcy 已提交
72 73
        tdSql.query(f"select * from ntb where timezone()='{time_zone}'")
        tdSql.checkRows(2)
J
update  
jiacy-jcy 已提交
74 75
        tdSql.query("select timezone()+1 from ntb")
        tdSql.checkRows(2)
J
update  
jiacy-jcy 已提交
76
        tdSql.query("select timezone()+1.5 from ntb")
Z
zhaoyanggh 已提交
77

J
update  
jiacy-jcy 已提交
78 79
        # tdSql.query("select timezone()")

Z
zhaoyanggh 已提交
80 81 82 83
    def stop(self):
        tdSql.close()
        tdLog.success(f"{__file__} successfully executed")

J
jiacy-jcy 已提交
84

Z
zhaoyanggh 已提交
85 86
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())