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

Change names of path_fixes to report_fixes #58

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion services/report/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def get_fixes_from_raw(content, fix: Callable) -> Dict[str, Dict[str, Any]]:
files.setdefault(fix(filename), {})["eof"] = int(line)

else:
# filename:5:<source>
# filename:5
# filename:5,10,20
filename, line = line.split(":", 1)
Expand Down
9 changes: 4 additions & 5 deletions services/report/parser/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


class LegacyReportParser(object):

network_separator = b"<<<<<< network"
env_separator = b"<<<<<< ENV"
eof_separator = b"<<<<<< EOF"
Expand Down Expand Up @@ -72,7 +71,7 @@ def cut_sections(self, raw_report: bytes):
- toc: the 'network', list of files present on this report
- env: the envvars the user set on the upload
- uploaded_files: the actual report files
- path_fixes: the patfixes some languages need
- report_fixes: the report fixes some languages need
and splits them, also taking care of 'strip()' them, removing whitespaces,
as the original logic also does.
Expand Down Expand Up @@ -132,15 +131,15 @@ def _generate_parsed_report_from_sections(self, sections):
uploaded_files = []
toc_section = None
env_section = None
path_fixes_section = None
report_fixes_section = None
for sect in sections:
if sect["footer"] == self.network_separator:
toc_section = sect["contents"]
elif sect["footer"] == self.env_separator:
env_section = sect["contents"]
else:
if sect["filename"] == "fixes":
path_fixes_section = sect["contents"]
report_fixes_section = sect["contents"]
else:
uploaded_files.append(
ParsedUploadedReportFile(
Expand All @@ -152,5 +151,5 @@ def _generate_parsed_report_from_sections(self, sections):
toc=toc_section,
env=env_section,
uploaded_files=uploaded_files,
path_fixes=path_fixes_section,
report_fixes=report_fixes_section,
)
4 changes: 2 additions & 2 deletions services/report/parser/tests/unit/test_version_one_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
)

input_data = b"""{
"path_fixes": {
"report_fixes": {
"format": "legacy",
"value": {
"SwiftExample/AppDelegate.swift": {
Expand Down Expand Up @@ -49,7 +49,7 @@ def test_version_one_parser():
subject = VersionOneReportParser()
res = subject.parse_raw_report_from_bytes(input_data)
assert res.get_env() is None
assert res.get_path_fixes(None) == {
assert res.get_report_fixes(None) == {
"SwiftExample/AppDelegate.swift": {
"eof": 15,
"lines": [1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13],
Expand Down
51 changes: 42 additions & 9 deletions services/report/parser/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,43 @@ def get_first_line(self):


class ParsedRawReport(object):
"""
Parsed raw report parent class
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very helpful 👍 thanks for doing this

