Skip to content

Commit e5588a0

Browse files
committed
added more tests
1 parent c6244a7 commit e5588a0

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

custom_components/pyscript/function.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ def init(cls, hass):
6969
}
7070
)
7171

72-
@classmethod
73-
async def entity_ids(cls, domain=None):
74-
"""Implement entity_ids."""
75-
return cls.hass.states.async_entity_ids(domain)
76-
7772
@classmethod
7873
async def async_sleep(cls, duration):
7974
"""Implement task.sleep()."""
@@ -196,8 +191,6 @@ def get(cls, name):
196191
async def service_call(*args, **kwargs):
197192
await cls.hass.services.async_call(domain, service, kwargs)
198193

199-
# service_call = functools.partial(cls.service_call, domain, service)
200-
201194
return service_call
202195

203196
@classmethod

tests/test_init.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
import pathlib
66

77
from custom_components.pyscript.const import DOMAIN
8+
from custom_components.pyscript.event import Event
9+
from custom_components.pyscript.function import Function
10+
from custom_components.pyscript.global_ctx import GlobalContextMgr
11+
from custom_components.pyscript.state import State
812
import custom_components.pyscript.trigger as trigger
913
from pytest_homeassistant.async_mock import mock_open, patch
1014

@@ -285,7 +289,11 @@ def func2(**kwargs):
285289
286290
@service
287291
def call_service(domain=None, name=None, **kwargs):
288-
service.call(domain, name, **kwargs)
292+
if domain == "pyscript" and name == "func1":
293+
task.sleep(0)
294+
pyscript.func1(**kwargs)
295+
else:
296+
service.call(domain, name, **kwargs)
289297
290298
""",
291299
)
@@ -447,3 +455,22 @@ def func5(var_name=None, value=None):
447455
"custom_components.pyscript.trigger.dt_now", return_value=now
448456
):
449457
await hass.services.async_call("pyscript", "reload", {}, blocking=True)
458+
459+
460+
async def test_misc_errors(hass, caplog):
461+
"""Test miscellaneous errors."""
462+
463+
await setup_script(hass, None, dt(2020, 7, 1, 11, 59, 59, 999999), "")
464+
465+
Function()
466+
GlobalContextMgr()
467+
State()
468+
Event()
469+
Event.notify_del("not_in_notify_list", None)
470+
trigger.TrigTime()
471+
472+
assert "Function class is not meant to be instantiated" in caplog.text
473+
assert "GlobalContextMgr class is not meant to be instantiated" in caplog.text
474+
assert "State class is not meant to be instantiated" in caplog.text
475+
assert "Event class is not meant to be instantiated" in caplog.text
476+
assert "TrigTime class is not meant to be instantiated" in caplog.text

tests/test_jupyter.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,4 +506,12 @@ async def test_jupyter_kernel_no_connection_timeout(hass, caplog):
506506
"""Test Jupyter kernel timeout on no connection."""
507507
sock, port_nums = await setup_script(hass, [dt(2020, 7, 1, 11, 0, 0, 0)], "", no_connect=True)
508508

509-
assert "No connections to session " in caplog.text
509+
#
510+
# There is a race condition waiting for the log message, so we need to poll
511+
#
512+
for _ in range(50):
513+
if "No connections to session jupyter_" in caplog.text:
514+
break
515+
await asyncio.sleep(2e-3)
516+
517+
assert "No connections to session jupyter_" in caplog.text

tests/test_unique.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ def func5():
131131
res = task.wait_until(state_trigger="pyscript.f5var2 == '1'")
132132
pyscript.done = [seq_num, "pyscript.f5var2"]
133133
134+
135+
@time_trigger("startup")
136+
def func6():
137+
task.unique("func6")
138+
task.unique("func6", kill_me=True)
139+
# mess up the sequence numbers if task.unique fails to kill us
140+
pyscript.done = [999]
141+
134142
""",
135143
)
136144

tests/test_unit_eval.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@ async def test_eval(hass):
757757
["continue", "Exception in test line 1 column 0: continue statement outside loop"],
758758
["raise", "Exception in test line 1 column 0: No active exception to reraise"],
759759
["yield", "Exception in test line 1 column 0: test: not implemented ast ast_yield"],
760+
["task.executor(5)", "Exception in test line 1 column 14: function is not callable by task.executor()"],
760761
[
761762
"import cmath; exec('xyz = cmath.sqrt(complex(3, 4))', {})",
762763
"Exception in test line 1 column 54: Exception in exec() line 1 column 28: 'sqrt' is not callable (got None)",

0 commit comments

Comments
 (0)