From d8841d0d7a4d14f8486f27c806bd59a9f12fefda Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Thu, 1 Oct 2020 22:47:19 +0100 Subject: [PATCH] my.endomondo: add fake data generator, test mypy --- doc/example_config/my/config/__init__.py | 3 +++ my/endomondo.py | 25 +++++++++++++++++++++--- tox.ini | 2 ++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/doc/example_config/my/config/__init__.py b/doc/example_config/my/config/__init__.py index 51a0d01..7aba5ca 100644 --- a/doc/example_config/my/config/__init__.py +++ b/doc/example_config/my/config/__init__.py @@ -20,3 +20,6 @@ class github: class reddit: export_path: Paths = '' + +class endomondo: + export_path: Paths = '' diff --git a/my/endomondo.py b/my/endomondo.py index 7b38ea3..6c56bfa 100644 --- a/my/endomondo.py +++ b/my/endomondo.py @@ -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 diff --git a/tox.ini b/tox.ini index d807f29..ab4f0a2 100644 --- a/tox.ini +++ b/tox.ini @@ -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}