Skip to content

Commit

Permalink
Introduce JUnitTreeOrException and ParsedJUnitFile
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Jun 14, 2022
1 parent 51dbd72 commit 2a34cfa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 6 additions & 5 deletions python/publish/junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ def close(self) -> Element:


JUnitTree = etree.ElementTree
JUnitTreeOrException = Union[JUnitTree, BaseException]
ParsedJUnitFile = Tuple[str, JUnitTreeOrException]


def parse_junit_xml_files(files: Iterable[str],
drop_testcases: bool = False,
progress: Callable[[Tuple[str, Union[JUnitTree, BaseException]]], Tuple[str, Union[JUnitTree, BaseException]]] = lambda x: x) -> Iterable[Tuple[str, Union[JUnitTree, BaseException]]]:
"""Parses junit xml files and returns aggregated statistics as a ParsedUnitTestResults."""
def parse(path: str) -> Union[JUnitXml, BaseException]:
progress: Callable[[ParsedJUnitFile], ParsedJUnitFile] = lambda x: x) -> Iterable[ParsedJUnitFile]:
def parse(path: str) -> JUnitTreeOrException:
"""Parses a junit xml file and returns either a JUnitTree or an Exception."""
if not os.path.exists(path):
return FileNotFoundError(f'File does not exist.')
if os.stat(path).st_size == 0:
Expand All @@ -143,8 +145,7 @@ def parse(path: str) -> Union[JUnitXml, BaseException]:
return [progress((result_file, parse(result_file))) for result_file in files]


def process_junit_xml_elems(trees: Iterable[Tuple[str, Union[JUnitTree, BaseException]]],
time_factor: float = 1.0) -> ParsedUnitTestResults:
def process_junit_xml_elems(trees: Iterable[ParsedJUnitFile], time_factor: float = 1.0) -> ParsedUnitTestResults:
# TODO: move upstream into JUnitTree
def create_junitxml(filepath: str, tree: JUnitTree) -> Union[JUnitXml, JUnitXmlError]:
root_elem = tree.getroot()
Expand Down
10 changes: 5 additions & 5 deletions python/publish/trx.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import os
import pathlib
from typing import Iterable, Tuple, Union, Callable
from typing import Iterable, Callable

from lxml import etree

from publish.junit import JUnitTree
from publish.junit import JUnitTreeOrException, ParsedJUnitFile

with (pathlib.Path(__file__).parent / 'xslt' / 'trx-to-junit.xslt').open('r', encoding='utf-8') as r:
transform_trx_to_junit = etree.XSLT(etree.parse(r))


def parse_trx_files(files: Iterable[str],
progress: Callable[[Tuple[str, Union[JUnitTree, BaseException]]], Tuple[str, Union[JUnitTree, BaseException]]] = lambda x: x) -> Iterable[Tuple[str, Union[JUnitTree, BaseException]]]:
"""Parses trx files and returns aggregated statistics as a ParsedUnitTestResults."""
def parse(path: str) -> Union[JUnitTree, BaseException]:
progress: Callable[[ParsedJUnitFile], ParsedJUnitFile] = lambda x: x) -> Iterable[ParsedJUnitFile]:
def parse(path: str) -> JUnitTreeOrException:
"""Parses a trx file and returns either a JUnitTree or an Exception."""
if not os.path.exists(path):
return FileNotFoundError(f'File does not exist.')
if os.stat(path).st_size == 0:
Expand Down

0 comments on commit 2a34cfa

Please sign in to comment.