Skip to content

Commit

Permalink
Fix callable typing
Browse files Browse the repository at this point in the history
  • Loading branch information
EnricoMi committed Jun 14, 2022
1 parent 4621b00 commit f28d9a8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
7 changes: 2 additions & 5 deletions 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
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions 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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion python/publish_unit_test_results.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f28d9a8

Please sign in to comment.