Skip to content

Commit

Permalink
fix: handle reports with line 0 executed (#73)
Browse files Browse the repository at this point in the history
Recently when testing the docs for integrating ATS I did [this commit](https://app.codecov.io/gh/giovanni-guidini/ats-data/commit/c24c1db8aa27fcda2d311fdcd293c20697030389)
for which processing failed. Checking the logs it failed because of

```
  [... removed stack trace...]
  File "/worker/services/report/languages/pycoverage.py", line 56, in process
    report_file.append(
  File "/usr/local/lib/python3.10/site-packages/shared/reports/resources.py", line 341, in append
    raise ValueError("Line number must be greater then 0. Got %s" % ln)
ValueError: Line number must be greater then 0. Got 0
```

Indeed when I donwloaded and checked the uploaded files there were 3 of them with `executed_lines: [0]`.
They were all `__init__.py` files. Idk why that happened, to be honest. It looks strange because the 3 files are empty.

In any case it's an easy fix that will not hurt us.
I think line 0 should not exist. It might indicate that when importing the code or something like that the file was
executed somehow, but for `__init__.py` files with some content in them the list of lines executed is as expected.
  • Loading branch information
giovanni-guidini committed Aug 22, 2023
1 parent ae66235 commit 4ce0025
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
19 changes: 10 additions & 9 deletions services/report/languages/pycoverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ def process(
str(ln), []
)
]
report_file.append(
ln,
report_builder_session.create_coverage_line(
fixed_filename,
cov,
coverage_type=CoverageType.line,
labels_list_of_lists=label_list_of_lists,
),
)
if ln > 0:
report_file.append(
ln,
report_builder_session.create_coverage_line(
fixed_filename,
cov,
coverage_type=CoverageType.line,
labels_list_of_lists=label_list_of_lists,
),
)
report_builder_session.append(report_file)
return report_builder_session.output_report()
14 changes: 14 additions & 0 deletions services/report/languages/tests/unit/test_pycoverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@
"excluded_lines": [],
"contexts": {},
},
"services/__init__.py": {
"executed_lines": [0],
"summary": {
"covered_lines": 0,
"num_statements": 0,
"percent_covered": "100.0",
"percent_covered_display": "100",
"missing_lines": 0,
"excluded_lines": 0,
},
"missing_lines": [],
"excluded_lines": [],
"contexts": {"0": [0]},
},
},
"labels_table": {
"0": "",
Expand Down

0 comments on commit 4ce0025

Please sign in to comment.