@@ -106,39 +106,37 @@ async def test_patch(
106106 restart : bool ,
107107) -> None :
108108 """Test updating a file."""
109- with tempfile . TemporaryDirectory () as base :
110- with tempfile .TemporaryDirectory () as destination :
111- with tempfile .TemporaryDirectory () as patch_dir :
112- with open ( os . path . join ( base , "file" ), "w" , encoding = "ascii" ) as file :
113- file . write ( base_content )
114- with open (
115- os . path . join ( destination , "file" ), "w" , encoding = "ascii"
116- ) as file :
117- file .write (destination_content )
118- with open (
119- os . path . join ( patch_dir , "file" ), "w" , encoding = "ascii"
120- ) as file :
121- file . write ( patch_content )
122- await async_setup (
123- hass ,
109+ with (
110+ tempfile .TemporaryDirectory () as base ,
111+ tempfile .TemporaryDirectory () as destination ,
112+ tempfile . TemporaryDirectory () as patch_dir ,
113+ ):
114+ with open ( os . path . join ( base , "file" ), "w" , encoding = "ascii" ) as file :
115+ file . write ( base_content )
116+ with open ( os . path . join ( destination , "file" ), "w" , encoding = "ascii" ) as file :
117+ file .write (destination_content )
118+ with open ( os . path . join ( patch_dir , "file" ), "w" , encoding = "ascii" ) as file :
119+ file . write ( patch_content )
120+ await async_setup (
121+ hass ,
122+ {
123+ CONF_FILES : [
124124 {
125- CONF_FILES : [
126- {
127- CONF_NAME : "file" ,
128- CONF_BASE : base ,
129- CONF_DESTINATION : destination ,
130- CONF_PATCH : patch_dir ,
131- }
132- ]
133- },
134- )
135- await async_next_day (hass , freezer )
136- with open (os .path .join (destination , "file" ), encoding = "ascii" ) as file :
137- assert file .read () == (
138- patch_content
139- if base_content == destination_content
140- else destination_content
141- )
125+ CONF_NAME : "file" ,
126+ CONF_BASE : base ,
127+ CONF_DESTINATION : destination ,
128+ CONF_PATCH : patch_dir ,
129+ }
130+ ]
131+ },
132+ )
133+ await async_next_day (hass , freezer )
134+ with open (os .path .join (destination , "file" ), encoding = "ascii" ) as file :
135+ assert file .read () == (
136+ patch_content
137+ if base_content == destination_content
138+ else destination_content
139+ )
142140 assert async_call_mock .call_count == (1 if restart else 0 )
143141 if restart :
144142 assert async_call_mock .await_args_list [0 ].args [0 ] == ha .DOMAIN
@@ -173,40 +171,36 @@ async def async_core_reload_mock(service_call: ServiceCall) -> None:
173171 vol .Schema ({}),
174172 )
175173
176- with tempfile .TemporaryDirectory () as base :
177- with tempfile .TemporaryDirectory () as destination :
178- with tempfile .TemporaryDirectory () as patch_dir :
179- with open (os .path .join (base , "file" ), "w" , encoding = "ascii" ) as file :
180- file .write ("123" )
181- with open (
182- os .path .join (destination , "file" ), "w" , encoding = "ascii"
183- ) as file :
184- file .write ("123" )
185- with open (
186- os .path .join (patch_dir , "file" ), "w" , encoding = "ascii"
187- ) as file :
188- file .write ("456" )
189- with patch (
190- "homeassistant.config.load_yaml_config_file" ,
191- return_value = {
192- DOMAIN : {
193- CONF_FILES : [
194- {
195- CONF_NAME : "file" ,
196- CONF_BASE : base ,
197- CONF_DESTINATION : destination ,
198- CONF_PATCH : patch_dir ,
199- }
200- ]
174+ with (
175+ tempfile .TemporaryDirectory () as base ,
176+ tempfile .TemporaryDirectory () as destination ,
177+ tempfile .TemporaryDirectory () as patch_dir ,
178+ ):
179+ with open (os .path .join (base , "file" ), "w" , encoding = "ascii" ) as file :
180+ file .write ("123" )
181+ with open (os .path .join (destination , "file" ), "w" , encoding = "ascii" ) as file :
182+ file .write ("123" )
183+ with open (os .path .join (patch_dir , "file" ), "w" , encoding = "ascii" ) as file :
184+ file .write ("456" )
185+ with patch (
186+ "homeassistant.config.load_yaml_config_file" ,
187+ return_value = {
188+ DOMAIN : {
189+ CONF_FILES : [
190+ {
191+ CONF_NAME : "file" ,
192+ CONF_BASE : base ,
193+ CONF_DESTINATION : destination ,
194+ CONF_PATCH : patch_dir ,
201195 }
202- },
203- ):
204- await hass . services . async_call (
205- DOMAIN , SERVICE_RELOAD , blocking = True
206- )
207- await hass .async_block_till_done ()
208- with open (os .path .join (destination , "file" ), encoding = "ascii" ) as file :
209- assert file .read () == "456"
196+ ]
197+ }
198+ },
199+ ):
200+ await hass . services . async_call ( DOMAIN , SERVICE_RELOAD , blocking = True )
201+ await hass .async_block_till_done ()
202+ with open (os .path .join (destination , "file" ), encoding = "ascii" ) as file :
203+ assert file .read () == "456"
210204 assert len (core_reload_calls ) == 1
211205
212206
0 commit comments