doctor & stat improvements
- doctor: log when there is no stats() function and suggest to use it - check that stats() result isn't None - warn when there is not data in the iterable
This commit is contained in:
parent
2619af7ae7
commit
ed4b6c409f
2 changed files with 10 additions and 1 deletions
|
@ -212,10 +212,13 @@ def modules_check(args):
|
||||||
info(f'{color.GREEN}OK{color.RESET} : {m:<50}')
|
info(f'{color.GREEN}OK{color.RESET} : {m:<50}')
|
||||||
stats = get_stats(m)
|
stats = get_stats(m)
|
||||||
if stats is None:
|
if stats is None:
|
||||||
|
eprint(" - no 'stats' function, can't check the data")
|
||||||
|
# todo point to a readme on the module structure or something?
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = stats()
|
res = stats()
|
||||||
|
assert res is not None, 'stats() returned None'
|
||||||
except Exception as ee:
|
except Exception as ee:
|
||||||
warning(f' - {color.RED}stats:{color.RESET} computing failed{vw}')
|
warning(f' - {color.RED}stats:{color.RESET} computing failed{vw}')
|
||||||
if verbose:
|
if verbose:
|
||||||
|
|
|
@ -403,11 +403,13 @@ def _stat_iterable(it: Iterable[C]) -> Any:
|
||||||
from more_itertools import ilen, take, first
|
from more_itertools import ilen, take, first
|
||||||
|
|
||||||
# todo not sure if there is something in more_itertools to compute this?
|
# todo not sure if there is something in more_itertools to compute this?
|
||||||
|
total = 0
|
||||||
errors = 0
|
errors = 0
|
||||||
last = None
|
last = None
|
||||||
def funcit():
|
def funcit():
|
||||||
nonlocal errors, last
|
nonlocal errors, last, total
|
||||||
for x in it:
|
for x in it:
|
||||||
|
total += 1
|
||||||
if isinstance(x, Exception):
|
if isinstance(x, Exception):
|
||||||
errors += 1
|
errors += 1
|
||||||
else:
|
else:
|
||||||
|
@ -429,6 +431,10 @@ def _stat_iterable(it: Iterable[C]) -> Any:
|
||||||
'count': count,
|
'count': count,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if total == 0:
|
||||||
|
# not sure but I guess a good balance? wouldn't want to throw early here?
|
||||||
|
res['warning'] = 'THE ITERABLE RETURNED NO DATA'
|
||||||
|
|
||||||
if errors > 0:
|
if errors > 0:
|
||||||
res['errors'] = errors
|
res['errors'] = errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue