timezone.py 2.3 KB
Newer Older
Z
zhaoyanggh 已提交
1 2 3 4 5
import taos
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 18 19
        # get system timezone
        time_zone = os.popen('timedatectl | grep zone').read().strip().split(':')[1].lstrip()
        
J
jiacy-jcy 已提交
20
        tdLog.printNoPrefix("==========step1:create tables==========")
Z
zhaoyanggh 已提交
21
        tdSql.execute(
J
jiacy-jcy 已提交
22
            '''create table if not exists ntb
Z
zhaoyanggh 已提交
23 24 25
            (ts timestamp, c1 int, c2 float,c3 double)
            '''
        )
J
jiacy-jcy 已提交
26 27 28 29 30 31 32 33 34 35
        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 已提交
36
        tdLog.printNoPrefix("==========step2:insert data==========")
J
jiacy-jcy 已提交
37 38
        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 已提交
39

J
jiacy-jcy 已提交
40
        tdLog.printNoPrefix("==========step3:query data==========")
J
jiacy-jcy 已提交
41 42 43 44 45 46 47 48 49 50 51
        for i in range(0,10):
            tdSql.query("select timezone() from ntb")
            tdSql.checkRows(2)
            tdSql.checkData(0,0,time_zone)
            i+=1
            
        for i in range(0,10):
            tdSql.query("select timezone() from db.ntb")
            tdSql.checkRows(2)
            tdSql.checkData(0,0,time_zone)
            i+=1
J
update  
jiacy-jcy 已提交
52
        tdSql.query("select timezone() from stb")
J
jiacy-jcy 已提交
53
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
54
        tdSql.checkData(0,0,time_zone)
J
jiacy-jcy 已提交
55 56
        tdSql.query("select timezone() from db.stb")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
57
        tdSql.checkData(0,0,time_zone)
J
jiacy-jcy 已提交
58

J
jiacy-jcy 已提交
59 60
        tdSql.query("select timezone() from stb_1")
        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_1 ")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
64
        tdSql.checkData(0,0,time_zone)
J
jiacy-jcy 已提交
65

Z
zhaoyanggh 已提交
66 67 68 69 70 71 72 73


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

tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())