my.bluemaestro: run against testdata, add on CI

This commit is contained in:
Dima Gerasimov 2020-10-03 20:05:21 +01:00 committed by karlicoss
parent e63c159b80
commit 6242307d7a
7 changed files with 49 additions and 20 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "testdata/hpi-testdata"]
path = testdata/hpi-testdata
url = https://github.com/karlicoss/hpi-testdata

View file

@ -26,3 +26,6 @@ class endomondo:
class exercise: class exercise:
workout_log: PathIsh = '/some/path.org' workout_log: PathIsh = '/some/path.org'
class bluemaestro:
export_path: Paths = ''

View file

@ -10,9 +10,8 @@ from pathlib import Path
import sqlite3 import sqlite3
from typing import Iterable, NamedTuple, Sequence, Set 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 ..core.cachew import cache_dir
from my.config import bluemaestro as config from my.config import bluemaestro as config
@ -99,12 +98,13 @@ def measurements(dbs=inputs()) -> Iterable[Measurement]:
# for k, v in merged.items(): # for k, v in merged.items():
# yield Point(dt=k, temp=v) # meh? # yield Point(dt=k, temp=v) # meh?
def stats(): from ..core.common import stat, Stats
from ..common import stat def stats() -> Stats:
return stat(measurements) return stat(measurements)
def dataframe(): from ..core.pandas import DataFrameT
def dataframe() -> DataFrameT:
""" """
%matplotlib gtk %matplotlib gtk
from my.bluemaestro import dataframe from my.bluemaestro import dataframe
@ -115,13 +115,4 @@ def dataframe():
import pandas as pd # type: ignore import pandas as pd # type: ignore
return pd.DataFrame(p._asdict() for p in measurements()).set_index('dt') return pd.DataFrame(p._asdict() for p in measurements()).set_index('dt')
# todo test against an older db?
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?

View file

@ -8,7 +8,11 @@ def disable_cachew():
NOTE: you need to use it before importing any function using @cachew.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 # 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 @cachew.doublewrap
def cachew_off(func=None, *args, **kwargs): def cachew_off(func=None, *args, **kwargs):

1
testdata/hpi-testdata vendored Submodule

@ -0,0 +1 @@
Subproject commit 977691c8577634ff7bc7c6ce9db21f6773b0d009

View file

@ -1,6 +1,25 @@
#!/usr/bin/env python3 #!/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(): def test() -> None:
print(list(measurements(_get_exports()[-1:]))) 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

10
tox.ini
View file

@ -13,7 +13,14 @@ commands =
# todo these are probably not necessary anymore? # todo these are probably not necessary anymore?
python3 -c 'from my.config import stub as config; print(config.key)' 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 -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 add; once I figure out porg depdencency?? tests/config.py
# TODO run demo.py? just make sure with_my is a bit cleverer? # TODO run demo.py? just make sure with_my is a bit cleverer?
# TODO e.g. under CI, rely on installing # TODO e.g. under CI, rely on installing
@ -49,6 +56,7 @@ commands =
-p my.endomondo \ -p my.endomondo \
-p my.body.exercise.cardio \ -p my.body.exercise.cardio \
-p my.body.exercise.cross_trainer \ -p my.body.exercise.cross_trainer \
-p my.bluemaestro \
--txt-report .mypy-coverage \ --txt-report .mypy-coverage \
--html-report .mypy-coverage \ --html-report .mypy-coverage \
{posargs} {posargs}