Skip to content
Permalink
Browse files

perform rounding either if field type is numeric or if value was casted

to the number
  • Loading branch information
alexbruy authored and nyalldawson committed Jun 15, 2020
1 parent 4b1f612 commit 136c5a4bc2556624ff9379fb362765ea9e4f9f37
Showing with 4 additions and 1 deletion.
  1. +4 −1 python/testing/__init__.py
@@ -269,19 +269,22 @@ def checkAttributesEqual(self, feat0, feat1, fields_expected, use_asserts, compa
field_result = [fld for fld in fields_expected.toList() if fld.name() == field_expected.name()][0]

# Cast field to a given type
isNumber = False
if 'cast' in cmp:
if cmp['cast'] == 'int':
attr_expected = int(attr_expected) if attr_expected else None
attr_result = int(attr_result) if attr_result else None
isNumber = True
if cmp['cast'] == 'float':
attr_expected = float(attr_expected) if attr_expected else None
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

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

0 comments on commit 136c5a4

Please sign in to comment.
You can’t perform that action at this time.