Skip to content

Commit 5949489

Browse files
committed
Make core tests that should run in the event loop coros
#111425 (comment)
1 parent d812507 commit 5949489

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

tests/test_core.py

+18-24
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_split_entity_id() -> None:
8585
ha.split_entity_id(".empty_domain")
8686

8787

88-
def test_async_add_hass_job_schedule_callback() -> None:
88+
async def test_async_add_hass_job_schedule_callback() -> None:
8989
"""Test that we schedule callbacks and add jobs to the job pool."""
9090
hass = MagicMock()
9191
job = MagicMock()
@@ -96,7 +96,7 @@ def test_async_add_hass_job_schedule_callback() -> None:
9696
assert len(hass.add_job.mock_calls) == 0
9797

9898

99-
def test_async_add_hass_job_coro_named(hass: HomeAssistant) -> None:
99+
async def test_async_add_hass_job_coro_named(hass: HomeAssistant) -> None:
100100
"""Test that we schedule coroutines and add jobs to the job pool with a name."""
101101

102102
async def mycoro():
@@ -109,7 +109,7 @@ async def mycoro():
109109
assert "named coro" in str(task)
110110

111111

112-
def test_async_add_hass_job_schedule_partial_callback() -> None:
112+
async def test_async_add_hass_job_schedule_partial_callback() -> None:
113113
"""Test that we schedule partial coros and add jobs to the job pool."""
114114
hass = MagicMock()
115115
job = MagicMock()
@@ -121,9 +121,9 @@ def test_async_add_hass_job_schedule_partial_callback() -> None:
121121
assert len(hass.add_job.mock_calls) == 0
122122

123123

124-
def test_async_add_hass_job_schedule_coroutinefunction(event_loop) -> None:
124+
async def test_async_add_hass_job_schedule_coroutinefunction() -> None:
125125
"""Test that we schedule coroutines and add jobs to the job pool."""
126-
hass = MagicMock(loop=MagicMock(wraps=event_loop))
126+
hass = MagicMock(loop=MagicMock(wraps=asyncio.get_running_loop()))
127127

128128
async def job():
129129
pass
@@ -134,9 +134,9 @@ async def job():
134134
assert len(hass.add_job.mock_calls) == 0
135135

136136

137-
def test_async_add_hass_job_schedule_partial_coroutinefunction(event_loop) -> None:
137+
async def test_async_add_hass_job_schedule_partial_coroutinefunction() -> None:
138138
"""Test that we schedule partial coros and add jobs to the job pool."""
139-
hass = MagicMock(loop=MagicMock(wraps=event_loop))
139+
hass = MagicMock(loop=MagicMock(wraps=asyncio.get_running_loop()))
140140

141141
async def job():
142142
pass
@@ -149,7 +149,7 @@ async def job():
149149
assert len(hass.add_job.mock_calls) == 0
150150

151151

152-
def test_async_add_job_add_hass_threaded_job_to_pool() -> None:
152+
async def test_async_add_job_add_hass_threaded_job_to_pool() -> None:
153153
"""Test that we schedule coroutines and add jobs to the job pool."""
154154
hass = MagicMock()
155155

@@ -162,11 +162,9 @@ def job():
162162
assert len(hass.loop.run_in_executor.mock_calls) == 2
163163

164164

165-
def test_async_create_task_schedule_coroutine(
166-
event_loop: asyncio.AbstractEventLoop,
167-
) -> None:
165+
async def test_async_create_task_schedule_coroutine() -> None:
168166
"""Test that we schedule coroutines and add jobs to the job pool."""
169-
hass = MagicMock(loop=MagicMock(wraps=event_loop))
167+
hass = MagicMock(loop=MagicMock(wraps=asyncio.get_running_loop()))
170168

171169
async def job():
172170
pass
@@ -180,11 +178,9 @@ async def job():
180178
@pytest.mark.skipif(
181179
sys.version_info < (3, 12), reason="eager_start is only supported for Python 3.12"
182180
)
183-
def test_async_create_task_eager_start_schedule_coroutine(
184-
event_loop: asyncio.AbstractEventLoop,
185-
) -> None:
181+
async def test_async_create_task_eager_start_schedule_coroutine() -> None:
186182
"""Test that we schedule coroutines and add jobs to the job pool."""
187-
hass = MagicMock(loop=MagicMock(wraps=event_loop))
183+
hass = MagicMock(loop=MagicMock(wraps=asyncio.get_running_loop()))
188184

189185
async def job():
190186
pass
@@ -198,11 +194,9 @@ async def job():
198194
@pytest.mark.skipif(
199195
sys.version_info >= (3, 12), reason="eager_start is not supported on < 3.12"
200196
)
201-
def test_async_create_task_eager_start_fallback_schedule_coroutine(
202-
event_loop: asyncio.AbstractEventLoop,
203-
) -> None:
197+
async def test_async_create_task_eager_start_fallback_schedule_coroutine() -> None:
204198
"""Test that we schedule coroutines and add jobs to the job pool."""
205-
hass = MagicMock(loop=MagicMock(wraps=event_loop))
199+
hass = MagicMock(loop=MagicMock(wraps=asyncio.get_running_loop()))
206200

207201
async def job():
208202
pass
@@ -215,9 +209,9 @@ async def job():
215209
assert len(hass.add_job.mock_calls) == 0
216210

217211

218-
def test_async_create_task_schedule_coroutine_with_name(event_loop) -> None:
212+
async def test_async_create_task_schedule_coroutine_with_name() -> None:
219213
"""Test that we schedule coroutines and add jobs to the job pool with a name."""
220-
hass = MagicMock(loop=MagicMock(wraps=event_loop))
214+
hass = MagicMock(loop=MagicMock(wraps=asyncio.get_running_loop()))
221215

222216
async def job():
223217
pass
@@ -229,7 +223,7 @@ async def job():
229223
assert "named task" in str(task)
230224

231225

232-
def test_async_run_hass_job_calls_callback() -> None:
226+
async def test_async_run_hass_job_calls_callback() -> None:
233227
"""Test that the callback annotation is respected."""
234228
hass = MagicMock()
235229
calls = []
@@ -242,7 +236,7 @@ def job():
242236
assert len(hass.async_add_job.mock_calls) == 0
243237

244238

245-
def test_async_run_hass_job_delegates_non_async() -> None:
239+
async def test_async_run_hass_job_delegates_non_async() -> None:
246240
"""Test that the callback annotation is respected."""
247241
hass = MagicMock()
248242
calls = []

0 commit comments

Comments
 (0)