Skip to content

Commit

Permalink
fix(tests): Update Common.py to add compare_dot_file() keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
bouda1 authored Feb 26, 2024
1 parent 0dd3f91 commit 9b50226
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/resources/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,3 +1471,40 @@ def has_file_permissions(path: str, permission: int):
return False
masked = stat_res.st_mode & permission
return masked == permission

def compare_dot_files(file1: str, file2: str):
"""
Compare two dot files file1 and file2 after removing the pointer addresses
that clearly are not the same.
Args:
file1: The first file to compare.
file2: The second file to compare.
Returns: True if they have the same content, False otherwise.
"""

with open(file1, "r") as f1:
content1 = f1.readlines()
with open(file2, "r") as f2:
content2 = f2.readlines()
r = re.compile(r"(.*) 0x[0-9a-f]+")

def replace_ptr(line):
m = r.match(line)
if m:
return m.group(1)
else:
return line

content1 = list(map(replace_ptr, content1))
content2 = list(map(replace_ptr, content2))

if len(content1) != len(content2):
return False
for i in range(len(content1)):
if content1[i] != content2[i]:
logger.console(
f"Files are different at line {i + 1}: first => << {content1[i].strip()} >> and second => << {content2[i].strip()} >>")
return False
return True

0 comments on commit 9b50226

Please sign in to comment.