diff --git a/python/publish/junit.py b/python/publish/junit.py index 50aaa061..1c950820 100644 --- a/python/publish/junit.py +++ b/python/publish/junit.py @@ -1,6 +1,6 @@ import os from collections import defaultdict -from typing import Optional, Iterable, Union, Any, List, Dict, Callable, TypeVar +from typing import Optional, Iterable, Union, Any, List, Dict, Callable, Tuple import junitparser from junitparser import Element, JUnitXml, TestCase, TestSuite, Skipped @@ -98,13 +98,10 @@ def end(self, tag: Union[str, bytes]) -> Element: self._stack.pop() -T = TypeVar("T") - - def parse_junit_xml_files(files: Iterable[str], time_factor: float = 1.0, drop_testcases: bool = False, - progress: Callable[[T], T] = lambda x: x) -> ParsedUnitTestResults: + progress: Callable[[Tuple[str, Any]], Tuple[str, Any]] = lambda x: x) -> ParsedUnitTestResults: """Parses junit xml files and returns aggregated statistics as a ParsedUnitTestResults.""" def parse(path: str) -> Union[str, Any]: if not os.path.exists(path): diff --git a/python/publish/progress.py b/python/publish/progress.py index d4d78c5f..c2c51a29 100644 --- a/python/publish/progress.py +++ b/python/publish/progress.py @@ -1,7 +1,7 @@ from datetime import datetime from logging import Logger from threading import Timer -from typing import Generic, TypeVar, Optional, Callable +from typing import Generic, TypeVar, Optional, Callable, Type, Any import contextlib import humanize @@ -14,8 +14,9 @@ def progress_logger(items: int, interval_seconds: int, progress_template: str, finish_template: Optional[str], - logger: Logger) -> Callable[[T], T]: - progress = Progress(items) + logger: Logger, + progress_item_type: Type[T] = Any) -> Callable[[T], T]: + progress = Progress[progress_item_type](items) plogger = ProgressLogger(progress, interval_seconds, progress_template, logger).start() try: yield progress.observe diff --git a/python/publish_unit_test_results.py b/python/publish_unit_test_results.py index a4ff8ee8..b8d26ca2 100644 --- a/python/publish_unit_test_results.py +++ b/python/publish_unit_test_results.py @@ -6,7 +6,7 @@ from collections import defaultdict from datetime import datetime from glob import glob -from typing import List, Optional, Union +from typing import List, Optional, Union, Tuple, Any import github import humanize @@ -108,6 +108,7 @@ def main(settings: Settings, gha: GithubAction) -> None: interval_seconds=10, progress_template='Read {progress} files in {time}', finish_template='Finished reading {observations} files in {duration}', + progress_item_type=Tuple[str, Any], logger=logger) as progress: # get the unit test results parsed = parse_junit_xml_files(files, settings.time_factor, settings.ignore_runs, progress).with_commit(settings.commit)