Skip to content

Commit 66b1630

Browse files
committed
refactor: remove unnecessary type casts for event channel in integration and unit tests
1 parent 2e29fd7 commit 66b1630

File tree

13 files changed

+46
-96
lines changed

13 files changed

+46
-96
lines changed

tests/integration/test_adapters/test_asyncmy/test_extensions/test_events.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# pyright: reportPrivateUsage=false, reportAttributeAccessIssue=false, reportArgumentType=false
22
"""AsyncMy integration tests for the EventChannel queue backend."""
33

4-
from typing import TYPE_CHECKING, Any, cast
4+
from typing import Any
55

66
import pytest
77
from pytest_databases.docker.mysql import MySQLService
@@ -10,9 +10,6 @@
1010
from sqlspec.adapters.asyncmy import AsyncmyConfig
1111
from sqlspec.migrations.commands import AsyncMigrationCommands
1212

13-
if TYPE_CHECKING:
14-
from sqlspec.extensions.events import AsyncEventChannel
15-
1613
pytestmark = pytest.mark.xdist_group("mysql")
1714

1815

@@ -41,7 +38,7 @@ async def test_asyncmy_event_channel_queue_fallback(mysql_service: MySQLService,
4138

4239
spec = SQLSpec()
4340
spec.add_config(config)
44-
channel = cast("AsyncEventChannel", spec.event_channel(config))
41+
channel = spec.event_channel(config)
4542

4643
assert channel._backend_name == "table_queue"
4744

@@ -87,7 +84,7 @@ async def test_asyncmy_event_channel_multiple_messages(mysql_service: MySQLServi
8784

8885
spec = SQLSpec()
8986
spec.add_config(config)
90-
channel = cast("AsyncEventChannel", spec.event_channel(config))
87+
channel = spec.event_channel(config)
9188

9289
event_ids = [
9390
await channel.publish("multi_test", {"index": 0}),
@@ -134,7 +131,7 @@ async def test_asyncmy_event_channel_nack_redelivery(mysql_service: MySQLService
134131

135132
spec = SQLSpec()
136133
spec.add_config(config)
137-
channel = cast("AsyncEventChannel", spec.event_channel(config))
134+
channel = spec.event_channel(config)
138135

139136
event_id = await channel.publish("nack_test", {"retry": True})
140137

tests/integration/test_adapters/test_asyncpg/test_extensions/test_events.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# pyright: reportPrivateUsage=false
22
"""AsyncPG integration tests for the EventChannel native backend."""
33

4-
from typing import cast
5-
64
import pytest
75
from pytest_databases.docker.postgres import PostgresService
86

97
from sqlspec import SQLSpec
108
from sqlspec.adapters.asyncpg import AsyncpgConfig
11-
from sqlspec.extensions.events import AsyncEventChannel
129

1310
pytestmark = pytest.mark.xdist_group("postgres")
1411

@@ -30,7 +27,7 @@ async def test_asyncpg_native_event_channel(postgres_service: PostgresService) -
3027

3128
spec = SQLSpec()
3229
spec.add_config(config)
33-
channel = cast(AsyncEventChannel, spec.event_channel(config))
30+
channel = spec.event_channel(config)
3431

3532
assert channel._backend_name == "listen_notify"
3633

tests/integration/test_adapters/test_asyncpg/test_extensions/test_events_listen_notify.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
"""PostgreSQL LISTEN/NOTIFY event channel tests for asyncpg adapter."""
33

44
import asyncio
5-
from typing import TYPE_CHECKING, Any, cast
5+
from typing import Any
66

77
import pytest
88

99
from sqlspec import SQLSpec
1010
from sqlspec.adapters.asyncpg import AsyncpgConfig
1111
from sqlspec.migrations.commands import AsyncMigrationCommands
1212

13-
if TYPE_CHECKING:
14-
from sqlspec.extensions.events import AsyncEventChannel
15-
1613
pytestmark = pytest.mark.xdist_group("postgres")
1714

1815

@@ -32,7 +29,7 @@ async def test_asyncpg_listen_notify_publish_and_ack(postgres_service: "Any") ->
3229

3330
spec = SQLSpec()
3431
spec.add_config(config)
35-
channel = cast("AsyncEventChannel", spec.event_channel(config))
32+
channel = spec.event_channel(config)
3633

3734
assert channel._backend_name == "listen_notify"
3835

@@ -58,7 +55,7 @@ async def test_asyncpg_listen_notify_message_delivery(postgres_service: "Any") -
5855

5956
spec = SQLSpec()
6057
spec.add_config(config)
61-
channel = cast("AsyncEventChannel", spec.event_channel(config))
58+
channel = spec.event_channel(config)
6259

6360
received: list[Any] = []
6461

@@ -105,7 +102,7 @@ async def test_asyncpg_hybrid_listen_notify_durable(postgres_service: "Any", tmp
105102

106103
spec = SQLSpec()
107104
spec.add_config(config)
108-
channel = cast("AsyncEventChannel", spec.event_channel(config))
105+
channel = spec.event_channel(config)
109106

110107
assert channel._backend_name == "listen_notify_durable"
111108

@@ -147,7 +144,7 @@ async def test_asyncpg_listen_notify_metadata(postgres_service: "Any") -> None:
147144

148145
spec = SQLSpec()
149146
spec.add_config(config)
150-
channel = cast("AsyncEventChannel", spec.event_channel(config))
147+
channel = spec.event_channel(config)
151148

152149
received: list[Any] = []
153150

tests/integration/test_adapters/test_duckdb/test_extensions/test_events.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
"""DuckDB integration tests for EventChannel queue fallback."""
22

3-
from typing import TYPE_CHECKING, cast
4-
53
import pytest
64

75
from sqlspec import SQLSpec
86
from sqlspec.adapters.duckdb import DuckDBConfig
97
from sqlspec.migrations.commands import SyncMigrationCommands
108

11-
if TYPE_CHECKING:
12-
from sqlspec.extensions.events import SyncEventChannel
13-
14-
159
@pytest.mark.integration
1610
@pytest.mark.duckdb
1711
def test_duckdb_event_channel_queue_fallback(tmp_path) -> None:
@@ -31,7 +25,7 @@ def test_duckdb_event_channel_queue_fallback(tmp_path) -> None:
3125

3226
spec = SQLSpec()
3327
spec.add_config(config)
34-
channel = cast("SyncEventChannel", spec.event_channel(config))
28+
channel = spec.event_channel(config)
3529

3630
event_id = channel.publish("notifications", {"action": "duck"})
3731
iterator = channel.iter_events("notifications", poll_interval=0.05)

tests/integration/test_adapters/test_oracledb/test_extensions/test_events.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import asyncio
55
import os
66
from textwrap import dedent
7-
from typing import TYPE_CHECKING, cast
7+
from typing import TYPE_CHECKING
88

99
import pytest
1010

@@ -15,8 +15,6 @@
1515
if TYPE_CHECKING:
1616
from pathlib import Path
1717

18-
from sqlspec.extensions.events import AsyncEventChannel, SyncEventChannel
19-
2018
pytestmark = pytest.mark.xdist_group("oracle")
2119

2220
ORACLE_HOST = os.environ.get("ORACLE_TEST_HOST", "127.0.0.1")
@@ -108,7 +106,7 @@ def test_oracle_sync_event_channel_queue_fallback(tmp_path: "Path") -> None:
108106

109107
spec = SQLSpec()
110108
spec.add_config(config)
111-
channel = cast("SyncEventChannel", spec.event_channel(config))
109+
channel = spec.event_channel(config)
112110

113111
event_id = channel.publish("notifications", {"action": "oracle"})
114112
iterator = channel.iter_events("notifications", poll_interval=0.5)
@@ -148,7 +146,7 @@ async def test_oracle_async_event_channel_queue_fallback(tmp_path: "Path") -> No
148146

149147
spec = SQLSpec()
150148
spec.add_config(config)
151-
channel = cast("AsyncEventChannel", spec.event_channel(config))
149+
channel = spec.event_channel(config)
152150

153151
event_id = await channel.publish("notifications", {"action": "oracle_async"})
154152
iterator = channel.iter_events("notifications", poll_interval=0.5)

tests/integration/test_adapters/test_psqlpy/test_extensions/test_events.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""Psqlpy integration tests for the EventChannel queue backend."""
33

44
import asyncio
5-
from typing import TYPE_CHECKING, cast
65

76
import pytest
87
from pytest_databases.docker.postgres import PostgresService
@@ -11,9 +10,6 @@
1110
from sqlspec.adapters.psqlpy import PsqlpyConfig
1211
from sqlspec.migrations.commands import AsyncMigrationCommands
1312

14-
if TYPE_CHECKING:
15-
from sqlspec.extensions.events import AsyncEventChannel
16-
1713
pytestmark = pytest.mark.xdist_group("postgres")
1814

1915

@@ -40,7 +36,7 @@ async def test_psqlpy_event_channel_queue_fallback(tmp_path, postgres_service: P
4036

4137
spec = SQLSpec()
4238
spec.add_config(config)
43-
channel = cast("AsyncEventChannel", spec.event_channel(config))
39+
channel = spec.event_channel(config)
4440

4541
event_id = await channel.publish("notifications", {"action": "psqlpy"})
4642
iterator = channel.iter_events("notifications", poll_interval=0.1)

tests/integration/test_adapters/test_psqlpy/test_extensions/test_events_listen_notify.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22
"""PostgreSQL LISTEN/NOTIFY event channel tests for psqlpy adapter."""
33

44
import asyncio
5-
from typing import TYPE_CHECKING, Any, cast
5+
from typing import Any
66

77
import pytest
88

99
from sqlspec import SQLSpec
1010
from sqlspec.adapters.psqlpy import PsqlpyConfig
1111
from sqlspec.migrations.commands import AsyncMigrationCommands
1212

13-
if TYPE_CHECKING:
14-
from sqlspec.extensions.events import AsyncEventChannel
15-
1613
pytestmark = pytest.mark.xdist_group("postgres")
1714

1815

@@ -31,7 +28,7 @@ async def test_psqlpy_listen_notify_native(postgres_service: "Any") -> None:
3128

3229
spec = SQLSpec()
3330
spec.add_config(config)
34-
channel = cast("AsyncEventChannel", spec.event_channel(config))
31+
channel = spec.event_channel(config)
3532

3633
received: list[Any] = []
3734

@@ -78,7 +75,7 @@ async def test_psqlpy_listen_notify_hybrid(postgres_service: "Any", tmp_path) ->
7875

7976
spec = SQLSpec()
8077
spec.add_config(config)
81-
channel = cast("AsyncEventChannel", spec.event_channel(config))
78+
channel = spec.event_channel(config)
8279

8380
received: list[Any] = []
8481

tests/integration/test_adapters/test_psycopg/test_extensions/test_events.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""Psycopg integration tests for the EventChannel queue backend."""
33

44
import asyncio
5-
from typing import TYPE_CHECKING, cast
65

76
import pytest
87
from pytest_databases.docker.postgres import PostgresService
@@ -11,9 +10,6 @@
1110
from sqlspec.adapters.psycopg import PsycopgAsyncConfig, PsycopgSyncConfig
1211
from sqlspec.migrations.commands import AsyncMigrationCommands, SyncMigrationCommands
1312

14-
if TYPE_CHECKING:
15-
from sqlspec.extensions.events import AsyncEventChannel, SyncEventChannel
16-
1713
pytestmark = pytest.mark.xdist_group("postgres")
1814

1915

@@ -38,7 +34,7 @@ def test_psycopg_sync_event_channel_queue_fallback(tmp_path, postgres_service: P
3834

3935
spec = SQLSpec()
4036
spec.add_config(config)
41-
channel = cast("SyncEventChannel", spec.event_channel(config))
37+
channel = spec.event_channel(config)
4238

4339
event_id = channel.publish("notifications", {"action": "queue"})
4440
iterator = channel.iter_events("notifications", poll_interval=0.1)
@@ -74,7 +70,7 @@ async def test_psycopg_async_event_channel_queue_fallback(tmp_path, postgres_ser
7470

7571
spec = SQLSpec()
7672
spec.add_config(config)
77-
channel = cast("AsyncEventChannel", spec.event_channel(config))
73+
channel = spec.event_channel(config)
7874

7975
event_id = await channel.publish("notifications", {"action": "async_queue"})
8076
iterator = channel.iter_events("notifications", poll_interval=0.1)

tests/integration/test_adapters/test_psycopg/test_extensions/test_events_listen_notify.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33

44
import asyncio
55
import time
6-
from typing import TYPE_CHECKING, Any, cast
6+
from typing import Any
77

88
import pytest
99

1010
from sqlspec import SQLSpec
1111
from sqlspec.adapters.psycopg import PsycopgAsyncConfig, PsycopgSyncConfig
1212
from sqlspec.migrations.commands import AsyncMigrationCommands, SyncMigrationCommands
1313

14-
if TYPE_CHECKING:
15-
from sqlspec.extensions.events import AsyncEventChannel, SyncEventChannel
16-
1714
pytestmark = pytest.mark.xdist_group("postgres")
1815

1916

@@ -31,7 +28,7 @@ def test_psycopg_sync_listen_notify(postgres_service: "Any") -> None:
3128

3229
spec = SQLSpec()
3330
spec.add_config(config)
34-
channel = cast("SyncEventChannel", spec.event_channel(config))
31+
channel = spec.event_channel(config)
3532
backend = channel._backend
3633
assert "_ensure_sync_listener" in dir(backend)
3734

@@ -62,7 +59,7 @@ async def test_psycopg_async_listen_notify(postgres_service: "Any") -> None:
6259

6360
spec = SQLSpec()
6461
spec.add_config(config)
65-
channel = cast("AsyncEventChannel", spec.event_channel(config))
62+
channel = spec.event_channel(config)
6663

6764
received: list[Any] = []
6865

@@ -101,7 +98,7 @@ def test_psycopg_sync_hybrid_listen_notify_durable(postgres_service: "Any", tmp_
10198

10299
spec = SQLSpec()
103100
spec.add_config(config)
104-
channel = cast("SyncEventChannel", spec.event_channel(config))
101+
channel = spec.event_channel(config)
105102

106103
received: list[Any] = []
107104
listener = channel.listen("alerts", lambda message: received.append(message), poll_interval=0.2)
@@ -137,7 +134,7 @@ async def test_psycopg_async_hybrid_listen_notify_durable(postgres_service: "Any
137134

138135
spec = SQLSpec()
139136
spec.add_config(config)
140-
channel = cast("AsyncEventChannel", spec.event_channel(config))
137+
channel = spec.event_channel(config)
141138

142139
received: list[Any] = []
143140

tests/integration/test_adapters/test_spanner/test_extensions/test_events/test_events.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
"""Integration tests for Spanner EventChannel queue backend."""
22

3-
from typing import TYPE_CHECKING, cast
4-
53
import pytest
64

75
from sqlspec import SQLSpec
86
from sqlspec.adapters.spanner import SpannerSyncConfig
97
from sqlspec.adapters.spanner.events import SpannerSyncEventQueueStore
108

11-
if TYPE_CHECKING:
12-
from sqlspec.extensions.events import SyncEventChannel
13-
149
pytestmark = [pytest.mark.spanner, pytest.mark.integration]
1510

1611

@@ -20,7 +15,7 @@ def test_spanner_event_channel_queue_fallback(
2015
"""Queue-backed events work on Spanner via the table queue backend."""
2116
spec = SQLSpec()
2217
spec.add_config(spanner_events_config)
23-
channel = cast("SyncEventChannel", spec.event_channel(spanner_events_config))
18+
channel = spec.event_channel(spanner_events_config)
2419

2520
event_id = channel.publish("notifications", {"action": "spanner_event"})
2621

@@ -88,7 +83,7 @@ def test_spanner_event_metadata_roundtrip(
8883
"""Events with metadata are correctly stored and retrieved."""
8984
spec = SQLSpec()
9085
spec.add_config(spanner_events_config)
91-
channel = cast("SyncEventChannel", spec.event_channel(spanner_events_config))
86+
channel = spec.event_channel(spanner_events_config)
9287

9388
metadata = {"source": "test", "priority": 1}
9489
event_id = channel.publish("metadata_test", {"data": "value"}, metadata=metadata)

0 commit comments

Comments
 (0)