Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.
Open
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
4 changes: 3 additions & 1 deletion services/report/languages/cobertura.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def from_xml(xml: Element, report_builder_session: ReportBuilderSession) -> None
"`create_coverage_file` with pre-fixed path is infallible"
)

for line in _class.iter("line"):
lines = next(_class.iterchildren("lines"), None)
lines = lines.iter("line") if lines else []
for line in lines:
_line = line.attrib
ln: str | int = _line["number"]
if ln == "undefined":
Expand Down
10 changes: 7 additions & 3 deletions services/report/languages/tests/unit/test_clover.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import datetime
import xml.etree.cElementTree as etree
from time import time

import pytest
from lxml import etree

from helpers.exceptions import ReportExpiredException
from services.report.languages import clover
Expand Down Expand Up @@ -77,7 +77,9 @@ def fixes(path):
return path

report_builder_session = create_report_builder_session(path_fixer=fixes)
clover.from_xml(etree.fromstring(xml % int(time())), report_builder_session)
clover.from_xml(
etree.fromstring((xml % int(time())).encode()), report_builder_session
)
report = report_builder_session.output_report()
processed_report = self.convert_report_to_better_readable(report)

Expand Down Expand Up @@ -144,4 +146,6 @@ def fixes(path):
def test_expired(self, date):
report_builder_session = create_report_builder_session()
with pytest.raises(ReportExpiredException, match="Clover report expired"):
clover.from_xml(etree.fromstring(xml % date), report_builder_session)
clover.from_xml(
etree.fromstring((xml % date).encode()), report_builder_session
)
12 changes: 8 additions & 4 deletions services/report/languages/tests/unit/test_cobertura.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import datetime
import os
import xml.etree.cElementTree as etree
from time import time

import pytest
from lxml import etree

from helpers.exceptions import ReportExpiredException
from services.path_fixer import PathFixer
Expand Down Expand Up @@ -534,13 +534,17 @@ def test_use_source_for_filename_if_multiple_sources_first_and_second_works(self


def test_empty_filename():
xml = """
xml = b"""
<coverage>
<class filename="" name="">
<line number="1" hits="1" />
<lines>
<line number="1" hits="1" />
</lines>
</class>
<class filename="non-empty" name="">
<line number="1" hits="1" />
<lines>
<line number="1" hits="1" />
</lines>
</class>
</coverage>
"""
Expand Down
4 changes: 2 additions & 2 deletions services/report/languages/tests/unit/test_csharp.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import xml.etree.cElementTree as etree
from lxml import etree

from services.report.languages import csharp
from test_utils.base import BaseTestCase

from . import create_report_builder_session

xml = """<?xml version="1.0" encoding="utf-8"?>
xml = b"""<?xml version="1.0" encoding="utf-8"?>
<CoverageSession xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Summary numSequencePoints="1803" visitedSequencePoints="1647" numBranchPoints="1155" visitedBranchPoints="1048" sequenceCoverage="91.35" branchCoverage="90.74" maxCyclomaticComplexity="32" minCyclomaticComplexity="1" />
<Modules>
Expand Down
4 changes: 2 additions & 2 deletions services/report/languages/tests/unit/test_csharp2.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import xml.etree.cElementTree as etree
from lxml import etree

from services.report.languages import csharp
from test_utils.base import BaseTestCase

from . import create_report_builder_session

xml = """<?xml version="1.0" encoding="utf-8"?>
xml = b"""<?xml version="1.0" encoding="utf-8"?>
<CoverageSession xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Summary numSequencePoints="1803" visitedSequencePoints="1647" numBranchPoints="1155" visitedBranchPoints="1048" sequenceCoverage="91.35" branchCoverage="90.74" maxCyclomaticComplexity="32" minCyclomaticComplexity="1" />
<Modules>
Expand Down
16 changes: 11 additions & 5 deletions services/report/languages/tests/unit/test_jacoco.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import datetime
import logging
import xml.etree.cElementTree as etree
from time import time

import pytest
from lxml import etree
from pytest import LogCaptureFixture

from helpers.exceptions import ReportExpiredException
Expand Down Expand Up @@ -69,7 +69,9 @@ def fixes(path):
report_builder_session = create_report_builder_session(path_fixer=fixes)

with self.caplog.at_level(logging.WARNING, logger=jacoco.__name__):
jacoco.from_xml(etree.fromstring(xml % int(time())), report_builder_session)
jacoco.from_xml(
etree.fromstring((xml % int(time())).encode()), report_builder_session
)

assert (
self.caplog.records[-1].message
Expand Down Expand Up @@ -102,7 +104,9 @@ def fixes(path):
current_yaml={"parsers": {"jacoco": {"partials_as_hits": True}}},
path_fixer=fixes,
)
jacoco.from_xml(etree.fromstring(xml % int(time())), report_builder_session)
jacoco.from_xml(
etree.fromstring((xml % int(time())).encode()), report_builder_session
)
report = report_builder_session.output_report()
processed_report = self.convert_report_to_better_readable(report)

Expand Down Expand Up @@ -134,7 +138,7 @@ def test_multi_module(self, module, path):
</package>
</report>"""
% module
)
).encode()

def fixes(path):
if module == "a":
Expand Down Expand Up @@ -162,4 +166,6 @@ def test_expired(self, date):
report_builder_session = create_report_builder_session()

with pytest.raises(ReportExpiredException, match="Jacoco report expired"):
jacoco.from_xml(etree.fromstring(xml % date), report_builder_session)
jacoco.from_xml(
etree.fromstring((xml % date).encode()), report_builder_session
)
2 changes: 1 addition & 1 deletion services/report/languages/tests/unit/test_jetbrainsxml.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import xml.etree.cElementTree as etree
from lxml import etree

from services.report.languages import jetbrainsxml

Expand Down
2 changes: 1 addition & 1 deletion services/report/languages/tests/unit/test_scoverage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import xml.etree.cElementTree as etree
from lxml import etree

from services.report.languages import scoverage
from test_utils.base import BaseTestCase
Expand Down
4 changes: 2 additions & 2 deletions services/report/languages/tests/unit/test_vb.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import xml.etree.cElementTree as etree
from lxml import etree

from services.report.languages import vb
from test_utils.base import BaseTestCase

from . import create_report_builder_session

txt = """<?xml version="1.0" encoding="UTF-8"?>
txt = b"""<?xml version="1.0" encoding="UTF-8"?>
<results>
<modules>
<module name="riosock.dll" path="riosock.dll" id="A8980752D35C194D988F77B70FC7950101000000" block_coverage="59.29" line_coverage="66.67" blocks_covered="166" blocks_not_covered="114" lines_covered="186" lines_partially_covered="4" lines_not_covered="89">
Expand Down
2 changes: 1 addition & 1 deletion services/report/languages/tests/unit/test_vb2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import xml.etree.cElementTree as etree
from lxml import etree

from services.report.languages import vb2
from test_utils.base import BaseTestCase
Expand Down
Loading