Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6e66b74b
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
6e66b74b
编写于
3月 23, 2023
作者:
T
t_max
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: fix check timestamp data
上级
e12bb340
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
25 addition
and
27 deletion
+25
-27
tests/pytest/util/sql.py
tests/pytest/util/sql.py
+25
-27
未找到文件。
tests/pytest/util/sql.py
浏览文件 @
6e66b74b
...
...
@@ -24,26 +24,12 @@ from util.log import *
from
util.constant
import
*
# from datetime import timezone
from
tzlocal
import
get_localzone
import
pytz
import
time
def
_locaTzTimeStamp
(
utctimestamp
):
tz
=
get_localzone
()
temptz
=
str
(
tz
)
localtz
=
pytz
.
timezone
(
temptz
)
defUtctimestamp
=
1035640800
local_dt
=
datetime
.
datetime
(
2002
,
10
,
27
,
6
,
0
,
0
,
tzinfo
=
localtz
)
defLocaltimestamp
=
time
.
mktime
(
local_dt
.
timetuple
())
deltaTzTime
=
int
(
defLocaltimestamp
)
-
int
(
defUtctimestamp
)
temp
=
int
(
str
(
utctimestamp
)[
0
:
10
])
tempOther
=
str
(
utctimestamp
)[
10
-
len
(
str
(
utctimestamp
)):]
localtemp
=
deltaTzTime
+
temp
localAll
=
str
(
localtemp
)
+
str
(
tempOther
)
localtimestamp
=
int
(
localAll
)
print
(
f
"local timezone is
{
localtimestamp
}
, Deltel time is
{
deltaTzTime
}
s"
)
return
localtimestamp
def
_parse_ns_timestamp
(
timestr
):
dt_obj
=
datetime
.
datetime
.
strptime
(
timestr
[:
len
(
timestr
)
-
3
],
"%Y-%m-%d %H:%M:%S.%f"
)
tz
=
int
(
int
((
dt_obj
-
datetime
.
datetime
.
fromtimestamp
(
0
,
dt_obj
.
tzinfo
)).
total_seconds
())
*
1e9
)
+
int
(
dt_obj
.
microsecond
*
1000
)
+
int
(
timestr
[
-
3
:])
return
tz
def
_parse_datetime
(
timestr
):
...
...
@@ -268,8 +254,7 @@ class TDSql:
# suppose user want to check nanosecond timestamp if a longer data passed``
if
isinstance
(
data
,
str
)
:
if
(
len
(
data
)
>=
28
):
resultData
=
_locaTzTimeStamp
(
self
.
queryResult
[
row
][
col
])
if
pd
.
to_datetime
(
resultData
)
==
pd
.
to_datetime
(
data
):
if
self
.
queryResult
[
row
][
col
]
==
_parse_ns_timestamp
(
data
):
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{pd.to_datetime(resultData)} == expect:{data}")
tdLog
.
info
(
"check successfully"
)
else
:
...
...
@@ -277,7 +262,7 @@ class TDSql:
args
=
(
caller
.
filename
,
caller
.
lineno
,
self
.
sql
,
row
,
col
,
self
.
queryResult
[
row
][
col
],
data
)
tdLog
.
exit
(
"%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s"
%
args
)
else
:
if
self
.
queryResult
[
row
][
col
]
==
_parse_datetime
(
data
):
if
self
.
queryResult
[
row
][
col
]
.
astimezone
(
datetime
.
timezone
.
utc
)
==
_parse_datetime
(
data
).
astimezone
(
datetime
.
timezone
.
utc
):
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
tdLog
.
info
(
"check successfully"
)
else
:
...
...
@@ -287,18 +272,31 @@ class TDSql:
return
elif
isinstance
(
data
,
int
)
:
if
len
(
str
(
data
))
==
16
:
unitTime
=
'us'
precision
=
'us'
elif
len
(
str
(
data
))
==
13
:
unitTime
=
'ms'
precision
=
'ms'
elif
len
(
str
(
data
))
==
19
:
unitTime
=
'ns'
precision
=
'ns'
else
:
caller
=
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
])
args
=
(
caller
.
filename
,
caller
.
lineno
,
self
.
sql
,
row
,
col
,
self
.
queryResult
[
row
][
col
],
data
)
tdLog
.
exit
(
"%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s"
%
args
)
resultData
=
pd
.
to_datetime
(
_locaTzTimeStamp
(
data
),
unit
=
unitTime
)
if
resultData
==
self
.
queryResult
[
row
][
col
]
:
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{resultData}")
return
success
=
False
if
precision
==
'ms'
:
dt_obj
=
self
.
queryResult
[
row
][
col
]
tz
=
int
(
int
((
dt_obj
-
datetime
.
datetime
.
fromtimestamp
(
0
,
dt_obj
.
tzinfo
)).
total_seconds
())
*
1000
)
+
int
(
dt_obj
.
microsecond
/
1000
)
if
tz
==
data
:
success
=
True
elif
precision
==
'us'
:
dt_obj
=
self
.
queryResult
[
row
][
col
]
tz
=
int
(
int
((
dt_obj
-
datetime
.
datetime
.
fromtimestamp
(
0
,
dt_obj
.
tzinfo
)).
total_seconds
())
*
1e6
)
+
int
(
dt_obj
.
microsecond
)
if
tz
==
data
:
success
=
True
elif
precision
==
'ns'
:
if
data
==
self
.
queryResult
[
row
][
col
]:
success
=
True
if
success
:
tdLog
.
info
(
"check successfully"
)
else
:
caller
=
inspect
.
getframeinfo
(
inspect
.
stack
()[
1
][
0
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录