Skip to content

Commit

Permalink
mypy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Sep 19, 2021
1 parent f65903d commit 159de36
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
22 changes: 12 additions & 10 deletions bombard/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import statistics
from array import array
from copy import deepcopy
from typing import Any, Dict, Optional, Set
from typing import Any, Callable, Dict, Optional, Set

from bombard import pretty_ns
from bombard.pretty_sz import pretty_sz
Expand Down Expand Up @@ -59,7 +59,9 @@ def __init__(
self.time_threshold_ns = time_threshold_ms * 10 ** 6
self.ok = success_statuses

self.stat: Dict[Any, Any] = {} # stat[request type][status]
self.stat: Dict[
str, Dict[int, Dict[str, array[Any]]]
] = {} # stat[request type][status]['time'|'size']
# todo implement cache
# To select the best approach cache compare benchmarks for two versions:
# 1) fill cache in log() and use in filter()/reduce()
Expand All @@ -73,8 +75,7 @@ def group_name_by_status(self, status: int) -> str:
"""
if status in self.ok:
return SUCCESS_GROUP
else:
return FAIL_GROUP
return FAIL_GROUP

def log(self, status: int, elapsed: int, request_name: str, response_size: int) -> None:
"""
Expand All @@ -95,10 +96,12 @@ def total_elapsed_ns(self) -> int:

def reduce(
self,
reduce_func,
reduce_func: Callable[
[Any], Any
], # actually this is Sized (for len) or Iterable[int] (for sub) but I do not see how to express that for mypy
dimension_name: str,
status_group_filter: str = None,
request_name_filter: str = None,
status_group_filter: Optional[str] = None,
request_name_filter: Optional[str] = None,
) -> int:
"""
Reduce the dimension by group and/or request_name with the reduce_func
Expand Down Expand Up @@ -177,10 +180,9 @@ def pretty_ns(self, elapsed_ns: int, paint: bool = True) -> str:
result = pretty_ns.pretty_ns(elapsed_ns, self.time_units)
if elapsed_ns > self.time_threshold_ns and paint:
return red(result)
else:
return result
return result

def report(self):
def report(self) -> str:
size_sum = self.reduce(sum, SIZE)
total_ns = self.reduce(sum, TIME)
total_num = self.reduce(len, TIME)
Expand Down
9 changes: 3 additions & 6 deletions tests/stdout_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@ def __enter__(self) -> "CaptureOutput":
def stdout(self) -> Optional[str]:
if self.capture and self.out.getvalue():
return self.out.getvalue()
else:
return None
return None

@property
def stderr(self) -> Optional[str]:
if self.capture and self.err.getvalue():
return self.err.getvalue()
else:
return None
return None

@property
def output(self) -> Optional[str]:
Expand All @@ -52,8 +50,7 @@ def output(self) -> Optional[str]:
return "\n".join([self.stdout, self.stderr])
elif self.stdout is not None:
return self.stdout
else:
return self.stderr
return self.stderr

def __exit__(self, *args) -> None:
if self.capture:
Expand Down

0 comments on commit 159de36

Please sign in to comment.