polar: support configuring defensive behaviour, support for highlight tags

This commit is contained in:
Dima Gerasimov 2020-05-15 12:40:15 +01:00
parent 844ebf28c1
commit 3d8002c8c9
3 changed files with 38 additions and 14 deletions

View file

@ -127,7 +127,9 @@ def wrap(j, throw=True) -> Iterator[Zoomable]:
for c in children:
if not c.this_consumed(): # TODO hmm. how does it figure out if it's consumed???
if throw:
raise UnconsumedError(str(c))
raise UnconsumedError(f'''
Expected {c} to be fully consumed by the parser.
'''.lstrip())
else:
# TODO log?
pass
@ -172,4 +174,14 @@ def test_consume_all():
aaa = w['aaa'].zoom()
aaa['bbb'].consume_all()
def test_zoom() -> None:
import pytest # type: ignore
with wrap({'aaa': 'whatever'}) as w:
w = cast(Wdict, w)
with pytest.raises(KeyError):
w['nosuchkey'].zoom()
w['aaa'].zoom()
# TODO type check this...