my.endomondo: add fake data generator, test mypy

This commit is contained in:
Dima Gerasimov 2020-10-01 22:47:19 +01:00 committed by karlicoss
parent 1c20eb27aa
commit d8841d0d7a
3 changed files with 27 additions and 3 deletions

View file

@ -20,3 +20,6 @@ class github:
class reddit:
export_path: Paths = ''
class endomondo:
export_path: Paths = ''

View file

@ -31,14 +31,14 @@ def inputs() -> Sequence[Path]:
# todo add a doctor check for pip endoexport module
import endoexport.dal
import endoexport.dal as dal
from endoexport.dal import Point, Workout
# todo cachew?
def workouts() -> Iterable[Res[Workout]]:
dal = endoexport.dal.DAL(inputs())
yield from dal.workouts()
_dal = dal.DAL(inputs())
yield from _dal.workouts()
def dataframe(defensive=True):
@ -77,3 +77,22 @@ def stats():
# TODO make sure it's possible to 'advise' functions and override stuff
from contextlib import contextmanager
@contextmanager
def fake_data(count: int=100):
from .core.cfg import override_config
from tempfile import TemporaryDirectory
import json
with override_config(endomondo) as cfg, TemporaryDirectory() as td:
tdir = Path(td)
cfg.export_path = tdir
# todo would be nice to somehow expose the generator so it's possible to hack from the outside?
fd = dal.FakeData()
data = fd.generate(count=count)
jf = tdir / 'data.json'
jf.write_text(json.dumps(data))
yield

View file

@ -36,12 +36,14 @@ commands =
pip install git+https://github.com/karlicoss/instapexport
pip install git+https://github.com/karlicoss/pockexport
pip install git+https://github.com/karlicoss/rexport
pip install git+https://github.com/karlicoss/endoexport
# todo I guess use a script...
python3 -m mypy -p my.github.ghexport \
-p my.hypothesis \
-p my.instapaper \
-p my.pocket \
-p my.reddit \
-p my.endomondo \
--txt-report .mypy-coverage \
--html-report .mypy-coverage \
{posargs}