Skip to content

Commit

Permalink
Add path fixing to report fixes in VersionOneParsedRawReport
Browse files Browse the repository at this point in the history
This commit path fixes the keys(file paths) in the report_fixes
dictionary in the VersionOneParsedRawReport.

There may be situations that arise where the uploaded files
are path fixed but the equivalent report fixes are not path fixed
which could lead to inaccurate coverage data if the ignored lines
from the report fixes are not procesed correctly.

Signed-off-by: joseph-sentry <[email protected]>
  • Loading branch information
joseph-sentry committed Aug 16, 2023
1 parent 44c918a commit 74e2fc3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
21 changes: 21 additions & 0 deletions services/report/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,24 @@ def get_fixes_from_raw(content, fix: Callable) -> Dict[str, Dict[str, Any]]:
lines.update(range(int(starts[x]) + 1, int(stops[x])))

return files


def path_fix_version_one(report_fixes, fix: Callable):
"""
Do path fixing on the report fixes in a VersionOneParsedReport format
For more on path fixing see: https://docs.codecov.com/docs/fixing-paths
Parameters
----------
report_fixes : Dict[str, Dict[str, any]]
fix : Callable
Function that applies the path fixes, is called on each path in the report fix
See the PathFixer class at services/path_fixer/__init__.py:26
"""
for key in list(report_fixes.keys()):
path_fixed = fix(key)
if path_fixed:
report_fixes[path_fixed] = report_fixes.pop(key)

Check warning on line 88 in services/report/fixes.py

View check run for this annotation

Codecov / codecov/patch

services/report/fixes.py#L88

Added line #L88 was not covered by tests
return report_fixes
7 changes: 6 additions & 1 deletion services/report/parser/tests/unit/test_version_one_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import base64
import zlib
from io import BytesIO
from typing import Sequence

from services.path_fixer import PathFixer
from services.report.parser.version_one import (
ParsedUploadedReportFile,
VersionOneReportParser,
Expand Down Expand Up @@ -48,8 +50,11 @@
def test_version_one_parser():
subject = VersionOneReportParser()
res = subject.parse_raw_report_from_bytes(input_data)
path_fixer = PathFixer.init_from_user_yaml(
{}, ["path/to/file1.c", "path/from/another.cpp", "path/from/aaaaaa.cpp"], []
)
assert res.get_env() is None
assert res.get_report_fixes(None) == {
assert res.get_report_fixes(path_fixer) == {
"SwiftExample/AppDelegate.swift": {
"eof": 15,
"lines": [1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13],
Expand Down
3 changes: 2 additions & 1 deletion services/report/parser/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any, BinaryIO, Dict, List, Optional

from services.path_fixer.fixpaths import clean_toc
from services.report.fixes import get_fixes_from_raw
from services.report.fixes import get_fixes_from_raw, path_fix_version_one


class ParsedUploadedReportFile(object):
Expand Down Expand Up @@ -104,6 +104,7 @@ def get_uploaded_files(self):
return self.uploaded_files

def get_report_fixes(self, path_fixer) -> Dict[str, Dict[str, Any]]:
path_fix_version_one(self.report_fixes, path_fixer)
return self.report_fixes


Expand Down

0 comments on commit 74e2fc3

Please sign in to comment.