mirror of
https://github.com/saymrwulf/QuantumLearning.git
synced 2026-05-23 22:13:50 +00:00
60 lines
2.1 KiB
Python
60 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
from quantum_learning import (
|
|
canonical_course_steps,
|
|
entry_notebook_path,
|
|
project_root,
|
|
reference_notebook_path,
|
|
visible_notebook_root_names,
|
|
)
|
|
|
|
|
|
def _notebook_text(path):
|
|
data = json.loads(path.read_text())
|
|
return "\n".join("".join(cell.get("source", [])) for cell in data.get("cells", []))
|
|
|
|
|
|
def test_start_here_is_the_only_supported_entrypoint():
|
|
assert entry_notebook_path() == project_root() / "notebooks" / "START_HERE.ipynb"
|
|
|
|
app_script = (project_root() / "scripts" / "app.sh").read_text()
|
|
assert "lab/tree/notebooks/START_HERE.ipynb" in app_script
|
|
|
|
|
|
def test_visible_notebook_root_is_curated():
|
|
notebook_root = project_root() / "notebooks"
|
|
visible_names = sorted(path.name for path in notebook_root.iterdir() if not path.name.startswith("."))
|
|
assert visible_names == sorted(visible_notebook_root_names())
|
|
|
|
|
|
def test_reference_notebook_is_not_in_root():
|
|
assert reference_notebook_path().exists()
|
|
assert not (project_root() / "notebooks" / "PROFESSIONAL_PATH.ipynb").exists()
|
|
|
|
|
|
def test_mainline_course_notebooks_have_navigation_guardrails():
|
|
steps = canonical_course_steps()
|
|
for index, step in enumerate(steps):
|
|
path = project_root() / step.path
|
|
text = _notebook_text(path)
|
|
assert "<!-- COURSE_NAV_TOP -->" in text
|
|
assert "<!-- COURSE_NAV_BOTTOM -->" in text
|
|
assert "What To Open Next" in text
|
|
if index == 0:
|
|
assert "This is the start of the mainline course" in text
|
|
if index < len(steps) - 1:
|
|
next_title = steps[index + 1].title
|
|
assert next_title in text
|
|
else:
|
|
assert "This notebook closes the mainline course" in text
|
|
|
|
|
|
def test_start_here_does_not_contain_stale_branching_advice():
|
|
text = _notebook_text(project_root() / "notebooks" / "START_HERE.ipynb")
|
|
|
|
assert "Read the rest of this notebook, then open `PROFESSIONAL_PATH.ipynb`." not in text
|
|
assert "Open `PROFESSIONAL_PATH.ipynb` next." not in text
|
|
assert "`00_circuit_literacy.ipynb`" not in text
|
|
assert "COURSE_BLUEPRINT.ipynb" in text
|