|
5 | 5 |
|
6 | 6 | from __future__ import annotations |
7 | 7 |
|
8 | | -from typing import TypeVar |
| 8 | +from typing import TypeVar, get_args, get_origin, get_type_hints |
9 | 9 |
|
10 | 10 | import pyarrow as pa |
11 | 11 | import pytest |
12 | 12 | from vgi_rpc.log import Level, Message |
| 13 | +from vgi_rpc.rpc import Stream |
13 | 14 | from vgi_rpc.utils import deserialize_record_batch |
14 | 15 |
|
15 | 16 | from tests.conftest import make_schema |
16 | 17 | from vgi.arguments import Arg, Arguments, ArgumentValidationError |
17 | | -from vgi.table_function import ( |
18 | | - TableCardinality, |
| 18 | +from vgi.protocol import ( |
| 19 | + ProcessState, |
| 20 | + ScalarExchangeState, |
| 21 | + TableInOutExchangeState, |
| 22 | + TableInOutFinalizeState, |
| 23 | + TableProducerState, |
| 24 | + VgiProtocol, |
19 | 25 | ) |
| 26 | +from vgi.table_function import TableCardinality |
20 | 27 |
|
21 | 28 | T = TypeVar("T") |
22 | 29 |
|
@@ -259,6 +266,25 @@ def test_exact_cardinality(self) -> None: |
259 | 266 | exact = TableCardinality(estimate=1, max=1) |
260 | 267 | assert exact.estimate == exact.max == 1 |
261 | 268 |
|
| 269 | + |
| 270 | +class TestProtocolStateTyping: |
| 271 | + """Tests for VGI protocol stream state typing.""" |
| 272 | + |
| 273 | + def test_init_declares_process_state_union(self) -> None: |
| 274 | + """VgiProtocol.init() returns Stream with the ProcessState union.""" |
| 275 | + hints = get_type_hints(VgiProtocol.init) |
| 276 | + return_hint = hints["return"] |
| 277 | + state_arg = get_args(return_hint)[0] |
| 278 | + assert state_arg == ProcessState |
| 279 | + assert set(get_args(state_arg)) == { |
| 280 | + ScalarExchangeState, |
| 281 | + TableProducerState, |
| 282 | + TableInOutExchangeState, |
| 283 | + TableInOutFinalizeState, |
| 284 | + } |
| 285 | + assert get_args(return_hint)[1].__name__ == "GlobalInitResponse" |
| 286 | + assert get_origin(return_hint) is Stream |
| 287 | + |
262 | 288 | def test_frozen(self) -> None: |
263 | 289 | """TableCardinality should be immutable (frozen dataclass).""" |
264 | 290 | info = TableCardinality(estimate=100, max=1000) |
|
0 commit comments