Skip to content

Commit 8206d13

Browse files
authored
Merge pull request #15 from Query-farm/refactor/testing-type-annotations
refactor: Add LogExpectation TypedDict for better type safety
2 parents 89d3298 + c2294ea commit 8206d13

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎.beads/issues.jsonl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
{"id":"vgi-python-p91","title":"Move exception classes from function.py to own file","description":"Move InitIdentifierError and SchemaValidationError from vgi/function.py to a new vgi/exceptions.py file. Update imports in function.py and any other files that reference these exceptions.","status":"closed","priority":2,"issue_type":"task","created_at":"2026-01-04T09:12:28.058227-05:00","created_by":"rusty","updated_at":"2026-01-04T09:17:52.477661-05:00","closed_at":"2026-01-04T09:17:52.477661-05:00","close_reason":"Closed"}
4747
{"id":"vgi-python-qud","title":"Test FunctionStorageSqlite: global_delete, global_exists, queue_clear","notes":"Coverage: 83% in vgi/function_storage.py. Missing tests for:\n- Line 266: KeyError path in global_get (key not found)\n- Lines 273-278: global_delete method\n- Lines 282-290: global_exists method \n- Line 337: queue_push with empty list\n- Lines 376-385: queue_clear method\n\nThese storage operations need direct unit tests to ensure correctness.","status":"closed","priority":3,"issue_type":"task","created_at":"2026-01-04T22:15:25.982124-05:00","created_by":"rusty","updated_at":"2026-01-04T22:30:05.625934-05:00","closed_at":"2026-01-04T22:30:05.625934-05:00","close_reason":"Added comprehensive tests for FunctionStorageSqlite. Coverage improved from 83% to 98%."}
4848
{"id":"vgi-python-r3t","title":"Consolidate test client infrastructure in testing.py","description":"testing.py has three test client classes (FunctionTestClient, TableFunctionTestClient, ScalarFunctionTestClient) with shared infrastructure patterns. Extend _BaseTestClient pattern to reduce code duplication. Consider using a single unified client with method dispatch based on function type.","status":"closed","priority":3,"issue_type":"task","created_at":"2026-01-04T20:06:53.913912-05:00","created_by":"rusty","updated_at":"2026-01-04T22:02:51.368907-05:00","closed_at":"2026-01-04T22:02:51.368907-05:00","close_reason":"Not warranted - _BaseTestClient already provides shared infrastructure (context manager, log capture, logging). The three clients handle genuinely different protocols (TableInOut with finalize, TableFunction with no input, Scalar with different protocol). Unifying would add type detection complexity without real benefit."}
49-
{"id":"vgi-python-set","title":"Improve type annotations in testing.py test helpers","notes":"92.61% type coverage (70 Anys) in vgi/testing.py\n\nMain opportunities:\n- Lines 136-137, 641-642, 685-686, etc: `args: tuple[Any, ...]` and `kwargs: dict[str, Any]`\n Could use ParamSpec or more specific signatures\n- Lines 151-152: `positional: tuple[pa.Scalar[Any], ...]` - unavoidable (PyArrow)\n- Lines 761, 843: Log expectation dicts - could use TypedDict\n\nLower priority since these are test helpers and flexibility is intentional.","status":"open","priority":4,"issue_type":"task","created_at":"2026-01-04T22:19:50.204524-05:00","created_by":"rusty","updated_at":"2026-01-04T22:20:05.418044-05:00"}
49+
{"id":"vgi-python-set","title":"Improve type annotations in testing.py test helpers","notes":"92.61% type coverage (70 Anys) in vgi/testing.py\n\nMain opportunities:\n- Lines 136-137, 641-642, 685-686, etc: `args: tuple[Any, ...]` and `kwargs: dict[str, Any]`\n Could use ParamSpec or more specific signatures\n- Lines 151-152: `positional: tuple[pa.Scalar[Any], ...]` - unavoidable (PyArrow)\n- Lines 761, 843: Log expectation dicts - could use TypedDict\n\nLower priority since these are test helpers and flexibility is intentional.","status":"closed","priority":4,"issue_type":"task","created_at":"2026-01-04T22:19:50.204524-05:00","created_by":"rusty","updated_at":"2026-01-05T12:09:36.813123-05:00","closed_at":"2026-01-05T12:09:36.813123-05:00","close_reason":"Closed"}
5050
{"id":"vgi-python-uq8","title":"Add validation for missing arg_types in extract_argument_specs","description":"In extract_argument_specs(), if an argument name is missing from arg_types dict, it silently defaults to pa.null(). This could mask bugs where the caller forgot to provide a type. Consider raising an error or logging a warning when a type mapping is missing.","status":"closed","priority":2,"issue_type":"task","created_at":"2026-01-05T11:51:19.501577-05:00","created_by":"rusty","updated_at":"2026-01-05T11:53:52.594504-05:00","closed_at":"2026-01-05T11:53:52.594504-05:00","close_reason":"Closed"}
5151
{"id":"vgi-python-vir","title":"Add tests for varargs in Arg descriptor","description":"In tests/test_arguments.py:\n- Basic varargs: receives multiple values as tuple\n- Single value varargs: works with exactly 1 value \n- Empty varargs: raises error when 0 values\n- Type validation: each element validated\n- Varargs with constraints (ge, le, etc.): validates each element\n- Varargs with choices: validates each element against choices","status":"closed","priority":2,"issue_type":"task","created_at":"2026-01-05T10:49:20.285269-05:00","created_by":"rusty","updated_at":"2026-01-05T11:00:06.124186-05:00","closed_at":"2026-01-05T11:00:06.124186-05:00","close_reason":"Added comprehensive tests for varargs in Arg descriptor and Arguments.get_varargs()","dependencies":[{"issue_id":"vgi-python-vir","depends_on_id":"vgi-python-jrf","type":"blocks","created_at":"2026-01-05T10:49:26.454614-05:00","created_by":"rusty"}]}
5252
{"id":"vgi-python-vzg","title":"Update documentation for DuckDB settings feature","description":"Update documentation to cover DuckDB settings feature.\n\nFiles to update:\n1. docs/protocol.md - Add settings to protocol flow diagrams and Invocation fields\n2. docs/metadata.md - Document required_settings in Meta class\n3. CLAUDE.md - Add example showing settings usage pattern\n4. docs/lifecycle.md - Mention settings availability during bind\n\nInclude:\n- When settings are available (bind phase and later)\n- How to declare required settings\n- How to access settings in function code\n- Example patterns for settings-dependent output schemas","status":"closed","priority":3,"issue_type":"task","created_at":"2026-01-04T13:05:48.795757-05:00","created_by":"rusty","updated_at":"2026-01-04T13:28:21.005166-05:00","closed_at":"2026-01-04T13:28:21.005166-05:00","close_reason":"Documentation updated in protocol.md and CLAUDE.md","dependencies":[{"issue_id":"vgi-python-vzg","depends_on_id":"vgi-python-67w","type":"blocks","created_at":"2026-01-04T13:06:14.089469-05:00","created_by":"rusty"}]}

