timezone.py 2.7 KB
Newer Older
J
jiacy-jcy 已提交
1
from pytz import timezone
Z
zhaoyanggh 已提交
2 3 4 5 6
import taos
from util.log import *
from util.sql import *
from util.cases import *

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


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 已提交
18
        # get system timezone
J
jiacy-jcy 已提交
19 20 21
        time_zone = os.popen('timedatectl | grep zone').read(
        ).strip().split(':')[1].lstrip()

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

J
jiacy-jcy 已提交
44
        tdLog.printNoPrefix("==========step3:query data==========")
J
jiacy-jcy 已提交
45
        for i in range(0, 10):
J
jiacy-jcy 已提交
46 47
            tdSql.query("select timezone() from ntb")
            tdSql.checkRows(2)
J
jiacy-jcy 已提交
48 49 50 51
            tdSql.checkData(0, 0, time_zone)
            i += 1

        for i in range(0, 10):
J
jiacy-jcy 已提交
52 53
            tdSql.query("select timezone() from db.ntb")
            tdSql.checkRows(2)
J
jiacy-jcy 已提交
54 55
            tdSql.checkData(0, 0, time_zone)
            i += 1
J
update  
jiacy-jcy 已提交
56
        tdSql.query("select timezone() from stb")
J
jiacy-jcy 已提交
57
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
58
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
59 60
        tdSql.query("select timezone() from db.stb")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
61
        tdSql.checkData(0, 0, time_zone)
J
jiacy-jcy 已提交
62

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

J
jiacy-jcy 已提交
70 71
        tdSql.error("select timezone(1) from ntb")
        tdSql.error("select timezone(now()) from 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
        tdSql.error("select timezone()+1 from ntb")
Z
zhaoyanggh 已提交
76 77 78 79 80

    def stop(self):
        tdSql.close()
        tdLog.success(f"{__file__} successfully executed")

J
jiacy-jcy 已提交
81

Z
zhaoyanggh 已提交
82 83
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())