1919from launch .actions import GroupAction
2020from launch .actions import PopLaunchConfigurations
2121from launch .actions import PushLaunchConfigurations
22+ from launch .actions import ResetLaunchConfigurations
2223from launch .actions import SetLaunchConfiguration
24+ from launch .substitutions import LaunchConfiguration
2325
2426
2527def test_group_action_constructors ():
2628 """Test the constructors for the GroupAction class."""
2729 GroupAction ([])
2830 GroupAction ([Action ()])
2931 GroupAction ([Action ()], scoped = False )
30- GroupAction ([Action ()], scoped = False , launch_configurations = {'foo' : 'FOO' })
32+ GroupAction ([Action ()], scoped = False , forwarding = False )
33+ GroupAction ([Action ()], scoped = False , forwarding = False , launch_configurations = {'foo' : 'FOO' })
3134
3235
3336def test_group_action_execute ():
@@ -39,16 +42,26 @@ def test_group_action_execute():
3942 assert len (lc1 .launch_configurations ) == 0
4043
4144 assert len (lc1 .launch_configurations ) == 0
42- result = GroupAction ([]).visit (lc1 )
43- assert len (result ) == 2 # push and pop actions, due to scope=True
45+ result = GroupAction ([], forwarding = True ).visit (lc1 )
46+ assert len (result ) == 2 # push and pop actions, due to scope=True, forwarded=True
4447 assert isinstance (result [0 ], PushLaunchConfigurations )
4548 assert isinstance (result [1 ], PopLaunchConfigurations )
4649 for a in result :
4750 a .visit (lc1 )
4851 assert len (lc1 .launch_configurations ) == 0
4952
5053 assert len (lc1 .launch_configurations ) == 0
51- result = GroupAction ([], launch_configurations = {'foo' : 'FOO' }).visit (lc1 )
54+ result = GroupAction ([], forwarding = False ).visit (lc1 )
55+ assert len (result ) == 3 # push, reset, pop actions, due to scope=True, forwarded=False
56+ assert isinstance (result [0 ], PushLaunchConfigurations )
57+ assert isinstance (result [1 ], ResetLaunchConfigurations )
58+ assert isinstance (result [2 ], PopLaunchConfigurations )
59+ for a in result :
60+ a .visit (lc1 )
61+ assert len (lc1 .launch_configurations ) == 0
62+
63+ assert len (lc1 .launch_configurations ) == 0
64+ result = GroupAction ([], forwarding = True , launch_configurations = {'foo' : 'FOO' }).visit (lc1 )
5265 assert len (result ) == 3 # push, set 1 launch_configurations, and pop actions
5366 assert isinstance (result [0 ], PushLaunchConfigurations )
5467 assert isinstance (result [1 ], SetLaunchConfiguration )
@@ -58,7 +71,8 @@ def test_group_action_execute():
5871 assert len (lc1 .launch_configurations ) == 0
5972
6073 assert len (lc1 .launch_configurations ) == 0
61- result = GroupAction ([], launch_configurations = {'foo' : 'FOO' , 'bar' : 'BAR' }).visit (lc1 )
74+ result = GroupAction ([], forwarding = True ,
75+ launch_configurations = {'foo' : 'FOO' , 'bar' : 'BAR' }).visit (lc1 )
6276 assert len (result ) == 4 # push, set 2 launch_configurations, and pop actions
6377 assert isinstance (result [0 ], PushLaunchConfigurations )
6478 assert isinstance (result [1 ], SetLaunchConfiguration )
@@ -68,6 +82,17 @@ def test_group_action_execute():
6882 a .visit (lc1 )
6983 assert len (lc1 .launch_configurations ) == 0
7084
85+ assert len (lc1 .launch_configurations ) == 0
86+ result = GroupAction ([], forwarding = False ,
87+ launch_configurations = {'foo' : 'FOO' , 'bar' : 'BAR' }).visit (lc1 )
88+ assert len (result ) == 3 # push, reset (which will set launch_configurations), and pop actions
89+ assert isinstance (result [0 ], PushLaunchConfigurations )
90+ assert isinstance (result [1 ], ResetLaunchConfigurations )
91+ assert isinstance (result [2 ], PopLaunchConfigurations )
92+ for a in result :
93+ a .visit (lc1 )
94+ assert len (lc1 .launch_configurations ) == 0
95+
7196 assert len (lc1 .launch_configurations ) == 0
7297 PushLaunchConfigurations ().visit (lc1 )
7398 result = GroupAction ([], scoped = False , launch_configurations = {'foo' : 'FOO' }).visit (lc1 )
@@ -92,7 +117,8 @@ def test_group_action_execute():
92117 assert len (lc1 .launch_configurations ) == 0
93118
94119 assert len (lc1 .launch_configurations ) == 0
95- result = GroupAction ([Action ()], launch_configurations = {'foo' : 'FOO' }).visit (lc1 )
120+ result = GroupAction ([Action ()], forwarding = True ,
121+ launch_configurations = {'foo' : 'FOO' }).visit (lc1 )
96122 assert len (result ) == 4 # push, set 1 launch_configurations, the 1 action, and pop actions
97123 assert isinstance (result [0 ], PushLaunchConfigurations )
98124 assert isinstance (result [1 ], SetLaunchConfiguration )
@@ -101,3 +127,65 @@ def test_group_action_execute():
101127 for a in result :
102128 a .visit (lc1 )
103129 assert len (lc1 .launch_configurations ) == 0
130+
131+ assert len (lc1 .launch_configurations ) == 0
132+ lc1 .launch_configurations ['foo' ] = 'FOO'
133+ lc1 .launch_configurations ['bar' ] = 'BAR'
134+ result = GroupAction ([Action ()], forwarding = False ,
135+ launch_configurations = {'bar' : LaunchConfiguration ('bar' ),
136+ 'baz' : 'BAZ' }).visit (lc1 )
137+ # push, reset (which will set launch_configurations), 1 action, and pop actions
138+ assert len (result ) == 4
139+ assert isinstance (result [0 ], PushLaunchConfigurations )
140+ assert isinstance (result [1 ], ResetLaunchConfigurations )
141+ assert isinstance (result [2 ], Action )
142+ assert isinstance (result [3 ], PopLaunchConfigurations )
143+ result [0 ].visit (lc1 ) # Push
144+ assert 'foo' in lc1 .launch_configurations .keys () # Copied to new scope, before Reset
145+ assert lc1 .launch_configurations ['foo' ] == 'FOO'
146+ assert 'bar' in lc1 .launch_configurations .keys () # Copied to new scope, before Reset
147+ assert lc1 .launch_configurations ['bar' ] == 'BAR'
148+ result [1 ].visit (lc1 ) # Reset
149+ assert 'foo' not in lc1 .launch_configurations .keys () # Cleared from scope in Reset
150+ assert 'bar' in lc1 .launch_configurations .keys () # Evaluated and forwarded in Reset
151+ assert lc1 .launch_configurations ['bar' ] == 'BAR'
152+ assert 'baz' in lc1 .launch_configurations .keys () # Evaluated and added in Reset
153+ assert lc1 .launch_configurations ['baz' ] == 'BAZ'
154+ result [2 ].visit (lc1 ) # Action
155+ result [3 ].visit (lc1 ) # Pop
156+ assert 'foo' in lc1 .launch_configurations .keys () # Still in original scope
157+ assert lc1 .launch_configurations ['foo' ] == 'FOO'
158+ assert 'bar' in lc1 .launch_configurations .keys () # Still in original scope
159+ assert lc1 .launch_configurations ['bar' ] == 'BAR'
160+ assert 'baz' not in lc1 .launch_configurations .keys () # Out of scope from pop, no longer exists
161+ assert len (lc1 .launch_configurations ) == 2
162+ lc1 .launch_configurations .clear ()
163+
164+ assert len (lc1 .launch_configurations ) == 0
165+ lc1 .launch_configurations ['foo' ] = 'FOO'
166+ lc1 .launch_configurations ['bar' ] = 'BAR'
167+ result = GroupAction ([Action ()], forwarding = True ,
168+ launch_configurations = {'foo' : 'OOF' }).visit (lc1 )
169+ # push, 1 set (overwrite), 1 action, and pop actions
170+ assert len (result ) == 4
171+ assert isinstance (result [0 ], PushLaunchConfigurations )
172+ assert isinstance (result [1 ], SetLaunchConfiguration )
173+ assert isinstance (result [2 ], Action )
174+ assert isinstance (result [3 ], PopLaunchConfigurations )
175+ result [0 ].visit (lc1 ) # Push
176+ assert 'foo' in lc1 .launch_configurations .keys () # Copied to new scope, before Set
177+ assert lc1 .launch_configurations ['foo' ] == 'FOO'
178+ assert 'bar' in lc1 .launch_configurations .keys () # Copied to new scope
179+ assert lc1 .launch_configurations ['bar' ] == 'BAR'
180+ result [1 ].visit (lc1 ) # Set
181+ assert 'foo' in lc1 .launch_configurations .keys () # Overwritten in Set
182+ assert lc1 .launch_configurations ['foo' ] == 'OOF'
183+ assert 'bar' in lc1 .launch_configurations .keys () # Untouched
184+ assert lc1 .launch_configurations ['bar' ] == 'BAR'
185+ result [2 ].visit (lc1 ) # Action
186+ result [3 ].visit (lc1 ) # Pop
187+ assert 'foo' in lc1 .launch_configurations .keys () # Still in original scope with original value
188+ assert lc1 .launch_configurations ['foo' ] == 'FOO'
189+ assert 'bar' in lc1 .launch_configurations .keys () # Still in original scope with original value
190+ assert lc1 .launch_configurations ['bar' ] == 'BAR'
191+ lc1 .launch_configurations .clear ()
0 commit comments