From 6242307d7ae47bbdb2178bd78decc9bb162ed880 Mon Sep 17 00:00:00 2001 From: Dima Gerasimov Date: Sat, 3 Oct 2020 20:05:21 +0100 Subject: [PATCH] my.bluemaestro: run against testdata, add on CI --- .gitmodules | 3 +++ doc/example_config/my/config/__init__.py | 3 +++ my/bluemaestro/__init__.py | 21 ++++++-------------- my/core/cachew.py | 6 +++++- testdata/hpi-testdata | 1 + tests/bluemaestro.py | 25 +++++++++++++++++++++--- tox.ini | 10 +++++++++- 7 files changed, 49 insertions(+), 20 deletions(-) create mode 100644 .gitmodules create mode 160000 testdata/hpi-testdata diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..67d3592 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "testdata/hpi-testdata"] + path = testdata/hpi-testdata + url = https://github.com/karlicoss/hpi-testdata diff --git a/doc/example_config/my/config/__init__.py b/doc/example_config/my/config/__init__.py index ff7d1ed..8728016 100644 --- a/doc/example_config/my/config/__init__.py +++ b/doc/example_config/my/config/__init__.py @@ -26,3 +26,6 @@ class endomondo: class exercise: workout_log: PathIsh = '/some/path.org' + +class bluemaestro: + export_path: Paths = '' diff --git a/my/bluemaestro/__init__.py b/my/bluemaestro/__init__.py index 51ac78d..8ff0b59 100755 --- a/my/bluemaestro/__init__.py +++ b/my/bluemaestro/__init__.py @@ -10,9 +10,8 @@ from pathlib import Path import sqlite3 from typing import Iterable, NamedTuple, Sequence, Set -from ..common import mcachew, LazyLogger, get_files - +from ..core.common import mcachew, LazyLogger, get_files from ..core.cachew import cache_dir from my.config import bluemaestro as config @@ -99,12 +98,13 @@ def measurements(dbs=inputs()) -> Iterable[Measurement]: # for k, v in merged.items(): # yield Point(dt=k, temp=v) # meh? -def stats(): - from ..common import stat +from ..core.common import stat, Stats +def stats() -> Stats: return stat(measurements) -def dataframe(): +from ..core.pandas import DataFrameT +def dataframe() -> DataFrameT: """ %matplotlib gtk from my.bluemaestro import dataframe @@ -115,13 +115,4 @@ def dataframe(): import pandas as pd # type: ignore return pd.DataFrame(p._asdict() for p in measurements()).set_index('dt') - -def main(): - ll = list(measurements()) - print(len(ll)) - - -if __name__ == '__main__': - main() - -# TODO copy a couble of databases (one old, one new) to my public data repository? +# todo test against an older db? diff --git a/my/core/cachew.py b/my/core/cachew.py index 27a35fb..61d0953 100644 --- a/my/core/cachew.py +++ b/my/core/cachew.py @@ -8,7 +8,11 @@ def disable_cachew(): NOTE: you need to use it before importing any function using @cachew.cachew ''' # TODO not sure... maybe it should instead use some hook.. it's a ibt ugly do - import cachew + try: + import cachew + except ImportError: + # nothing to disable + return @cachew.doublewrap def cachew_off(func=None, *args, **kwargs): diff --git a/testdata/hpi-testdata b/testdata/hpi-testdata new file mode 160000 index 0000000..977691c --- /dev/null +++ b/testdata/hpi-testdata @@ -0,0 +1 @@ +Subproject commit 977691c8577634ff7bc7c6ce9db21f6773b0d009 diff --git a/tests/bluemaestro.py b/tests/bluemaestro.py index d4d00f8..127f0b7 100644 --- a/tests/bluemaestro.py +++ b/tests/bluemaestro.py @@ -1,6 +1,25 @@ #!/usr/bin/env python3 -from my.bluemaestro import measurements, _get_exports +from pathlib import Path + +from my.core.cachew import disable_cachew +disable_cachew() # meh -def test(): - print(list(measurements(_get_exports()[-1:]))) +def test() -> None: + from my.bluemaestro import measurements + res = list(measurements()) + assert len(res) > 1000 + + +import pytest # type: ignore +@pytest.fixture(autouse=True) +def prepare(): + testdata = Path(__file__).absolute().parent.parent / 'testdata' + bmdata = testdata / 'hpi-testdata' / 'bluemaestro' + assert bmdata.exists(), bmdata + + from my.cfg import config + class user_config: + export_path = bmdata + config.bluemaestro = user_config # type: ignore + yield diff --git a/tox.ini b/tox.ini index 9df7a47..7a3dddb 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,14 @@ commands = # todo these are probably not necessary anymore? python3 -c 'from my.config import stub as config; print(config.key)' python3 -c 'import my.config; import my.config.repos' # shouldn't fail at least - python3 -m pytest tests/core.py tests/misc.py tests/get_files.py tests/config.py::test_set_repo tests/config.py::test_environment_variable tests/demo.py + python3 -m pytest \ + tests/core.py \ + tests/misc.py \ + tests/get_files.py \ + tests/config.py::test_set_repo \ + tests/config.py::test_environment_variable \ + tests/demo.py \ + tests/bluemaestro.py # TODO add; once I figure out porg depdencency?? tests/config.py # TODO run demo.py? just make sure with_my is a bit cleverer? # TODO e.g. under CI, rely on installing @@ -49,6 +56,7 @@ commands = -p my.endomondo \ -p my.body.exercise.cardio \ -p my.body.exercise.cross_trainer \ + -p my.bluemaestro \ --txt-report .mypy-coverage \ --html-report .mypy-coverage \ {posargs}