Added sorted() to python_script (#10621)
* added sorted() to python_script * fixed lint errorspull/10631/head
parent
24aeea5ca3
commit
f052a0926b
|
@ -140,6 +140,7 @@ def execute(hass, filename, source, data=None):
|
||||||
builtins = safe_builtins.copy()
|
builtins = safe_builtins.copy()
|
||||||
builtins.update(utility_builtins)
|
builtins.update(utility_builtins)
|
||||||
builtins['datetime'] = datetime
|
builtins['datetime'] = datetime
|
||||||
|
builtins['sorted'] = sorted
|
||||||
builtins['time'] = TimeWrapper()
|
builtins['time'] = TimeWrapper()
|
||||||
builtins['dt_util'] = dt_util
|
builtins['dt_util'] = dt_util
|
||||||
restricted_globals = {
|
restricted_globals = {
|
||||||
|
|
|
@ -209,6 +209,27 @@ hass.states.set('hello.ab_list', '{}'.format(ab_list))
|
||||||
assert caplog.text == ''
|
assert caplog.text == ''
|
||||||
|
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def test_execute_sorted(hass, caplog):
|
||||||
|
"""Test sorted() function."""
|
||||||
|
caplog.set_level(logging.ERROR)
|
||||||
|
source = """
|
||||||
|
a = sorted([3,1,2])
|
||||||
|
assert(a == [1,2,3])
|
||||||
|
hass.states.set('hello.a', a[0])
|
||||||
|
hass.states.set('hello.b', a[1])
|
||||||
|
hass.states.set('hello.c', a[2])
|
||||||
|
"""
|
||||||
|
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.c', '3')
|
||||||
|
# No errors logged = good
|
||||||
|
assert caplog.text == ''
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def test_exposed_modules(hass, caplog):
|
def test_exposed_modules(hass, caplog):
|
||||||
"""Test datetime and time modules exposed."""
|
"""Test datetime and time modules exposed."""
|
||||||
|
|
Loading…
Reference in New Issue