Skip to content

Commit

Permalink
perform rounding either if field type is numeric or if value was casted
Browse files Browse the repository at this point in the history
to the number
  • Loading branch information
alexbruy authored and nyalldawson committed Jun 15, 2020
1 parent 4b1f612 commit 136c5a4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python/testing/__init__.py
Expand Up @@ -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:
Expand Down

0 comments on commit 136c5a4

Please sign in to comment.