Skip to content

Commit 51d732f

Browse files
committed
add more tests and cases
1 parent dc7529e commit 51d732f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

quartodoc/tests/test_validation.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,10 @@ def test_missing_name_contents_2():
7474
with pytest.raises(ValueError) as e:
7575
Builder(sections=sections, package='quartodoc')
7676
assert '- Missing field `name` for element 0 in the list for `contents` located in element 1 in the list for `sections`' in str(e.value)
77+
78+
def test_misplaced_kindpage():
79+
sections = copy.deepcopy(EXAMPLE_SECTIONS)
80+
sections[0]['kind'] = 'page'
81+
with pytest.raises(ValueError) as e:
82+
Builder(sections=sections, package='quartodoc')
83+
assert ' - Missing field `path` for element 0 in the list for `sections`, which you need when setting `kind: page`.' in str(e.value)

quartodoc/validation.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,17 @@ def fmt(err:dict):
1414
msg += f" from root level: `{err['loc'][0]}`"
1515
elif len(err['loc']) == 3:
1616
msg += f" `{err['loc'][2]}` for element {err['loc'][1]} in the list for `{err['loc'][0]}`"
17+
elif len(err['loc']) == 4 and err['loc'][2] == 'Page':
18+
msg += f" `{err['loc'][3]}` for element {err['loc'][1]} in the list for `{err['loc'][0]}`, which you need when setting `kind: page`."
1719
elif len(err['loc']) == 5:
1820
msg += f" `{err['loc'][4]}` for element {err['loc'][3]} in the list for `{err['loc'][2]}` located in element {err['loc'][1]} in the list for `{err['loc'][0]}`"
1921
elif len(err['loc']) == 6 and err['loc'][4] == 'Auto':
2022
msg += f" `{err['loc'][5]}` for element {err['loc'][3]} in the list for `{err['loc'][2]}` located in element {err['loc'][1]} in the list for `{err['loc'][0]}`"
23+
else:
24+
return str(err) # so we can debug and include more cases
2125
else:
2226
msg += str(err)
2327
return msg
28+
29+
30+
# {'loc': ('sections', 0, 'Page', 'path'), 'msg': 'field required', 'type': 'value_error.missing'} ... }

0 commit comments

Comments
 (0)