Skip to content

Commit 3bb0e00

Browse files
authored
Update python_script tests to use async_add_executor_job (home-assistant#41553)
1 parent 49e5b66 commit 3bb0e00

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

tests/components/python_script/test_init.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async def test_execute_with_data(hass, caplog):
6060
hass.states.set('test.entity', data.get('name', 'not set'))
6161
"""
6262

63-
hass.async_add_job(execute, hass, "test.py", source, {"name": "paulus"})
63+
hass.async_add_executor_job(execute, hass, "test.py", source, {"name": "paulus"})
6464
await hass.async_block_till_done()
6565

6666
assert hass.states.is_state("test.entity", "paulus")
@@ -76,7 +76,7 @@ async def test_execute_warns_print(hass, caplog):
7676
print("This triggers warning.")
7777
"""
7878

79-
hass.async_add_job(execute, hass, "test.py", source, {})
79+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
8080
await hass.async_block_till_done()
8181

8282
assert "Don't use print() inside scripts." in caplog.text
@@ -89,7 +89,7 @@ async def test_execute_logging(hass, caplog):
8989
logger.info('Logging from inside script')
9090
"""
9191

92-
hass.async_add_job(execute, hass, "test.py", source, {})
92+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
9393
await hass.async_block_till_done()
9494

9595
assert "Logging from inside script" in caplog.text
@@ -102,7 +102,7 @@ async def test_execute_compile_error(hass, caplog):
102102
this is not valid Python
103103
"""
104104

105-
hass.async_add_job(execute, hass, "test.py", source, {})
105+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
106106
await hass.async_block_till_done()
107107

108108
assert "Error loading script test.py" in caplog.text
@@ -115,7 +115,7 @@ async def test_execute_runtime_error(hass, caplog):
115115
raise Exception('boom')
116116
"""
117117

118-
hass.async_add_job(execute, hass, "test.py", source, {})
118+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
119119
await hass.async_block_till_done()
120120

121121
assert "Error executing script: boom" in caplog.text
@@ -128,7 +128,7 @@ async def test_accessing_async_methods(hass, caplog):
128128
hass.async_stop()
129129
"""
130130

131-
hass.async_add_job(execute, hass, "test.py", source, {})
131+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
132132
await hass.async_block_till_done()
133133

134134
assert "Not allowed to access async methods" in caplog.text
@@ -143,7 +143,7 @@ async def test_using_complex_structures(hass, caplog):
143143
logger.info('Logging from inside script: %s %s' % (mydict["a"], mylist[2]))
144144
"""
145145

146-
hass.async_add_job(execute, hass, "test.py", source, {})
146+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
147147
await hass.async_block_till_done()
148148

149149
assert "Logging from inside script: 1 3" in caplog.text
@@ -160,7 +160,7 @@ async def test_accessing_forbidden_methods(hass, caplog):
160160
"time.tzset()": "TimeWrapper.tzset",
161161
}.items():
162162
caplog.records.clear()
163-
hass.async_add_job(execute, hass, "test.py", source, {})
163+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
164164
await hass.async_block_till_done()
165165
assert f"Not allowed to access {name}" in caplog.text
166166

@@ -172,7 +172,7 @@ async def test_iterating(hass):
172172
hass.states.set('hello.{}'.format(i), 'world')
173173
"""
174174

175-
hass.async_add_job(execute, hass, "test.py", source, {})
175+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
176176
await hass.async_block_till_done()
177177

178178
assert hass.states.is_state("hello.1", "world")
@@ -190,7 +190,7 @@ async def test_unpacking_sequence(hass, caplog):
190190
hass.states.set('hello.ab_list', '{}'.format(ab_list))
191191
"""
192192

193-
hass.async_add_job(execute, hass, "test.py", source, {})
193+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
194194
await hass.async_block_till_done()
195195

196196
assert hass.states.is_state("hello.a", "1")
@@ -211,7 +211,7 @@ async def test_execute_sorted(hass, caplog):
211211
hass.states.set('hello.b', a[1])
212212
hass.states.set('hello.c', a[2])
213213
"""
214-
hass.async_add_job(execute, hass, "test.py", source, {})
214+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
215215
await hass.async_block_till_done()
216216

217217
assert hass.states.is_state("hello.a", "1")
@@ -232,7 +232,7 @@ async def test_exposed_modules(hass, caplog):
232232
datetime.timedelta(minutes=1).total_seconds())
233233
"""
234234

235-
hass.async_add_job(execute, hass, "test.py", source, {})
235+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
236236
await hass.async_block_till_done()
237237

238238
assert hass.states.is_state("module.time", "1986")
@@ -256,7 +256,7 @@ def b():
256256
257257
b()
258258
"""
259-
hass.async_add_job(execute, hass, "test.py", source, {})
259+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
260260
await hass.async_block_till_done()
261261

262262
assert hass.states.is_state("hello.a", "one")
@@ -400,7 +400,7 @@ async def test_sleep_warns_one(hass, caplog):
400400
"""
401401

402402
with patch("homeassistant.components.python_script.time.sleep"):
403-
hass.async_add_job(execute, hass, "test.py", source, {})
403+
hass.async_add_executor_job(execute, hass, "test.py", source, {})
404404
await hass.async_block_till_done()
405405

406406
assert caplog.text.count("time.sleep") == 1

0 commit comments

Comments
 (0)