@@ -199,6 +199,46 @@ def setup(self):
199199 assert current_config ["MyTool" ]["userparam" ] == 2.0
200200
201201
202+ def test_tool_current_config_subcomponents_list ():
203+ """Check that we can get the full instance configuration for tools that
204+ contain lists of subcomponents (which can be tools)"""
205+ from ctapipe .core .component import Component
206+
207+ class SubComponent (Component ):
208+ param = Int (default_value = 3 ).tag (config = True )
209+
210+ class SubComponent2 (Component ):
211+ param = Int (default_value = 3 ).tag (config = True )
212+
213+ class MyComponent (Component ):
214+ val = Int (default_value = 42 ).tag (config = True )
215+
216+ def __init__ (self , config = None , parent = None ):
217+ super ().__init__ (config = config , parent = parent )
218+ self .subs = [SubComponent (parent = self ), SubComponent2 (parent = self )]
219+
220+ class MyTool (Tool ):
221+ description = "test"
222+ userparam = Float (5.0 , help = "parameter" ).tag (config = True )
223+
224+ def setup (self ):
225+ self .my_comp = MyComponent (parent = self )
226+
227+ config = Config ()
228+ config .MyTool .userparam = 2.0
229+ config .MyTool .MyComponent .val = 10
230+ config .MyTool .MyComponent .SubComponent .param = - 1
231+
232+ tool = MyTool (config = config )
233+ tool .setup ()
234+
235+ current_config = tool .get_current_config ()
236+ assert current_config ["MyTool" ]["MyComponent" ]["val" ] == 10
237+ assert current_config ["MyTool" ]["MyComponent" ]["SubComponent" ]["param" ] == - 1
238+ assert current_config ["MyTool" ]["MyComponent" ]["SubComponent2" ]["param" ] == 3
239+ assert current_config ["MyTool" ]["userparam" ] == 2.0
240+
241+
202242def test_tool_exit_code ():
203243 """Check that we can get the full instance configuration"""
204244
@@ -665,3 +705,45 @@ class SomeTool(Tool):
665705 # test correct case:
666706 tool .load_config_file (good_conf_path )
667707 assert tool .float_option > 1
708+
709+
710+ def test_tool_in_tool ():
711+ """Check that a Tool that calls other Tools has the right config in the
712+ provenance log."""
713+
714+ class InnerTool (Tool ):
715+ param1 = traits .Integer (12 ).tag (config = True )
716+
717+ def start (self ):
718+ print (f"started inner: { self .get_current_config ()} " )
719+
720+ class CompoundTool (Tool ):
721+ param1 = traits .Integer (12 ).tag (config = True )
722+ filename = traits .Unicode ().tag (config = True )
723+
724+ classes = [
725+ InnerTool ,
726+ ]
727+
728+ def setup (self ):
729+ self ._inner = InnerTool (parent = self )
730+
731+ def start (self ):
732+ print (f"started calib: { self .get_current_config ()} " )
733+
734+ run_tool (self ._inner )
735+
736+ conf = Config ()
737+ conf .InnerTool .param1 = 6
738+ conf .CompoundTool .filename = "test.txt"
739+ conf .CompoundTool .param1 = 100
740+
741+ tool = CompoundTool (config = conf )
742+ run_tool (tool , raises = False ) # have to run it for setup()
743+
744+ assert "InnerTool" in tool .config
745+
746+ current_config = tool .get_current_config ()
747+ assert "CompoundTool" in current_config
748+ assert "InnerTool" in current_config ["CompoundTool" ]
749+ assert current_config ["CompoundTool" ]["InnerTool" ]["param1" ] == 6
0 commit comments