-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add reusable CI validation utilities for development automation #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,18 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Reusable validation helpers for CI scripts. | ||
| """Reusable validation helpers for CI scripts. | ||
|
|
||
| These helpers reduce boilerplate and provide clearer failure semantics | ||
| using specific exception types. | ||
| These helpers reduce boilerplate and provide clearer failure semantics using specific | ||
| exception types. | ||
| """ | ||
|
|
||
| from typing import Any, Iterable | ||
|
|
||
|
|
||
| def validate_metric_ranges(metrics: dict[str, Any], fields: Iterable[str]) -> None: | ||
| """Ensure each metric in fields is within [0, 1]. | ||
|
|
||
| Raises: | ||
| Raises | ||
| ------ | ||
| ValueError: if any metric is missing or out of range. | ||
| """ | ||
| for field in fields: | ||
|
|
@@ -27,10 +28,15 @@ def validate_metric_ranges(metrics: dict[str, Any], fields: Iterable[str]) -> No | |
| raise ValueError(f"{pretty} should be between 0 and 1") | ||
|
|
||
|
|
||
| def validate_required_keys(obj: dict[str, Any], keys: Iterable[str], label: str = "object") -> None: | ||
| def validate_required_keys( | ||
| obj: dict[str, Any], | ||
| keys: Iterable[str], | ||
| label: str = "object", | ||
| ) -> None: | ||
|
Comment on lines
+31
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation iterates through keys and fails on the first one that's missing. For a better developer experience, consider collecting all missing keys and reporting them in a single |
||
| """Validate that all keys exist in obj. | ||
|
|
||
| Raises: | ||
| Raises | ||
| ------ | ||
|
Comment on lines
+38
to
+39
|
||
| KeyError: if a required key is missing. | ||
| """ | ||
| for key in keys: | ||
|
|
@@ -39,10 +45,15 @@ def validate_required_keys(obj: dict[str, Any], keys: Iterable[str], label: str | |
| raise KeyError(f"{label} should have {pretty}") | ||
|
|
||
|
|
||
| def validate_hasattrs(instance: Any, attrs: Iterable[str], label: str = "object") -> None: | ||
| def validate_hasattrs( | ||
| instance: Any, | ||
| attrs: Iterable[str], | ||
| label: str = "object", | ||
| ) -> None: | ||
|
Comment on lines
+48
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to |
||
| """Validate that instance has all attributes in attrs. | ||
|
|
||
| Raises: | ||
| Raises | ||
| ------ | ||
|
Comment on lines
+55
to
+56
|
||
| AttributeError: if a required attribute is missing. | ||
| """ | ||
| for attr in attrs: | ||
|
|
@@ -57,4 +68,3 @@ def ensure(condition: bool, message: str) -> None: | |
| """ | ||
| if not condition: | ||
| raise AssertionError(message) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring format should use 'Raises:' with a colon instead of 'Raises' with dashes for consistency with Python docstring conventions.