Skip to content

Commit e62c35f

Browse files
authored
Merge pull request #350 from AutomationSolutionz/compare-data-improvements
Compare data improvements
2 parents 9f17c4c + 62e0815 commit e62c35f

1 file changed

Lines changed: 55 additions & 1 deletion

File tree

Framework/Built_In_Automation/Sequential_Actions/common_functions.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,15 +991,54 @@ def New_Compare_Variables(step_data):
991991
check_exclusion = False
992992
check_subset = False
993993
compare_json = False; ignore_keys = []; map_keys = {}
994-
ignore_string_case = False; ignore_numeric_type_changes = False
994+
# Whether to be case-sensitive or not when comparing strings. By setting
995+
# ignore_string_case=False, strings will be compared case-insensitively.
996+
ignore_string_case = False
997+
ignore_numeric_type_changes = False
995998
global nested, datatype1, datatype2
996999
nested, datatype1, datatype2 = False, "", ""
9971000

1001+
# --- Deep-diff specific features, these default values are taken from the
1002+
# deep diff docs.
1003+
1004+
# truncate_datetime can take value one of ‘second’, ‘minute’, ‘hour’,
1005+
# ‘day’ and truncate with this value datetime objects before hashing it
1006+
truncate_datetime = None
1007+
1008+
# Whether to be case-sensitive or not when comparing strings. By setting
1009+
# ignore_string_case=False, strings will be compared case-insensitively.
1010+
ignore_string_case = False
1011+
1012+
# Whether to ignore float(‘nan’) inequality in Python.
1013+
ignore_nan_inequality = False
1014+
1015+
# significant_digits defines the number of digits AFTER the decimal point
1016+
# to be used in the comparison.
1017+
significant_digits = None
1018+
1019+
# math_epsilon uses Python’s built in Math.isclose. It defines a tolerance
1020+
# value which is passed to math.isclose(). Any numbers that are within the
1021+
# tolerance will not report as being different. Any numbers outside of
1022+
# that tolerance will show up as different.
1023+
math_epsilon = None
1024+
# --- Deep-diff end
1025+
9981026
for left, mid, right in step_data:
9991027
mid = mid.strip().lower()
10001028
if mid in ("compare", "element parameter"):
10011029
list1_name = left
10021030
list2_name = right
1031+
1032+
# Deep-diff specific features
1033+
elif "diff: truncate datetime" in left:
1034+
truncate_datetime = right.strip()
1035+
elif "diff: ignore nan inequality" in left:
1036+
ignore_nan_inequality = CommonUtil.parse_value_into_object(right) == True
1037+
elif "diff: significant digits" in left:
1038+
significant_digits = int(CommonUtil.parse_value_into_object(right))
1039+
elif "diff: math epsilon" in left:
1040+
math_epsilon = float(CommonUtil.parse_value_into_object(right))
1041+
10031042
elif "action" in mid:
10041043
action_type = right.replace(" ", "").replace("_", "").lower()
10051044
if "exactmatch" in action_type:
@@ -1016,6 +1055,7 @@ def New_Compare_Variables(step_data):
10161055
ignore_numeric_type_changes = True
10171056
if "ignorestringcase" in action_type:
10181057
ignore_string_case = True
1058+
10191059
elif left.replace(" ", "").replace("_", "").lower() == "ignorekeys":
10201060
ignore_keys = CommonUtil.parse_value_into_object(right.strip())
10211061
elif left.replace(" ", "").replace("_", "").lower() == "mapkeys":
@@ -1024,6 +1064,10 @@ def New_Compare_Variables(step_data):
10241064
Left = left.strip()
10251065
Right = right.strip()
10261066

1067+
if math_epsilon:
1068+
match_by_index = False
1069+
CommonUtil.ExecLog(sModuleInfo, f"Match By Index is set to False as Math Epsilon is being used", 2)
1070+
10271071
list1 = CommonUtil.parse_value_into_object(list1_name)
10281072
list2 = CommonUtil.parse_value_into_object(list2_name)
10291073

@@ -1052,6 +1096,11 @@ def New_Compare_Variables(step_data):
10521096
ignore_order=not match_by_index,
10531097
ignore_string_case=ignore_string_case,
10541098
ignore_numeric_type_changes=ignore_numeric_type_changes,
1099+
1100+
truncate_datetime=truncate_datetime,
1101+
ignore_nan_inequality=ignore_nan_inequality,
1102+
significant_digits=significant_digits,
1103+
math_epsilon=math_epsilon,
10551104
)
10561105

10571106
diff21 = DeepDiff(
@@ -1060,6 +1109,11 @@ def New_Compare_Variables(step_data):
10601109
ignore_order=not match_by_index,
10611110
ignore_string_case=ignore_string_case,
10621111
ignore_numeric_type_changes=ignore_numeric_type_changes,
1112+
1113+
truncate_datetime=truncate_datetime,
1114+
ignore_nan_inequality=ignore_nan_inequality,
1115+
significant_digits=significant_digits,
1116+
math_epsilon=math_epsilon,
10631117
)
10641118
if not diff21 and not diff12:
10651119
CommonUtil.ExecLog(sModuleInfo, f"{Left} ({datatype1}):\n{list1_str}\n\n{Right} ({datatype2}):\n{list2_str}", 1)

0 commit comments

Comments
 (0)