From 01f4ec5ee4af4aaa5dc7fbfcf47ec6b0760ab819 Mon Sep 17 00:00:00 2001 From: Steve Howell Date: Wed, 1 Jan 2025 15:42:38 +0000 Subject: [PATCH] check-schemas: Enforce that all fixtures get checked. I had to work around that the event type is "saved_snippets", but the author of the feature otherwise correctly used the singular "saved_snippet". --- tools/check-schemas | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tools/check-schemas b/tools/check-schemas index c8debc4da4..0830084438 100755 --- a/tools/check-schemas +++ b/tools/check-schemas @@ -55,29 +55,37 @@ from zerver.lib import event_schema from zerver.lib.data_types import make_checker -def get_event_checker(event: dict[str, Any]) -> Callable[[str, dict[str, Any]], None] | None: +def get_event_checker(event: dict[str, Any]) -> Callable[[str, dict[str, Any]], None]: + # Follow the naming convention to find the event checker. + # Start by grabbing the event type. name = event["type"] + + # Work around the fact that we send a "saved_snippets" (plural) + # event type for an event that really just sends a single value. + if name == "saved_snippets": + name = "saved_snippet" + + # Handle things like attachment_remove_event. if "op" in event: name += "_" + event["op"] + # And add the suffix. name += "_event" - if hasattr(event_schema, name): - return make_checker(getattr(event_schema, name)) - return None + if not hasattr(event_schema, name): + raise ValueError(f"We could not find {name} in event_schemas.py") + + return make_checker(getattr(event_schema, name)) def check_event(name: str, event: dict[str, Any]) -> None: event["id"] = 1 checker = get_event_checker(event) - if checker is not None: - try: - checker(name, event) - except AssertionError: - print(f"\n{EVENTS_JS} has bad data for {name}:\n\n") - raise - else: - print(f"WARNING - NEED SCHEMA: {name}") + try: + checker(name, event) + except AssertionError: + print(f"\n{EVENTS_JS} has bad data for {name}:\n\n") + raise def read_fixtures() -> dict[str, Any]: