test(characterization): fail when a public-API golden is missing instead of regenerating it

Both guards in test_public_api.py rewrote a missing golden and passed, so deleting public_imports.json along with an import would have hidden the removal. They now regenerate only under UPDATE_GOLDEN=1.
This commit is contained in:
agessaman committed 2026-10-01 20:21:03 -07:00
1 parent 09a6b50564
commit b62806f58b
1 file changed
+4 -2
+4 -2
View File
@@ -74,9 +74,10 @@ def test_no_public_name_was_removed():
import os
current = _public_names()
if os.environ.get("UPDATE_GOLDEN") == "1" or not GOLDEN.exists():
if os.environ.get("UPDATE_GOLDEN") == "1":
GOLDEN.write_text(json.dumps(current, indent=1, sort_keys=True) + "\n", encoding="utf-8")
return
assert GOLDEN.exists(), f"{GOLDEN} missing; generate it with UPDATE_GOLDEN=1"
recorded = json.loads(GOLDEN.read_text(encoding="utf-8"))
missing = []
for module, names in recorded.items():
@@ -91,9 +92,10 @@ def test_no_public_name_was_removed():
def test_no_imported_public_name_was_dropped():
import os
if os.environ.get("UPDATE_GOLDEN") == "1" or not IMPORTS_GOLDEN.exists():
if os.environ.get("UPDATE_GOLDEN") == "1":
IMPORTS_GOLDEN.write_text(json.dumps(_public_imports(), indent=1, sort_keys=True) + "\n", encoding="utf-8")
return
assert IMPORTS_GOLDEN.exists(), f"{IMPORTS_GOLDEN} missing; generate it with UPDATE_GOLDEN=1"
recorded = json.loads(IMPORTS_GOLDEN.read_text(encoding="utf-8"))
missing = [
f"{module}: {name}"