polar: add test for orger integration
This commit is contained in:
parent
0f27071dcc
commit
87ad9d38bb
2 changed files with 42 additions and 13 deletions
|
@ -246,3 +246,10 @@ def isoparse(s: str) -> tzdatetime:
|
|||
assert s.endswith('Z'), s
|
||||
s = s[:-1] + '+00:00'
|
||||
return fromisoformat(s)
|
||||
|
||||
|
||||
import re
|
||||
# https://stackoverflow.com/a/295466/706389
|
||||
def get_valid_filename(s: str) -> str:
|
||||
s = str(s).strip().replace(' ', '_')
|
||||
return re.sub(r'(?u)[^-\w.]', '', s)
|
||||
|
|
|
@ -1,19 +1,49 @@
|
|||
from pathlib import Path
|
||||
import sys
|
||||
from importlib import reload
|
||||
from my.core.common import get_valid_filename
|
||||
|
||||
ROOT = Path(__file__).parent.absolute()
|
||||
OUTPUTS = ROOT / 'outputs'
|
||||
|
||||
|
||||
import pytest # type: ignore
|
||||
|
||||
# todo maybe search fot info.json recursively?
|
||||
@pytest.mark.parametrize('dotpolar', [
|
||||
|
||||
def test_hpi(prepare: str) -> None:
|
||||
import my.reading.polar as polar
|
||||
reload(polar)
|
||||
from my.reading.polar import get_entries
|
||||
assert len(list(get_entries())) > 1
|
||||
|
||||
|
||||
def test_orger(prepare: str, tmp_path: Path) -> None:
|
||||
import my.reading.polar as polar
|
||||
reload(polar)
|
||||
# TODO hmm... ok, need to document reload()
|
||||
|
||||
from my.core.common import import_from, import_file
|
||||
om = import_file(ROOT / 'orger/modules/polar.py')
|
||||
# reload(om)
|
||||
|
||||
pv = om.PolarView() # type: ignore
|
||||
# TODO hmm. worth making public?
|
||||
OUTPUTS.mkdir(exist_ok=True)
|
||||
out = OUTPUTS / (get_valid_filename(prepare) + '.org')
|
||||
pv._run(to=out)
|
||||
|
||||
|
||||
PARAMS = [
|
||||
'',
|
||||
'data/polar/BojanKV_polar/.polar',
|
||||
'data/polar/TheCedarPrince_KnowledgeRepository',
|
||||
'data/polar/coelias_polardocs',
|
||||
'data/polar/warkdarrior_polar-document-repository'
|
||||
])
|
||||
def test_hpi(dotpolar: str):
|
||||
]
|
||||
|
||||
@pytest.fixture(params=PARAMS)
|
||||
def prepare(request):
|
||||
dotpolar = request.param
|
||||
if dotpolar != '':
|
||||
pdir = Path(ROOT / dotpolar)
|
||||
class user_config:
|
||||
|
@ -22,12 +52,4 @@ def test_hpi(dotpolar: str):
|
|||
import my.config
|
||||
setattr(my.config, 'polar', user_config)
|
||||
|
||||
import sys
|
||||
M = 'my.reading.polar'
|
||||
if M in sys.modules:
|
||||
del sys.modules[M]
|
||||
# TODO maybe set config directly against polar module?
|
||||
|
||||
import my.reading.polar as polar
|
||||
from my.reading.polar import get_entries
|
||||
assert len(list(get_entries())) > 1
|
||||
yield dotpolar
|
||||
|
|
Loading…
Add table
Reference in a new issue