Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ All notable changes to lectern are documented here.
- **Vendored `slugify`, dropped the `vaultkit` dependency** — the name `vaultkit` on PyPI is an unrelated third-party SDK, so depending on it was a dependency-confusion risk. The one helper used (`slugify`) is now inlined in `lectern/_text.py`, making the public distribution self-contained with no private/ambiguous dependency.

### Fixed
- **Letter-prefixed True/False reveals no longer lose their credit in the grading note.** A TF or code verdict revealed as `\textbf{Answer:} a (True)` or `b (False) --- why` was read as the letter `a`/`b`, so `_outline.csv` carried a letter and `GRADING_NOTE.md` gave neither the True nor the False row any points. `parse_outline_from_tex` now takes the verdict word whenever it leads the reveal, and a bare `T`/`F` on a TF item. A code answer that only mentions "true" later in its text is left alone. The CECS 378 Su26 final used this form on all 10 verdict questions per form; this term's exams use the bare word and are unchanged. Salvaged from the closed #26.
- **Exam section headings no longer strand at the foot of a page.** `\examsection` in `references/reference_exam.tex` now reserves the heading's height plus `\qreserve` before it prints, so it moves to the next page with its first question. The question-level `\needspace` (issue #29) kept each question whole but did nothing for the heading above it. Found on CECS 326 Fa26 Exam 1. Template-only; existing exam `.tex` are not backfilled.
- **`reg-triage` broadsheet table was broken by its own reasoning column.** Signal evidence is joined with `\" | \"`, which ends a Markdown table cell, so every `TRIAGE.md` row spilled into phantom columns. Pipes are escaped now.
- **Declared the `pdfplumber` dependency** that was previously undeclared: added to the `dev` extra (the test suite imports it directly) and to a new optional `verify` extra. `reg-exam-verify` prefers pdfplumber for footer-serial extraction but falls back to the `pdftotext` CLI, so it stays optional at runtime — not a hard dependency.
Expand Down
28 changes: 26 additions & 2 deletions lectern/exam_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,31 @@ def _parse_annotations(tex_content: str) -> dict[int, tuple[str, str]]:
return out


# The verdict must lead the reveal: "True", "a (True)", "b) False --- why".
# A code answer that only mentions "true" later is not a verdict.
_VERDICT_RE = re.compile(r"^(?:[a-d][.)]?\s*)?\(?(true|false)\b", re.I)


def _outline_answer(raw: str, qtype: str) -> str:
"""The ``_outline.csv`` answer for one question's ``\\textbf{Answer:}`` text.

FIB keeps every ``;``-joined blank. TF and code verdict items give the word
``True``/``False`` even when the reveal is letter-prefixed (``a (True)``),
because the grading note keys credit on that word. A bare ``T``/``F`` on a
TF item counts too. Everything else takes the first token.
"""
if qtype == "fib":
return raw
first = raw.split()[0].rstrip(".") if raw else ""
if qtype in ("tf", "code"):
m = _VERDICT_RE.match(raw)
if m:
return m.group(1).capitalize()
if qtype == "tf" and first.upper() in ("T", "F"):
return "True" if first.upper() == "T" else "False"
return first


def parse_outline_from_tex(tex_content: str) -> list[OutlineRow]:
body = tex_content.split("\\begin{document}", 1)[-1]
# Split at every \item, then REGROUP: a question starts at a fragment that
Expand All @@ -229,8 +254,7 @@ def parse_outline_from_tex(tex_content: str) -> list[OutlineRow]:
qtype = _classify(block)
ans_m = _ANS_RE.search(block)
raw = ans_m.group(1).strip() if ans_m else ""
# type-aware: FIB keeps all ;-joined blanks; others take first token
answer = raw if qtype == "fib" else (raw.split()[0].rstrip(".") if raw else "")
answer = _outline_answer(raw, qtype)
name, rubric = annotations.get(q, ("", ""))
if not name:
raise SystemExit(f"exam_pack: question {q} is missing a '% name:' annotation")
Expand Down
33 changes: 32 additions & 1 deletion tests/test_exam_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ExamManifest, FormSpec, OutlineRow, PackResult,
assign_forms, emit_bubble_products, emit_gradescope_roster,
emit_grading_note, emit_region_products, load_manifest,
parse_outline_from_tex, run,
_outline_answer, parse_outline_from_tex, run,
)

FIX = Path(__file__).parent / "fixtures" / "exam_pack"
Expand Down Expand Up @@ -203,6 +203,37 @@ def test_mc_default_rubric_when_unannotated():
assert rows[0].rubric == "Correct = b (3 pts, all-or-nothing)."



@pytest.mark.parametrize("raw,qtype,want", [
("True", "tf", "True"),
("a (True)", "tf", "True"),
("b (False) --- 2^128 is out of reach", "tf", "False"),
("F", "tf", "False"),
("a (True)", "code", "True"),
("b) false", "code", "False"),
# a code answer that only mentions "true" later is not a verdict
("deadlock, since the condition stays true", "code", "deadlock,"),
("b", "mc", "b"),
("confusion; diffusion", "fib", "confusion; diffusion"),
])
def test_outline_answer_normalizes_verdicts(raw, qtype, want):
assert _outline_answer(raw, qtype) == want


def test_letter_prefixed_tf_reveal_gets_credit_in_grading_note(tmp_path):
tex = (
"\\begin{document}\\begin{enumerate}\n"
"% name: Shor vs. AES-256\n"
"\\item \\textit{(1 pts)}~Shor breaks AES-256. \\textsc{T / F}\n"
" \\ifanswers \\textbf{Answer:} b (False) \\fi\n"
"\\end{enumerate}\\end{document}"
)
rows = parse_outline_from_tex(tex)
assert rows[0].type == "tf" and rows[0].answer == "False"
text = _note(tmp_path, rows)
assert "| 0 | `A·Q1·T` | True |" in text and "| +1 | `A·Q1·F` | False |" in text


OUTLINE = [
OutlineRow(1, 2, "mc", "a"),
OutlineRow(2, 1, "tf", "True"),
Expand Down
Loading