Skip to content

Commit 70231fd

Browse files
committed
implement: Generate the question-format tables from the export (t33)
1 parent b07990b commit 70231fd

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎docs/source/conf.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@
6262
graphviz_output_format = "svg"
6363

6464
templates_path = ["_templates"]
65-
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
65+
exclude_patterns = [
66+
"_build",
67+
"Thumbs.db",
68+
".DS_Store",
69+
# Tables that question-format.md includes: pages of their own otherwise.
70+
"_autosummary/question-format/*.md",
71+
]
6672
source_suffix = [".rst", ".md"]
6773

6874
copybutton_prompt_text = "$ "

‎docs/source/question_format.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,12 @@ def _flatten(
133133
A key holding an object is descended into, so that `workedSolution` becomes
134134
`workedSolution.content`, unless it has a note of its own — `gradeParams` and
135135
`config` hold whatever the box type needs, and are described in prose instead.
136+
An empty object is a row like any other: descending into it would yield nothing,
137+
so a new key holding `{}` would go unnoticed rather than asking for a note.
136138
"""
137139
for key, value in obj.items():
138140
full_path = f"{path}{key}"
139-
if isinstance(value, dict) and full_path not in notes:
141+
if isinstance(value, dict) and value and full_path not in notes:
140142
yield from _flatten(value, notes, f"{full_path}.")
141143
else:
142144
yield full_path, value

‎tests/test_question_format_docs.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ def test_tables_cover_the_exported_keys(tmp_path: Path) -> None:
4949
assert "response.responseInput.config" in _table_keys(tmp_path / "response_area.md")
5050

5151

52-
def test_a_key_with_no_note_is_named(tmp_path: Path) -> None:
52+
# An empty object holds no keys to descend into, so it has to be a row in its own
53+
# right for a new key to be named rather than silently dropped.
54+
@pytest.mark.parametrize("value", [1, {}])
55+
def test_a_key_with_no_note_is_named(value: object, tmp_path: Path) -> None:
5356
"""A key added to the schema stops the build, saying which key needs a note."""
5457
export_dir = Path(shutil.copytree(EXPORTS[0], tmp_path / "export"))
5558
file = sorted(export_dir.glob("question_*.json"))[0]
5659
question = json.loads(file.read_text())
57-
question["madeUp"] = 1
60+
question["madeUp"] = value
5861
file.write_text(json.dumps(question))
5962

6063
with pytest.raises(ValueError, match="madeUp"):

0 commit comments

Comments
 (0)