MakerFLOSS/tests/test_gen_overview.py
sjat 4dc975062a
All checks were successful
Build docs site / build (push) Successful in 49s
Build slides / build (push) Successful in 1m11s
docs(hardware): reconcile rack01 to as-mounted layout and document cabling
Rebuild rack01 from the physically remounted hardware:
- Correct stale positions/ports/outlets for pp01, pp02, sw01, pdu01-04
- Model shelves as 1U trays (towers stand above without consuming rack U's);
  add shf02 and empty half-depth shf03/shf04
- Add ups01/ups02; reseat nas01/02 and sw02-05; move srv04-07 onto shf02
- Add `wan` hardware kind; add WAN demarcation hosts wan01 (active) and
  wan02 (staging)
- Document full live network wiring: srv01-07 -> pp02 -> sw01 (LAN) and
  srv01 eth0 -> pp02 -> pp01 -> wan01 (WAN); keep non-active lines
  (wan2, working-table patches, sw01 mgmt) in notes only
- Regenerate hardware index + rack01 elevation/network/power artifacts

Also includes the in-progress generator updates (gen_rack.py, gen_overview.py,
Makefile, tests) that the regenerated artifacts depend on.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-30 21:31:48 +02:00

48 lines
1.5 KiB
Python

import pytest
import gen_overview
CFG = {
"required_fields": ["hostname", "kind", "status"],
"enums": {
"kind": ["server", "switch", "pdu"],
"status": ["in-use", "staging", "spare"],
},
"key_field": "hostname",
}
def validate(stem, fm):
from pathlib import Path
gen_overview.validate(Path(f"{stem}.md"), fm, CFG)
def test_missing_required_field_names_field_and_lists_allowed():
with pytest.raises(gen_overview.SchemaError) as ei:
validate("srv06", {"hostname": "srv06", "kind": "server"})
msg = str(ei.value)
assert "status" in msg # which field
assert "in-use" in msg # an allowed value, so a novice knows what to type
def test_enum_violation_lists_allowed_values():
with pytest.raises(gen_overview.SchemaError) as ei:
validate("x", {"hostname": "x", "kind": "router", "status": "in-use"})
msg = str(ei.value)
assert "router" in msg # the offending value
assert "server" in msg # an allowed value
def test_filename_mismatch_explains_the_rename():
with pytest.raises(gen_overview.SchemaError) as ei:
validate("srv06", {"hostname": "srv07", "kind": "server", "status": "in-use"})
msg = str(ei.value).lower()
assert "srv07.md" in msg or "rename" in msg
def test_error_report_points_to_the_guide(capsys):
gen_overview.report_errors(["srv06.md: missing required field 'status'"], "hardware")
err = capsys.readouterr().err
assert "make docs-index" in err
assert gen_overview.GUIDE_URL in err