record-manager-template/tests/public/test_public.py
trevon 7e5c368800
Some checks failed
grade / grade (push) Failing after 1m1s
template: starter + setup + milestone + agents + workflow
2026-08-26 01:07:25 +00:00

32 lines
1.1 KiB
Python

"""Public tests for the Record Manager (M1: build + menu basics).
These ship to students and run under the grade harness (pytest, cwd = the
submission). M1 features only: add + list must work after `make` (delete/save/load come in
later milestones — the hidden suite gates those).
"""
import pathlib
import subprocess
def _run(cmd, timeout=180, **kw):
return subprocess.run(cmd, capture_output=True, text=True, timeout=timeout, **kw)
def test_m1_menu_basics():
root = pathlib.Path.cwd()
build = _run(["make", "-C", str(root), "-j2"])
assert build.returncode == 0, "BUILD FAILED:\n" + build.stdout + build.stderr
recman = root / "build" / "recman"
assert recman.exists(), "build/recman missing after make"
session = (
"add\nAda Lovelace\nada@x\n555-0100\n"
"add\nGrace Hopper\ngrace@x\n444-0200\n"
"list\n"
"quit\n"
)
r = _run([str(recman)], input=session)
assert "added: Ada Lovelace" in r.stdout, "add failed:\n" + r.stdout
assert "added: Grace Hopper" in r.stdout, "add failed:\n" + r.stdout
assert "Grace Hopper" in r.stdout, "list did not show the records:\n" + r.stdout