Attributes
----------
toc
table of contents, this lists the files relevant to the report,
i.e. the files contained in the repository
env
list of env vars in environment of uploader (legacy only)
uploaded_files
list of class ParsedUploadedReportFile describing uploaded coverage files
report_fixes
list of objects describing report_fixes for each file, the format differs between
legacy and VersionOne parsed raw report
"""

def __init__(
self,
toc: Optional[BinaryIO],
env: Optional[BinaryIO],
uploaded_files: List[ParsedUploadedReportFile],
path_fixes: Optional[BinaryIO],
report_fixes: Optional[BinaryIO],
):
self.toc = toc
self.env = env
self.uploaded_files = uploaded_files
self.path_fixes = path_fixes
self.report_fixes = report_fixes

def has_toc(self) -> bool:
return self.toc is not None

def has_env(self) -> bool:
return self.env is not None

def has_path_fixes(self) -> bool:
return self.path_fixes is not None
def has_report_fixes(self) -> bool:
return self.report_fixes is not None

@property
def size(self):
Expand All @@ -66,6 +83,17 @@ def content(self) -> BytesIO:


class VersionOneParsedRawReport(ParsedRawReport):
"""
report_fixes : Dict[str, Dict[str, any]]
{
<path to file>: {
eof: int | None
lines: List[int]
},
...
}
"""

def get_toc(self) -> List[str]:
return self.toc

Expand All @@ -75,11 +103,16 @@ def get_env(self):
def get_uploaded_files(self):
return self.uploaded_files

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


class LegacyParsedRawReport(ParsedRawReport):
"""
report_fixes : BinaryIO
<filename>:<line number>,<line number>,...
"""

def get_toc(self) -> List[str]:
toc = self.toc.read().decode(errors="replace").strip()
toc = clean_toc(toc)
Expand All @@ -92,6 +125,6 @@ def get_env(self):
def get_uploaded_files(self):
return self.uploaded_files

def get_path_fixes(self, path_fixer) -> Dict[str, Dict[str, Any]]:
path_fixes = self.path_fixes.read().decode(errors="replace")
return get_fixes_from_raw(path_fixes, path_fixer)
def get_report_fixes(self, path_fixer) -> Dict[str, Dict[str, Any]]:
report_fixes = self.report_fixes.read().decode(errors="replace")
return get_fixes_from_raw(report_fixes, path_fixer)
9 changes: 7 additions & 2 deletions services/report/parser/version_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ def parse_raw_report_from_bytes(self, raw_report: bytes):
uploaded_files=[
self._parse_single_coverage_file(x) for x in data["coverage_files"]
],
path_fixes=self._parse_path_fixes(data["path_fixes"]),
report_fixes=self._parse_report_fixes(
# want backwards compatibility with older versions of the CLI that still name this section path_fixes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10/10 - This is very good. Yes we do want that.

data["report_fixes"]
if "report_fixes" in data
else data["path_fixes"]
),
)

def _parse_path_fixes(self, value):
def _parse_report_fixes(self, value):
return value["value"]

def _parse_single_coverage_file(self, coverage_file):
Expand Down
4 changes: 2 additions & 2 deletions services/report/raw_upload_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ def process_raw_upload(
# ------------------
# Extract bash fixes
# ------------------
if reports.has_path_fixes():
ignored_file_lines = reports.get_path_fixes(path_fixer)
if reports.has_report_fixes():
ignored_file_lines = reports.get_report_fixes(path_fixer)
else:
ignored_file_lines = None

Expand Down
24 changes: 12 additions & 12 deletions services/report/tests/unit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,21 +321,21 @@ def test_parser_with_toc(self):
res = LegacyReportParser().parse_raw_report_from_bytes(simple_content)
assert res.has_toc()
assert not res.has_env()
assert not res.has_path_fixes()
assert not res.has_report_fixes()
assert len(res.uploaded_files) == 1

def test_parser_no_toc(self):
res = LegacyReportParser().parse_raw_report_from_bytes(simple_no_toc)
assert not res.has_toc()
assert not res.has_env()
assert not res.has_path_fixes()
assert not res.has_report_fixes()
assert len(res.uploaded_files) == 1

def test_parser_more_complete(self):
res = LegacyReportParser().parse_raw_report_from_bytes(more_complex)
assert res.has_toc()
assert res.has_env()
assert not res.has_path_fixes()
assert not res.has_report_fixes()
assert len(res.uploaded_files) == 2
assert res.uploaded_files[0].filename == "unit.coverage.xml"
assert res.uploaded_files[0].contents.startswith(b'<?xml version="1.0" ?>')
Expand All @@ -350,7 +350,7 @@ def test_parser_more_complete_with_line_end(self):
)
assert res.has_toc()
assert res.has_env()
assert not res.has_path_fixes()
assert not res.has_report_fixes()
assert len(res.uploaded_files) == 2
assert res.uploaded_files[0].filename == "unit.coverage.xml"
assert (
Expand All @@ -375,7 +375,7 @@ def test_line_end_no_line_break(self):
res = LegacyReportParser().parse_raw_report_from_bytes(line_end_no_line_break)
assert res.has_toc()
assert res.has_env()
assert not res.has_path_fixes()
assert not res.has_report_fixes()
assert len(res.uploaded_files) == 2
assert res.uploaded_files[0].filename == "unit.coverage.xml"
assert (
Expand Down Expand Up @@ -415,7 +415,7 @@ def test_cases_little_mor_ridiculous(self):
]
)
assert res.has_env()
assert not res.has_path_fixes()
assert not res.has_report_fixes()
assert len(res.uploaded_files) == 2
assert res.uploaded_files[0].filename == "unit.coverage.xml"
assert (
Expand Down Expand Up @@ -453,7 +453,7 @@ def test_cases_no_eof_end(self):
]
)
assert res.has_env()
assert not res.has_path_fixes()
assert not res.has_report_fixes()
assert len(res.uploaded_files) == 2
assert res.uploaded_files[0].filename == "unit.coverage.xml"
assert (
Expand Down Expand Up @@ -482,7 +482,7 @@ def test_cases_emptylines_betweenpath_and_content(self):
]
)
assert not res.has_env()
assert not res.has_path_fixes()
assert not res.has_report_fixes()
assert len(res.uploaded_files) == 1
assert res.uploaded_files[0].filename == "coverage.txt"
assert (
Expand Down Expand Up @@ -510,8 +510,8 @@ def test_cases_compatibility_mode(self):
assert res.toc.getvalue() == would_be_simple_content_res.toc.getvalue()
assert not res.has_env()
assert not would_be_simple_content_res.has_env()
assert not res.has_path_fixes()
assert not would_be_simple_content_res.has_path_fixes()
assert not res.has_report_fixes()
assert not would_be_simple_content_res.has_report_fixes()
assert len(res.uploaded_files) == len(
would_be_simple_content_res.uploaded_files
)
Expand All @@ -538,8 +538,8 @@ def test_cases_compatibility_mode_failed_case(self):
assert res.toc.getvalue() == would_be_simple_content_res.toc.getvalue()
assert not res.has_env()
assert not would_be_simple_content_res.has_env()
assert not res.has_path_fixes()
assert not would_be_simple_content_res.has_path_fixes()
assert not res.has_report_fixes()
assert not would_be_simple_content_res.has_report_fixes()
assert len(res.uploaded_files) == len(
would_be_simple_content_res.uploaded_files
)
Expand Down
6 changes: 3 additions & 3 deletions services/report/tests/unit/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def test_fixes_paths(self):

assert res.get("file") is not None

def test_path_fixes_same_final_result(self):
def test_report_fixes_same_final_result(self):
commit_yaml = {"fixes": ["arroba::prefix", "bingo::prefix"]}
result = process.process_raw_upload(
commit_yaml=UserYaml(commit_yaml),
Expand Down Expand Up @@ -915,7 +915,7 @@ def test_process_raw_upload_multiple_raw_reports(self, mocker):
uploaded_reports = LegacyParsedRawReport(
toc=None,
env=None,
path_fixes=None,
report_fixes=None,
uploaded_files=[
ParsedUploadedReportFile(
filename="/Users/path/to/app.coverage.txt",
Expand Down Expand Up @@ -1074,7 +1074,7 @@ def test_process_raw_upload_with_carryforwarded_flags(self):
uploaded_reports = LegacyParsedRawReport(
toc=None,
env=None,
path_fixes=None,
report_fixes=None,
uploaded_files=[
ParsedUploadedReportFile(
filename="/Users/path/to/app.coverage.json",
Expand Down
Loading