‎vgi/testing.py‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
import uuid
7878
from collections.abc import Callable, Generator, Iterator
79-
from typing import Any, Self, cast
79+
from typing import Any, Self, TypedDict, cast
8080

8181
import pyarrow as pa
8282
import structlog
@@ -112,6 +112,7 @@
112112
"TableInOutFunctionTestClientError",
113113
"TableFunctionTestClient",
114114
"ScalarFunctionTestClient",
115+
"LogExpectation",
115116
"batch",
116117
"assert_function_output",
117118
"assert_function_logs",
@@ -123,6 +124,29 @@
123124
]
124125

125126

127+
class LogExpectation(TypedDict, total=False):
128+
"""Type definition for log message expectations in assert_function_logs.
129+
130+
All fields are optional. Use any combination to match log messages:
131+
- level: Match exact log level (Level enum)
132+
- message: Match exact message string
133+
- message_contains: Match if message contains this substring
134+
- message_startswith: Match if message starts with this prefix
135+
136+
Example:
137+
expected_logs: list[LogExpectation] = [
138+
{"level": Level.INFO, "message_contains": "Processing"},
139+
{"message_startswith": "Completed"},
140+
]
141+
142+
"""
143+
144+
level: Level
145+
message: str
146+
message_contains: str
147+
message_startswith: str
148+
149+
126150
class TableInOutFunctionTestClientError(Exception):
127151
"""Error raised by TableInOutFunctionTestClient operations."""
128152

@@ -758,7 +782,7 @@ def assert_function_output(
758782
def assert_function_logs(
759783
function: type[TableInOutGenerator] | type[TableInOutFunction],
760784
input: list[pa.RecordBatch],
761-
expected_logs: list[dict[str, Any]],
785+
expected_logs: list[LogExpectation],
762786
args: tuple[Any, ...] | None = None,
763787
kwargs: dict[str, Any] | None = None,
764788
msg: str | None = None,
@@ -840,7 +864,7 @@ def assert_function_logs(
840864
return outputs
841865

842866

843-
def _log_matches(log: Message, expectation: dict[str, Any]) -> bool:
867+
def _log_matches(log: Message, expectation: LogExpectation) -> bool:
844868
"""Check if a log message matches an expectation dict."""
845869
return not (
846870
("level" in expectation and log.level != expectation["level"])

0 commit comments

Comments
 (0)