Skip to content

Commit 88eebeb

Browse files
committed
update tests for 2023.7 - no limit arg on service calls
1 parent bd45610 commit 88eebeb

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

custom_components/pyscript/function.py

-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ async def service_call(cls, domain, name, **kwargs):
325325
("context", [Context], cls.task2context.get(curr_task, None)),
326326
("blocking", [bool], None),
327327
("return_response", [bool], None),
328-
("limit", [float, int], None),
329328
]:
330329
if keyword in kwargs and type(kwargs[keyword]) in typ:
331330
hass_args[keyword] = kwargs.pop(keyword)
@@ -396,7 +395,6 @@ async def service_call(*args, **kwargs):
396395
("context", [Context], cls.task2context.get(curr_task, None)),
397396
("blocking", [bool], None),
398397
("return_response", [bool], None),
399-
("limit", [float, int], None),
400398
]:
401399
if keyword in kwargs and type(kwargs[keyword]) in typ:
402400
hass_args[keyword] = kwargs.pop(keyword)

tests/requirements_test.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ mypy==1.3.0
66
pre-commit==3.2.1
77
pytest==7.3.1
88
pytest-cov==3.0.0
9-
pytest-homeassistant-custom-component==0.13.34
9+
pytest-homeassistant-custom-component==0.13.45
1010
pylint==2.17.4
1111
pylint-strict-informational==0.1

tests/test_function.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -1216,14 +1216,18 @@ async def test_service_call_params(hass):
12161216
"""Test that hass params get set properly on service calls."""
12171217
with patch.object(hass.services, "async_call") as call, patch.object(
12181218
Function, "service_has_service", return_value=True
1219+
), patch.object(
1220+
hass.services,
1221+
"supports_response",
1222+
return_value="none",
12191223
):
12201224
Function.init(hass)
12211225
await Function.service_call(
1222-
"test", "test", context=Context(id="test"), blocking=True, limit=1, other_service_data="test"
1226+
"test", "test", context=Context(id="test"), blocking=True, other_service_data="test"
12231227
)
12241228
assert call.called
12251229
assert call.call_args[0] == ("test", "test", {"other_service_data": "test"})
1226-
assert call.call_args[1] == {"context": Context(id="test"), "blocking": True, "limit": 1}
1230+
assert call.call_args[1] == {"context": Context(id="test"), "blocking": True}
12271231
call.reset_mock()
12281232

12291233
await Function.service_call(
@@ -1234,12 +1238,10 @@ async def test_service_call_params(hass):
12341238
assert call.call_args[1] == {"context": Context(id="test"), "blocking": False}
12351239
call.reset_mock()
12361240

1237-
await Function.get("test.test")(
1238-
context=Context(id="test"), blocking=True, limit=1, other_service_data="test"
1239-
)
1241+
await Function.get("test.test")(context=Context(id="test"), blocking=True, other_service_data="test")
12401242
assert call.called
12411243
assert call.call_args[0] == ("test", "test", {"other_service_data": "test"})
1242-
assert call.call_args[1] == {"context": Context(id="test"), "blocking": True, "limit": 1}
1244+
assert call.call_args[1] == {"context": Context(id="test"), "blocking": True}
12431245
call.reset_mock()
12441246

12451247
await Function.get("test.test")(
@@ -1285,20 +1287,19 @@ def func_startup():
12851287
pyscript.done = [seq_num, pyscript.var1]
12861288
12871289
seq_num += 1
1288-
pyscript.var1 = int(pyscript.var1) + 1
1289-
service.call("pyscript", "long_sleep", blocking=True, limit=1e-6)
1290+
service.call("pyscript", "short_sleep", blocking=True)
12901291
pyscript.done = [seq_num, pyscript.var1]
12911292
1292-
task.cancel(long_sleep_id)
12931293
seq_num += 1
12941294
pyscript.done = [seq_num]
12951295
12961296
@service
1297-
def long_sleep():
1297+
def short_sleep():
12981298
global long_sleep_id
12991299
13001300
long_sleep_id = task.current_task()
1301-
task.sleep(10000)
1301+
task.sleep(0.0001)
1302+
pyscript.var1 = int(pyscript.var1) + 1
13021303
13031304
@service
13041305
def service1():

tests/test_reload.py

+2
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ def shutdown(trigger_time=None):
289289
)
290290
if i < 2:
291291
await hass.services.async_call("pyscript", "reload", {"global_ctx": "*"}, blocking=True)
292+
while caplog.text.count("world is starting up") < 3 + i:
293+
await asyncio.sleep(0.001)
292294

293295
#
294296
# make sure files that shouldn't load were not loaded

0 commit comments

Comments
 (0)