Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(coverage): Prevent hard failure in case of empty file #30707

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions tasks/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,22 @@ def _merge_dev_in_main_coverage(main_cov_file: str, dev_cov_file: str) -> None:
"""
with open(main_cov_file, encoding='utf-8') as main_cov:
main_cov_lines = main_cov.readlines()
main_mode_line = main_cov_lines.pop(0)
with open(dev_cov_file, encoding='utf-8') as dev_cov:
dev_cov_lines = dev_cov.readlines()
dev_mode_line = dev_cov_lines.pop(0)

if len(main_cov_lines) == 0:
print(f"[{color_message('WARNING', Color.ORANGE)}] Main coverage file {main_cov_file} is empty.")
with open(main_cov_file, 'w', encoding='utf-8') as main_cov:
main_cov.writelines(dev_cov_lines)
return

main_mode = main_cov_lines.pop(0)
dev_mode = dev_cov_lines.pop(0)
# Check if the mode is the same in both files.
if dev_mode_line != main_mode_line:
if dev_mode != main_mode:
raise Exit(
color_message(
f"Error: the mode in the dev coverage file ({dev_mode_line}) is different from the one in the main coverage file {main_mode_line}.",
f"Error: the mode in the dev coverage file ({dev_mode}) is different from the one in the main coverage file {main_mode}.",
Color.RED,
),
code=1,
Expand All @@ -227,7 +233,7 @@ def _merge_dev_in_main_coverage(main_cov_file: str, dev_cov_file: str) -> None:
if file_path not in browsed_dev_files:
final_file_lines.append(line)

final_file_lines = [main_mode_line] + sorted(final_file_lines + dev_cov_lines)
final_file_lines = [main_mode] + sorted(final_file_lines + dev_cov_lines)
with open(main_cov_file, 'w', encoding='utf-8') as main_cov:
main_cov.writelines(final_file_lines)

Expand Down
Loading