@@ -69,6 +69,15 @@ def shutdown(trigger_time=None):
6969log.info(f"modules/xyz2/other global_ctx={pyscript.get_global_ctx()};")
7070
7171xyz = 123
72+ """ ,
73+ #
74+ # these shouldn't load since the package takes precedence
75+ #
76+ f"{ conf_dir } /modules/xyz2.py" : """
77+ log.info(f"BOTCH shouldn't load {__name__}")
78+ """ ,
79+ f"{ conf_dir } /apps/world2.py" : """
80+ log.info(f"BOTCH shouldn't load {__name__}")
7281""" ,
7382 }
7483
@@ -123,11 +132,11 @@ async def state_changed(event):
123132 assert hass .services .has_service ("pyscript" , "func2" )
124133 assert hass .services .has_service ("pyscript" , "func3" )
125134
126- assert "modules/xyz2 global_ctx=modules.xyz2.__init__ ;" in caplog .text
135+ assert "modules/xyz2 global_ctx=modules.xyz2;" in caplog .text
127136 assert "modules/xyz2/other global_ctx=modules.xyz2.other;" in caplog .text
128137 assert "hello global_ctx=file.hello xyz=123 xyz2.xyz=123" in caplog .text
129138 assert "world2.other global_ctx=apps.world2.other" in caplog .text
130- assert "world2 global_ctx=apps.world2.__init__ var1=100, other_abc=987" in caplog .text
139+ assert "world2 global_ctx=apps.world2 var1=100, other_abc=987" in caplog .text
131140
132141 #
133142 # add a new script file
@@ -196,7 +205,7 @@ def func20():
196205 #
197206 conf ["apps" ]["world2" ]["var1" ] = 200
198207 await hass .services .async_call ("pyscript" , "reload" , {}, blocking = True )
199- assert "world2 global_ctx=apps.world2.__init__ var1=200, other_abc=987" in caplog .text
208+ assert "world2 global_ctx=apps.world2 var1=200, other_abc=987" in caplog .text
200209 assert "world2.other global_ctx=apps.world2.other shutdown trigger_time=shutdown" in caplog .text
201210
202211 #
@@ -217,7 +226,7 @@ def shutdown(trigger_time=None):
217226 f"{ conf_dir } /apps/world2/other.py"
218227 ]
219228 await hass .services .async_call ("pyscript" , "reload" , {}, blocking = True )
220- assert "world2 global_ctx=apps.world2.__init__ var1=200, other_abc=654" in caplog .text
229+ assert "world2 global_ctx=apps.world2 var1=200, other_abc=654" in caplog .text
221230 assert "world2.other global_ctx=apps.world2.other shutdown trigger_time=shutdown" in caplog .text
222231
223232 #
@@ -226,10 +235,10 @@ def shutdown(trigger_time=None):
226235 #
227236 for i in range (3 ):
228237 assert caplog .text .count ("world global_ctx=apps.world xyz=" ) == 2 + i
229- assert caplog .text .count ("world2 global_ctx=apps.world2.__init__ var1=" ) == 3 + i
238+ assert caplog .text .count ("world2 global_ctx=apps.world2 var1=" ) == 3 + i
230239 assert caplog .text .count ("hello global_ctx=file.hello xyz=" ) == 4 + i
231240 assert caplog .text .count ("modules/xyz2/other global_ctx=modules.xyz2.other" ) == 2 + i
232- assert caplog .text .count ("modules/xyz2 global_ctx=modules.xyz2.__init__ " ) == 2 + i
241+ assert caplog .text .count ("modules/xyz2 global_ctx=modules.xyz2" ) == 2 + i
233242 assert (
234243 caplog .text .count ("world2.other global_ctx=apps.world2.other shutdown trigger_time=shutdown" )
235244 == 2
@@ -242,3 +251,8 @@ def shutdown(trigger_time=None):
242251 )
243252 if i < 2 :
244253 await hass .services .async_call ("pyscript" , "reload" , {"global_ctx" : "*" }, blocking = True )
254+
255+ #
256+ # make sure files that shouldn't load were not loaded
257+ #
258+ assert "BOTCH shouldn't load" not in caplog .text
0 commit comments