Skip to content
Permalink
Browse files

Allow casting date/datetime values to string to compare to expected r…

…esults
  • Loading branch information
nyalldawson committed Feb 5, 2021
1 parent 45ad2f1 commit 318dbc86caddc7e60cd8b3b214884c536ffba57d
Showing with 13 additions and 3 deletions.
  1. +13 −3 python/testing/__init__.py
@@ -28,7 +28,7 @@
import filecmp
import tempfile

from qgis.PyQt.QtCore import QVariant
from qgis.PyQt.QtCore import QVariant, QDateTime, QDate
from qgis.core import (
QgsApplication,
QgsFeatureRequest,
@@ -305,8 +305,18 @@ def checkAttributesEqual(self, feat0, feat1, fields_expected, use_asserts, compa
attr_result = float(attr_result) if attr_result else None
isNumber = True
if cmp['cast'] == 'str':
attr_expected = str(attr_expected) if attr_expected else None
attr_result = str(attr_result) if attr_result else None
if isinstance(attr_expected, QDateTime):
attr_expected = attr_expected.toString('yyyy/MM/dd hh:mm:ss')
elif isinstance(attr_expected, QDate):
attr_expected = attr_expected.toString('yyyy/MM/dd')
else:
attr_expected = str(attr_expected) if attr_expected else None
if isinstance(attr_result, QDateTime):
attr_result = attr_result.toString('yyyy/MM/dd hh:mm:ss')
elif isinstance(attr_result, QDate):
attr_result = attr_result.toString('yyyy/MM/dd')
else:
attr_result = str(attr_result) if attr_result else None

# Round field (only numeric so it works with __all__)
if 'precision' in cmp and (field_expected.type() in [QVariant.Int, QVariant.Double, QVariant.LongLong] or isNumber):

0 comments on commit 318dbc8

Please sign in to comment.