Merge branch 'main' into fix_chrome
This commit is contained in:
@@ -463,23 +463,60 @@ def compare_table(result: str, expected: str = None, **options) -> float:
|
||||
# }}} function compare_table #
|
||||
|
||||
|
||||
def compare_csv(result: str, expected: str, **options) -> float:
|
||||
def compare_csv(result: str, expected: Union[str, List[str]], **options) -> float:
|
||||
"""
|
||||
Compare CSV files. If expected is a list, returns 1.0 if result matches any of the expected files.
|
||||
|
||||
Args:
|
||||
result: Path to result CSV file
|
||||
expected: Path to expected CSV file or list of paths to expected CSV files
|
||||
options: Additional options (strict, ignore_case)
|
||||
|
||||
Returns:
|
||||
1.0 if result matches expected (or any file in expected list), 0.0 otherwise
|
||||
"""
|
||||
if result is None:
|
||||
return 0.
|
||||
|
||||
with open(result) as f:
|
||||
result_lines: Iterable[str] = f.read().splitlines()
|
||||
with open(expected) as f:
|
||||
expected_lines: Iterable[str] = f.read().splitlines()
|
||||
if not options.get("strict", True):
|
||||
result_lines = map(str.strip, result_lines)
|
||||
expected_lines = map(str.strip, expected_lines)
|
||||
if options.get("ignore_case", False):
|
||||
result_lines = map(str.lower, result_lines)
|
||||
expected_lines = map(str.lower, expected_lines)
|
||||
try:
|
||||
with open(result) as f:
|
||||
result_lines: Iterable[str] = f.read().splitlines()
|
||||
except (FileNotFoundError, IOError):
|
||||
return 0.
|
||||
|
||||
metric: bool = list(result_lines) == list(expected_lines)
|
||||
return float(metric)
|
||||
# Convert expected to list if it's a single string (for backward compatibility)
|
||||
if isinstance(expected, str):
|
||||
expected_files = [expected]
|
||||
else:
|
||||
expected_files = expected
|
||||
|
||||
# Try to match against each expected file
|
||||
for expected_file in expected_files:
|
||||
try:
|
||||
with open(expected_file) as f:
|
||||
expected_lines: Iterable[str] = f.read().splitlines()
|
||||
|
||||
# Process lines based on options
|
||||
current_result_lines = result_lines
|
||||
current_expected_lines = expected_lines
|
||||
|
||||
if not options.get("strict", True):
|
||||
current_result_lines = map(str.strip, current_result_lines)
|
||||
current_expected_lines = map(str.strip, current_expected_lines)
|
||||
if options.get("ignore_case", False):
|
||||
current_result_lines = map(str.lower, current_result_lines)
|
||||
current_expected_lines = map(str.lower, current_expected_lines)
|
||||
|
||||
# Check if this expected file matches
|
||||
if list(current_result_lines) == list(current_expected_lines):
|
||||
return 1.0
|
||||
|
||||
except (FileNotFoundError, IOError):
|
||||
# If this expected file doesn't exist, continue to next one
|
||||
continue
|
||||
|
||||
# No match found
|
||||
return 0.0
|
||||
|
||||
|
||||
def compare_conference_city_in_order(actual_city_list_path, expected_city):
|
||||
|
||||
Reference in New Issue
Block a user