1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-23 12:29:55 +00:00

Improve Python script (#9417)

* add datetime and support for unpacksequence

add datetime to builtin and support for unpacksequence
a,b = (1,2)
for a,b in [(1,2),(3,4)]

* add test for python_script

* fix test

* restore previous test

restore previous tests, removed by mistake sorry...

* fix test

* Update test_python_script.py

* fix travis

* fix test

* Update test_python_script.py

* Add files via upload

* fix travis...
This commit is contained in:
Sébastien RAMAGE
2017-09-14 16:52:47 +02:00
committed by Paulus Schoutsen
parent 371d1cc872
commit 20f3e3dcf9
2 changed files with 30 additions and 2 deletions

View File

@@ -180,3 +180,26 @@ for i in [1, 2]:
assert hass.states.is_state('hello.1', 'world')
assert hass.states.is_state('hello.2', 'world')
@asyncio.coroutine
def test_unpacking_sequence(hass, caplog):
"""Test compile error logs error."""
caplog.set_level(logging.ERROR)
source = """
a,b = (1,2)
ab_list = [(a,b) for a,b in [(1, 2), (3, 4)]]
hass.states.set('hello.a', a)
hass.states.set('hello.b', b)
hass.states.set('hello.ab_list', '{}'.format(ab_list))
"""
hass.async_add_job(execute, hass, 'test.py', source, {})
yield from hass.async_block_till_done()
assert hass.states.is_state('hello.a', '1')
assert hass.states.is_state('hello.b', '2')
assert hass.states.is_state('hello.ab_list', '[(1, 2), (3, 4)]')
# No errors logged = good
assert caplog.text == ''