Update python_script tests to use async_add_executor_job (#41553)
This commit is contained in:
parent
49e5b665cf
commit
3bb0e00abe
1 changed files with 14 additions and 14 deletions
|
@ -60,7 +60,7 @@ async def test_execute_with_data(hass, caplog):
|
||||||
hass.states.set('test.entity', data.get('name', 'not set'))
|
hass.states.set('test.entity', data.get('name', 'not set'))
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {"name": "paulus"})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {"name": "paulus"})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.is_state("test.entity", "paulus")
|
assert hass.states.is_state("test.entity", "paulus")
|
||||||
|
@ -76,7 +76,7 @@ async def test_execute_warns_print(hass, caplog):
|
||||||
print("This triggers warning.")
|
print("This triggers warning.")
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert "Don't use print() inside scripts." in caplog.text
|
assert "Don't use print() inside scripts." in caplog.text
|
||||||
|
@ -89,7 +89,7 @@ async def test_execute_logging(hass, caplog):
|
||||||
logger.info('Logging from inside script')
|
logger.info('Logging from inside script')
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert "Logging from inside script" in caplog.text
|
assert "Logging from inside script" in caplog.text
|
||||||
|
@ -102,7 +102,7 @@ async def test_execute_compile_error(hass, caplog):
|
||||||
this is not valid Python
|
this is not valid Python
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert "Error loading script test.py" in caplog.text
|
assert "Error loading script test.py" in caplog.text
|
||||||
|
@ -115,7 +115,7 @@ async def test_execute_runtime_error(hass, caplog):
|
||||||
raise Exception('boom')
|
raise Exception('boom')
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert "Error executing script: boom" in caplog.text
|
assert "Error executing script: boom" in caplog.text
|
||||||
|
@ -128,7 +128,7 @@ async def test_accessing_async_methods(hass, caplog):
|
||||||
hass.async_stop()
|
hass.async_stop()
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert "Not allowed to access async methods" in caplog.text
|
assert "Not allowed to access async methods" in caplog.text
|
||||||
|
@ -143,7 +143,7 @@ mylist = [1, 2, 3, 4]
|
||||||
logger.info('Logging from inside script: %s %s' % (mydict["a"], mylist[2]))
|
logger.info('Logging from inside script: %s %s' % (mydict["a"], mylist[2]))
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert "Logging from inside script: 1 3" in caplog.text
|
assert "Logging from inside script: 1 3" in caplog.text
|
||||||
|
@ -160,7 +160,7 @@ async def test_accessing_forbidden_methods(hass, caplog):
|
||||||
"time.tzset()": "TimeWrapper.tzset",
|
"time.tzset()": "TimeWrapper.tzset",
|
||||||
}.items():
|
}.items():
|
||||||
caplog.records.clear()
|
caplog.records.clear()
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert f"Not allowed to access {name}" in caplog.text
|
assert f"Not allowed to access {name}" in caplog.text
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ for i in [1, 2]:
|
||||||
hass.states.set('hello.{}'.format(i), 'world')
|
hass.states.set('hello.{}'.format(i), 'world')
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.is_state("hello.1", "world")
|
assert hass.states.is_state("hello.1", "world")
|
||||||
|
@ -190,7 +190,7 @@ hass.states.set('hello.b', b)
|
||||||
hass.states.set('hello.ab_list', '{}'.format(ab_list))
|
hass.states.set('hello.ab_list', '{}'.format(ab_list))
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.is_state("hello.a", "1")
|
assert hass.states.is_state("hello.a", "1")
|
||||||
|
@ -211,7 +211,7 @@ hass.states.set('hello.a', a[0])
|
||||||
hass.states.set('hello.b', a[1])
|
hass.states.set('hello.b', a[1])
|
||||||
hass.states.set('hello.c', a[2])
|
hass.states.set('hello.c', a[2])
|
||||||
"""
|
"""
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.is_state("hello.a", "1")
|
assert hass.states.is_state("hello.a", "1")
|
||||||
|
@ -232,7 +232,7 @@ hass.states.set('module.datetime',
|
||||||
datetime.timedelta(minutes=1).total_seconds())
|
datetime.timedelta(minutes=1).total_seconds())
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.is_state("module.time", "1986")
|
assert hass.states.is_state("module.time", "1986")
|
||||||
|
@ -256,7 +256,7 @@ def b():
|
||||||
|
|
||||||
b()
|
b()
|
||||||
"""
|
"""
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.is_state("hello.a", "one")
|
assert hass.states.is_state("hello.a", "one")
|
||||||
|
@ -400,7 +400,7 @@ time.sleep(5)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with patch("homeassistant.components.python_script.time.sleep"):
|
with patch("homeassistant.components.python_script.time.sleep"):
|
||||||
hass.async_add_job(execute, hass, "test.py", source, {})
|
hass.async_add_executor_job(execute, hass, "test.py", source, {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert caplog.text.count("time.sleep") == 1
|
assert caplog.text.count("time.sleep") == 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue