-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtestutils.py
More file actions
49 lines (39 loc) · 1.61 KB
/
Copy pathtestutils.py
File metadata and controls
49 lines (39 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import re
# Compare results with expected file
def compare_model(comp_results, file_name):
def normalize(text):
"""Normalize text by removing extra spaces, tabs, and Unicode variations."""
text = text.strip() # Remove leading/trailing spaces
text = re.sub(
r"\s+", " ", text
) # Replace multiple spaces/tabs/newlines with a single space
return text
with open(file_name, "r", encoding="utf-8") as file:
for r, line in zip(comp_results.split("\n"), file.readlines()):
line = normalize(line)
r = normalize(r)
if r != line:
print("file: " + line)
print("test: " + r)
return False
return True
def compare_model_ignore_order(comp_results, file_name):
with open(file_name, "r") as file:
file_lines = {line.strip() for line in file.readlines() if line.strip()}
result_lines = {
line.strip() for line in comp_results.split("\n") if line.strip()
}
# Check if both sets of lines are equal
if file_lines != result_lines:
missing_in_file = result_lines - file_lines
missing_in_results = file_lines - result_lines
if missing_in_file:
print("Lines in results but not in file:")
for line in missing_in_file:
print(f"test: {line}")
if missing_in_results:
print("Lines in file but not in results:")
for line in missing_in_results:
print(f"file: {line}")
return False
return True