@@ -95,9 +95,10 @@ async def test_func_completions(
9595@pytest .mark .asyncio
9696async 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
12481249async 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 ()
0 commit comments