core/stats: get rid of duplicated keys for 'auto stats'
previously: ``` {'iter_data': {'iter_data': {'count': 9, 'last': datetime.datetime(2020, 1, 3, 1, 1, 1)}}} ``` after ``` {'iter_data': {'count': 9, 'last': datetime.datetime(2020, 1, 3, 1, 1, 1)}} ```
This commit is contained in:
parent
c5fe2e9412
commit
bf6f57c7db
3 changed files with 63 additions and 7 deletions
|
@ -12,16 +12,35 @@ from .common import StatsFun, Stats, stat
|
|||
|
||||
# TODO maybe could be enough to annotate OUTPUTS or something like that?
|
||||
# then stats could just use them as hints?
|
||||
def guess_stats(module_name: str, quick: bool=False) -> Optional[StatsFun]:
|
||||
def guess_stats(module_name: str, quick: bool = False) -> Optional[StatsFun]:
|
||||
providers = guess_data_providers(module_name)
|
||||
if len(providers) == 0:
|
||||
return None
|
||||
|
||||
def auto_stats() -> Stats:
|
||||
return {k: stat(v, quick=quick) for k, v in providers.items()}
|
||||
res = {}
|
||||
for k, v in providers.items():
|
||||
res.update(stat(v, quick=quick, name=k))
|
||||
return res
|
||||
|
||||
return auto_stats
|
||||
|
||||
|
||||
def test_guess_stats() -> None:
|
||||
from datetime import datetime
|
||||
import my.core.tests.auto_stats as M
|
||||
|
||||
auto_stats = guess_stats(M.__name__)
|
||||
res = auto_stats()
|
||||
assert res.keys() == {'iter_data'}
|
||||
|
||||
r = res['iter_data']
|
||||
assert r == {
|
||||
'count': 9,
|
||||
'last': datetime(2020, 1, 3, 1, 1, 1),
|
||||
}
|
||||
|
||||
|
||||
def guess_data_providers(module_name: str) -> Dict[str, Callable]:
|
||||
module = importlib.import_module(module_name)
|
||||
mfunctions = inspect.getmembers(module, inspect.isfunction)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue