mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Allow iteration in python_script (#8134)
* Allow iteration in python_script * Add tests
This commit is contained in:
parent
4d2b79156d
commit
6398e92836
@ -92,6 +92,7 @@ def execute(hass, filename, source, data=None):
|
|||||||
'_print_': StubPrinter,
|
'_print_': StubPrinter,
|
||||||
'_getattr_': protected_getattr,
|
'_getattr_': protected_getattr,
|
||||||
'_write_': full_write_guard,
|
'_write_': full_write_guard,
|
||||||
|
'_getiter_': iter,
|
||||||
}
|
}
|
||||||
logger = logging.getLogger('{}.{}'.format(__name__, filename))
|
logger = logging.getLogger('{}.{}'.format(__name__, filename))
|
||||||
local = {
|
local = {
|
||||||
|
@ -149,3 +149,18 @@ hass.stop()
|
|||||||
yield from hass.async_block_till_done()
|
yield from hass.async_block_till_done()
|
||||||
|
|
||||||
assert "Not allowed to access HomeAssistant.stop" in caplog.text
|
assert "Not allowed to access HomeAssistant.stop" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def test_iterating(hass):
|
||||||
|
"""Test compile error logs error."""
|
||||||
|
source = """
|
||||||
|
for i in [1, 2]:
|
||||||
|
hass.states.set('hello.{}'.format(i), 'world')
|
||||||
|
"""
|
||||||
|
|
||||||
|
hass.async_add_job(execute, hass, 'test.py', source, {})
|
||||||
|
yield from hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert hass.states.is_state('hello.1', 'world')
|
||||||
|
assert hass.states.is_state('hello.2', 'world')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user