Files
felhom.eu/scripts/test_repo_gates_docstring.py
T

22 lines
1009 B
Python

#!/usr/bin/env python3
"""R-418: repo_gates.py's docstring list of gates names exactly the gates in GATES, in the same order.
It drifted twice (eleven listed while thirteen ran, 2026-08-24..09-01; then fifteen while seventeen ran). Run:
python3 scripts/test_repo_gates_docstring.py"""
import os
import re
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import repo_gates # noqa: E402
listed = re.findall(r"^ {1,3}\d+b?\. +([a-z][a-z0-9-]+) ", repo_gates.__doc__, re.M)
registered = [g[0] for g in repo_gates.GATES]
if listed != registered:
print("FAIL: the docstring lists %d gate(s), GATES registers %d" % (len(listed), len(registered)))
print(" only listed: %s" % sorted(set(listed) - set(registered)))
print(" only registered: %s" % sorted(set(registered) - set(listed)))
if set(listed) == set(registered):
print(" (same set, different order)")
sys.exit(1)
print("OK: the docstring lists the %d registered gates, in order" % len(registered))