File tree Expand file tree Collapse file tree 2 files changed +69
-5
lines changed
tests/unit/modules/_selenium Expand file tree Collapse file tree 2 files changed +69
-5
lines changed Original file line number Diff line number Diff line change @@ -1970,6 +1970,32 @@ def _gen_actionid_exception_wrapped_body(self, body):
19701970 )
19711971 )
19721972
1973+ if len (body ) == 1 and isinstance (body [0 ], ast .With ):
1974+ with_stmt = body [0 ]
1975+ wrapped_try = ast .Try (
1976+ body = with_stmt .body ,
1977+ handlers = [ast .ExceptHandler (
1978+ type = ast .Name (id = "Exception" , ctx = ast .Load ()),
1979+ name = "exc" ,
1980+ body = [ast .Raise (
1981+ exc = ast .Call (
1982+ func = ast .Call (
1983+ func = ast .Name (id = "type" , ctx = ast .Load ()),
1984+ args = [ast .Name (id = "exc" , ctx = ast .Load ())],
1985+ keywords = []
1986+ ),
1987+ args = [final_error ],
1988+ keywords = []
1989+ ),
1990+ cause = ast .Name (id = "exc" , ctx = ast .Load ())
1991+ )]
1992+ )],
1993+ orelse = [],
1994+ finalbody = []
1995+ )
1996+ with_stmt .body = [wrapped_try ]
1997+ return [with_stmt ]
1998+
19731999 wrapped_try = ast .Try (
19742000 body = body ,
19752001 handlers = [ast .ExceptHandler (
@@ -1992,11 +2018,6 @@ def _gen_actionid_exception_wrapped_body(self, body):
19922018 finalbody = []
19932019 )
19942020
1995- if len (body ) == 1 and isinstance (body [0 ], ast .With ):
1996- with_stmt = body [0 ]
1997- with_stmt .body = [wrapped_try ]
1998- return [with_stmt ]
1999-
20002021 return [wrapped_try ]
20012022
20022023 def _gen_master_test_method (self , try_block , finally_block ):
Original file line number Diff line number Diff line change @@ -204,6 +204,49 @@ def test_modern_actions_generator(self):
204204 TestSeleniumScriptGeneration .clear_spaces (content ),
205205 msg = "\n \n %s. %s" % (idx , target_lines [idx ]))
206206
207+ def test_actionid_try_except_inside_step_method (self ):
208+ self .configure ({
209+ "execution" : [{
210+ "executor" : "apiritif" ,
211+ "scenario" : "loc_sc"
212+ }],
213+ "scenarios" : {
214+ "loc_sc" : {
215+ "default-address" : "https://example.com" ,
216+ "requests" : [{
217+ "label" : "tx" ,
218+ "actions" : [{
219+ "type" : "go" ,
220+ "param" : "https://example.com" ,
221+ "value" : None ,
222+ "actionId" : "aid-1"
223+ }]
224+ }]
225+ }
226+ }
227+ })
228+
229+ self .obj .prepare ()
230+ with open (self .obj .script ) as fds :
231+ content = fds .read ()
232+
233+ self .assertIn (
234+ TestSeleniumScriptGeneration .clear_spaces ("with apiritif.smart_transaction('tx'):\n try:" ),
235+ TestSeleniumScriptGeneration .clear_spaces (content )
236+ )
237+ self .assertIn (
238+ TestSeleniumScriptGeneration .clear_spaces ("raise type(exc)" ),
239+ TestSeleniumScriptGeneration .clear_spaces (content )
240+ )
241+ self .assertIn (
242+ TestSeleniumScriptGeneration .clear_spaces (" actionId: " ),
243+ TestSeleniumScriptGeneration .clear_spaces (content )
244+ )
245+ self .assertIn (
246+ TestSeleniumScriptGeneration .clear_spaces ("def test_locsc(self):\n self._1_tx()" ),
247+ TestSeleniumScriptGeneration .clear_spaces (content )
248+ )
249+
207250 @staticmethod
208251 def clear_spaces (content ):
209252 return content .replace (" " , "" ).replace ("\t " , "" ).replace ("\n " , "" )
You can’t perform that action at this time.
0 commit comments