[TD-3639] <fix>: compare timestamp with datetime in python (#5990)

By this commit, It will close TD-3639.

It will not require test case to write *correct* datetime string to pass
a test case. One test could use seconds, milliseconds or microseconds to
check data.

That means the three tests are equivalent:

```python
.checkData(0, 0, "2020-01-01 00:00:00")
.checkData(0, 0, "2020-01-01 00:00:00.000")
.checkData(0, 0, "2020-01-01 00:00:00.000000")
```

Co-authored-by: Huo Linhe <linhehuo@gmail.com>
This commit is contained in:
Shuduo Sang 2021-04-30 22:45:59 +08:00 committed by GitHub
parent a7e41f2c86
commit b12668ff7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -136,6 +136,11 @@ class TDSql:
def checkData(self, row, col, data):
self.checkRowCol(row, col)
if self.queryResult[row][col] != data:
if self.cursor.istype(col, "TIMESTAMP") and self.queryResult[row][col] == datetime.datetime.fromisoformat(data):
tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" %
(self.sql, row, col, self.queryResult[row][col], data))
return
if str(self.queryResult[row][col]) == str(data):
tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" %
(self.sql, row, col, self.queryResult[row][col], data))