1
0
Fork 0

Adding upstream version 3.4.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 20:45:12 +01:00
parent 91f556e1ee
commit f4a7436faf
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
11 changed files with 94 additions and 68 deletions

View file

@ -1,3 +1,5 @@
from __future__ import annotations
import json
from unittest import mock
@ -34,11 +36,12 @@ from cfgv import WarnAdditionalKeys
def _assert_exception_trace(e, trace):
inner = e
for ctx in trace[:-1]:
assert inner.ctx == ctx
inner = inner.error_msg
assert inner.error_msg == trace[-1]
parts = []
while e.ctx is not None:
parts.append(e.ctx)
e = e.error_msg
parts.append(e.error_msg)
assert tuple(parts) == trace
def test_ValidationError_simple_str():
@ -580,6 +583,35 @@ def test_load_from_filename_applies_defaults(tmpdir):
assert ret == {'key': False}
def test_load_from_filename_custom_display_no_file(tmp_path):
with pytest.raises(ValidationError) as excinfo:
load_from_filename(
tmp_path.joinpath('cfg.json'),
map_required,
json.loads,
display_filename='cfg.json',
)
_assert_exception_trace(excinfo.value.args[0], ('cfg.json is not a file',))
def test_load_from_filename_custom_display_error(tmp_path):
f = tmp_path.joinpath('cfg.json')
f.write_text('{}')
with pytest.raises(ValidationError) as excinfo:
load_from_filename(
f,
map_required,
json.loads,
display_filename='cfg.json',
)
expected = (
'File cfg.json',
'At foo(key=MISSING)',
'Missing required key: key',
)
_assert_exception_trace(excinfo.value.args[0], expected)
conditional_recurse = Map(
'Map', None,