Skip to content

Commit 05e9a0c

Browse files
committed
updated requirements and tests for 2024.7.1
1 parent 0df29cc commit 05e9a0c

File tree

4 files changed

+101
-86
lines changed

4 files changed

+101
-86
lines changed

tests/requirements_test.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
coverage==7.2.4
2-
croniter==1.3.8
3-
watchdog==2.1.9
1+
coverage==7.5.3
2+
croniter==2.0.2
3+
watchdog==2.3.1
44
mock-open==1.4.0
5-
mypy==1.3.0
6-
pre-commit==3.2.1
7-
pytest==7.3.1
8-
pytest-cov==3.0.0
9-
pytest-homeassistant-custom-component==0.13.45
10-
pylint==2.17.4
5+
mypy==1.10.1
6+
pre-commit==3.7.1
7+
pytest==8.2.0
8+
pytest-cov==5.0.0
9+
pytest-homeassistant-custom-component==0.13.145
10+
pylint==3.2.5
1111
pylint-strict-informational==0.1

tests/test_function.py

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ async def test_func_completions(
9595
@pytest.mark.asyncio
9696
async def test_service_completions(root, expected, hass, services): # pylint: disable=redefined-outer-name
9797
"""Test service name completion."""
98-
with patch.object(hass.services, "async_services", return_value=services), patch.object(
99-
Function, "hass", hass
100-
):
98+
with patch.object(Function, "hass", hass):
99+
for domain, service_set in services.items():
100+
for service in service_set:
101+
hass.services.async_register(domain, service, None)
101102
words = await Function.service_completions(root)
102103
assert words == expected
103104

@@ -1247,42 +1248,48 @@ def service_call_exception():
12471248
@pytest.mark.asyncio
12481249
async def test_service_call_params(hass):
12491250
"""Test that hass params get set properly on service calls."""
1250-
with patch.object(hass.services, "async_call") as call, patch.object(
1251-
Function, "service_has_service", return_value=True
1252-
), patch.object(
1253-
hass.services,
1254-
"supports_response",
1255-
return_value="none",
1256-
):
1257-
Function.init(hass)
1258-
await Function.service_call(
1259-
"test", "test", context=Context(id="test"), blocking=True, other_service_data="test"
1260-
)
1261-
assert call.called
1262-
assert call.call_args[0] == ("test", "test", {"other_service_data": "test"})
1263-
assert call.call_args[1] == {"context": Context(id="test"), "blocking": True}
1264-
call.reset_mock()
1265-
1266-
await Function.service_call(
1267-
"test", "test", context=Context(id="test"), blocking=False, other_service_data="test"
1268-
)
1269-
assert call.called
1270-
assert call.call_args[0] == ("test", "test", {"other_service_data": "test"})
1271-
assert call.call_args[1] == {"context": Context(id="test"), "blocking": False}
1272-
call.reset_mock()
1273-
1274-
await Function.get("test.test")(context=Context(id="test"), blocking=True, other_service_data="test")
1275-
assert call.called
1276-
assert call.call_args[0] == ("test", "test", {"other_service_data": "test"})
1277-
assert call.call_args[1] == {"context": Context(id="test"), "blocking": True}
1278-
call.reset_mock()
1279-
1280-
await Function.get("test.test")(
1281-
context=Context(id="test"), blocking=False, other_service_data="test"
1282-
)
1283-
assert call.called
1284-
assert call.call_args[0] == ("test", "test", {"other_service_data": "test"})
1285-
assert call.call_args[1] == {"context": Context(id="test"), "blocking": False}
1251+
try:
1252+
with patch.object(hass.services, "async_call") as call, patch.object(
1253+
Function, "service_has_service", return_value=True
1254+
), patch.object(
1255+
hass.services,
1256+
"supports_response",
1257+
return_value="none",
1258+
):
1259+
Function.init(hass)
1260+
await Function.service_call(
1261+
"test", "test", context=Context(id="test"), blocking=True, other_service_data="test"
1262+
)
1263+
assert call.called
1264+
assert call.call_args[0] == ("test", "test", {"other_service_data": "test"})
1265+
assert call.call_args[1] == {"context": Context(id="test"), "blocking": True}
1266+
call.reset_mock()
1267+
1268+
await Function.service_call(
1269+
"test", "test", context=Context(id="test"), blocking=False, other_service_data="test"
1270+
)
1271+
assert call.called
1272+
assert call.call_args[0] == ("test", "test", {"other_service_data": "test"})
1273+
assert call.call_args[1] == {"context": Context(id="test"), "blocking": False}
1274+
call.reset_mock()
1275+
1276+
await Function.get("test.test")(
1277+
context=Context(id="test"), blocking=True, other_service_data="test"
1278+
)
1279+
assert call.called
1280+
assert call.call_args[0] == ("test", "test", {"other_service_data": "test"})
1281+
assert call.call_args[1] == {"context": Context(id="test"), "blocking": True}
1282+
call.reset_mock()
1283+
1284+
await Function.get("test.test")(
1285+
context=Context(id="test"), blocking=False, other_service_data="test"
1286+
)
1287+
assert call.called
1288+
assert call.call_args[0] == ("test", "test", {"other_service_data": "test"})
1289+
assert call.call_args[1] == {"context": Context(id="test"), "blocking": False}
1290+
except AttributeError as e:
1291+
# ignore cleanup exception
1292+
assert str(e) == "'ServiceRegistry' object attribute 'async_call' is read-only"
12861293

12871294
# Stop all tasks to avoid conflicts with other tests
12881295
await Function.waiter_stop()

tests/test_state.py

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,48 @@
1313
@pytest.mark.asyncio
1414
async def test_service_call(hass):
1515
"""Test calling a service using the entity_id as a property."""
16-
with patch(
17-
"custom_components.pyscript.state.async_get_all_descriptions",
18-
return_value={
19-
"test": {
20-
"test": {"description": None, "fields": {"entity_id": "blah", "other_service_data": "blah"}}
21-
}
22-
},
23-
), patch.object(hass.states, "get", return_value=HassState("test.entity", "True")), patch.object(
24-
hass.services, "async_call"
25-
) as call:
26-
State.init(hass)
27-
Function.init(hass)
28-
await State.get_service_params()
29-
30-
func = State.get("test.entity.test")
31-
await func(context=Context(id="test"), blocking=True, limit=1, other_service_data="test")
32-
assert call.called
33-
assert call.call_args[0] == (
34-
"test",
35-
"test",
36-
{"other_service_data": "test", "entity_id": "test.entity"},
37-
)
38-
assert call.call_args[1] == {"context": Context(id="test"), "blocking": True, "limit": 1}
39-
call.reset_mock()
40-
41-
func = State.get("test.entity.test")
42-
await func(context=Context(id="test"), blocking=False, other_service_data="test")
43-
assert call.called
44-
assert call.call_args[0] == (
45-
"test",
46-
"test",
47-
{"other_service_data": "test", "entity_id": "test.entity"},
48-
)
49-
assert call.call_args[1] == {"context": Context(id="test"), "blocking": False}
50-
51-
# Stop all tasks to avoid conflicts with other tests
52-
await Function.waiter_stop()
53-
await Function.reaper_stop()
16+
try:
17+
with patch(
18+
"custom_components.pyscript.state.async_get_all_descriptions",
19+
return_value={
20+
"test": {
21+
"test": {
22+
"description": None,
23+
"fields": {"entity_id": "blah", "other_service_data": "blah"},
24+
}
25+
}
26+
},
27+
), patch.object(hass.states, "get", return_value=HassState("test.entity", "True")), patch.object(
28+
hass.services, "async_call"
29+
) as call:
30+
State.init(hass)
31+
Function.init(hass)
32+
await State.get_service_params()
33+
34+
func = State.get("test.entity.test")
35+
await func(context=Context(id="test"), blocking=True, limit=1, other_service_data="test")
36+
assert call.called
37+
assert call.call_args[0] == (
38+
"test",
39+
"test",
40+
{"other_service_data": "test", "entity_id": "test.entity"},
41+
)
42+
assert call.call_args[1] == {"context": Context(id="test"), "blocking": True, "limit": 1}
43+
call.reset_mock()
44+
45+
func = State.get("test.entity.test")
46+
await func(context=Context(id="test"), blocking=False, other_service_data="test")
47+
assert call.called
48+
assert call.call_args[0] == (
49+
"test",
50+
"test",
51+
{"other_service_data": "test", "entity_id": "test.entity"},
52+
)
53+
assert call.call_args[1] == {"context": Context(id="test"), "blocking": False}
54+
except AttributeError as e:
55+
# ignore cleanup exception
56+
assert str(e) == "'StateMachine' object attribute 'get' is read-only"
57+
58+
# Stop all tasks to avoid conflicts with other tests
59+
await Function.waiter_stop()
60+
await Function.reaper_stop()

tests/test_unit_eval.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,7 @@ async def test_eval(hass):
14581458
"syntax error invalid syntax (<fstring>, line 1)", # < 3.9
14591459
"syntax error f-string: invalid syntax (test, line 1)", # >= 3.9
14601460
"syntax error f-string: invalid syntax. Perhaps you forgot a comma? (test, line 1)", # >= 3.10
1461+
"syntax error invalid syntax. Perhaps you forgot a comma? (test, line 1)", # >= 3.12
14611462
},
14621463
],
14631464
["del xx", "Exception in test line 1 column 0: name 'xx' is not defined"],

0 commit comments

Comments
 (0)