core/modules: switch away from using override_config to tmp_config in some tests & faka data generators

This commit is contained in:
Dima Gerasimov 2023-02-09 00:53:24 +00:00 committed by karlicoss
parent 5ac5636e7f
commit 0e884fe166
5 changed files with 48 additions and 25 deletions

View file

@ -58,22 +58,27 @@ def stats() -> Stats:
# basically, hack config and populate it with fake data? fake data generated by DAL, but the rest is handled by this?
from typing import Iterator
from contextlib import contextmanager
from typing import Iterator
# todo take seed, or what?
@contextmanager
def fake_data(rows: int=1000) -> Iterator[None]:
def fake_data(rows: int=1000) -> Iterator:
# todo also disable cachew automatically for such things?
from .core.cachew import disabled_cachew
from .core.cfg import override_config
from my.core.cfg import tmp_config
from my.core.cachew import disabled_cachew
from tempfile import TemporaryDirectory
with disabled_cachew(), override_config(config) as cfg, TemporaryDirectory() as td:
import json
with disabled_cachew(), TemporaryDirectory() as td:
tdir = Path(td)
cfg.export_path = tdir
f = tdir / 'rescuetime.json'
import json
f.write_text(json.dumps(dal.fake_data_generator(rows=rows)))
yield
class override:
class rescuetime:
export_path = tdir
with tmp_config(modules=__name__, config=override) as cfg:
yield cfg
# TODO ok, now it's something that actually could run on CI!
# todo would be kinda nice if doctor could run against the fake data, to have a basic health check of the module?