timezone.py 2.5 KB
Newer Older
Z
zhaoyanggh 已提交
1 2 3 4 5
from tarfile import SYMTYPE
from time import sleep
from tkinter import E
import taos
import sys
J
jiacy-jcy 已提交
6 7
import time
from tzlocal import get_localzone
Z
zhaoyanggh 已提交
8 9 10 11
from util.log import *
from util.sql import *
from util.cases import *

J
jiacy-jcy 已提交
12
import os
Z
zhaoyanggh 已提交
13 14 15 16 17 18 19 20 21 22


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 已提交
23 24 25
        # get system timezone
        time_zone = os.popen('timedatectl | grep zone').read().strip().split(':')[1].lstrip()
        
J
jiacy-jcy 已提交
26
        tdLog.printNoPrefix("==========step1:create tables==========")
Z
zhaoyanggh 已提交
27
        tdSql.execute(
J
jiacy-jcy 已提交
28
            '''create table if not exists ntb
Z
zhaoyanggh 已提交
29 30 31
            (ts timestamp, c1 int, c2 float,c3 double)
            '''
        )
J
jiacy-jcy 已提交
32 33 34 35 36 37 38 39 40 41
        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 已提交
42
        tdLog.printNoPrefix("==========step2:insert data==========")
J
jiacy-jcy 已提交
43 44
        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 已提交
45

J
jiacy-jcy 已提交
46
        tdLog.printNoPrefix("==========step3:query data==========")
J
jiacy-jcy 已提交
47 48 49 50 51 52 53 54 55 56 57
        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 已提交
58
        tdSql.query("select timezone() from stb")
J
jiacy-jcy 已提交
59
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
60
        tdSql.checkData(0,0,time_zone)
J
jiacy-jcy 已提交
61 62
        tdSql.query("select timezone() from db.stb")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
63
        tdSql.checkData(0,0,time_zone)
J
jiacy-jcy 已提交
64

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

Z
zhaoyanggh 已提交
72 73 74 75 76 77 78 79


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

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