add test for dynamic config attributes (import my.cfg as config)
This commit is contained in:
parent
fe763c3c04
commit
4cceccd787
6 changed files with 72 additions and 4 deletions
1
lint
1
lint
|
@ -41,6 +41,7 @@ def core_modules() -> Iterable[str]:
|
||||||
'my.init',
|
'my.init',
|
||||||
'tests/misc.py',
|
'tests/misc.py',
|
||||||
'tests/get_files.py',
|
'tests/get_files.py',
|
||||||
|
# 'tests/config.py', TODO hmm. unclear how to type check this module
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,16 +29,16 @@ def from_orgmode() -> Iterator[Result]:
|
||||||
orgs = orgmode.query()
|
orgs = orgmode.query()
|
||||||
for o in orgs.query_all(lambda o: o.with_tag('weight')):
|
for o in orgs.query_all(lambda o: o.with_tag('weight')):
|
||||||
try:
|
try:
|
||||||
# TODO ?? Result type?
|
# TODO can it throw? not sure
|
||||||
created = o.created
|
created = o.created
|
||||||
heading = o.heading
|
assert created is not None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
yield e
|
yield e
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
w = float(heading)
|
w = float(o.heading)
|
||||||
except ValueError as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
yield e
|
yield e
|
||||||
continue
|
continue
|
||||||
|
@ -69,3 +69,7 @@ def dataframe():
|
||||||
df.set_index('dt', inplace=True)
|
df.set_index('dt', inplace=True)
|
||||||
df.index = pd.to_datetime(df.index, utc=True)
|
df.index = pd.to_datetime(df.index, utc=True)
|
||||||
return df
|
return df
|
||||||
|
|
||||||
|
# TODO move to a submodule? e.g. my.body.weight.orgmode?
|
||||||
|
# so there could be more sources
|
||||||
|
# not sure about my.body thing though
|
||||||
|
|
|
@ -26,6 +26,7 @@ def _org_files_in(ppp: Path, archived: bool=False) -> Iterator[Path]:
|
||||||
|
|
||||||
|
|
||||||
def org_files(roots=config.roots, archived: bool=False) -> Iterator[Path]:
|
def org_files(roots=config.roots, archived: bool=False) -> Iterator[Path]:
|
||||||
|
# TODO rename to 'paths'? use get_files?
|
||||||
for p in config.roots:
|
for p in config.roots:
|
||||||
yield from _org_files_in(Path(p), archived=archived)
|
yield from _org_files_in(Path(p), archived=archived)
|
||||||
|
|
||||||
|
|
3
setup.py
3
setup.py
|
@ -50,6 +50,9 @@ def main():
|
||||||
'pytest',
|
'pytest',
|
||||||
'pylint',
|
'pylint',
|
||||||
'mypy',
|
'mypy',
|
||||||
|
|
||||||
|
# used in some tests
|
||||||
|
'pandas',
|
||||||
],
|
],
|
||||||
'optional': [
|
'optional': [
|
||||||
# TODO document these?
|
# TODO document these?
|
||||||
|
|
58
tests/config.py
Normal file
58
tests/config.py
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def setup_notes_path(notes: Path) -> None:
|
||||||
|
# TODO reuse doc from my.cfg?
|
||||||
|
from my.cfg import config
|
||||||
|
|
||||||
|
from types import SimpleNamespace
|
||||||
|
config.orgmode = SimpleNamespace( # type: ignore[misc,assignment]
|
||||||
|
roots=[notes],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_dynamic_configuration(notes: Path) -> None:
|
||||||
|
setup_notes_path(notes)
|
||||||
|
|
||||||
|
from my.body.weight import dataframe
|
||||||
|
weight_df = dataframe()
|
||||||
|
|
||||||
|
assert list(weight_df['weight'].fillna(0.0)) == [
|
||||||
|
0.0,
|
||||||
|
62.0,
|
||||||
|
0.0,
|
||||||
|
61.0,
|
||||||
|
62.0,
|
||||||
|
0.0,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
import pytest # type: ignore
|
||||||
|
@pytest.fixture
|
||||||
|
def notes(tmp_path: Path):
|
||||||
|
ndir = tmp_path / 'notes'
|
||||||
|
ndir.mkdir()
|
||||||
|
logs = ndir / 'logs.org'
|
||||||
|
logs.write_text('''
|
||||||
|
#+TITLE: Stuff I'm logging
|
||||||
|
|
||||||
|
* Weight (org-capture) :weight:
|
||||||
|
** [2020-05-01 Fri 09:00] 62
|
||||||
|
** 63
|
||||||
|
this should be ignored, got no timestmap
|
||||||
|
** [2020-05-03 Sun 08:00] 61
|
||||||
|
** [2020-05-04 Mon 10:00] 62
|
||||||
|
''')
|
||||||
|
misc = ndir / 'misc.org'
|
||||||
|
misc.write_text('''
|
||||||
|
Some misc stuff
|
||||||
|
|
||||||
|
* unrelated note :weight:whatever:
|
||||||
|
''')
|
||||||
|
try:
|
||||||
|
yield ndir
|
||||||
|
finally:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# TODO test set_repo?
|
1
tox.ini
1
tox.ini
|
@ -14,6 +14,7 @@ commands =
|
||||||
python3 -c 'import my.init; from my.config import stub as config; print(config.key)'
|
python3 -c 'import my.init; from my.config import stub as config; print(config.key)'
|
||||||
python3 -c 'import my.init; import my.config; import my.config.repos' # shouldn't fail at least
|
python3 -c 'import my.init; import my.config; import my.config.repos' # shouldn't fail at least
|
||||||
python3 -m pytest tests/misc.py tests/get_files.py
|
python3 -m pytest tests/misc.py tests/get_files.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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue