@@ -229,22 +229,84 @@ def test_actionid_try_except_inside_step_method(self):
229229 self .obj .prepare ()
230230 with open (self .obj .script ) as fds :
231231 content = fds .read ()
232+ normalized = TestSeleniumScriptGeneration .clear_spaces (content )
232233
233234 self .assertIn (
234235 TestSeleniumScriptGeneration .clear_spaces ("with apiritif.smart_transaction('tx'):\n try:" ),
235- TestSeleniumScriptGeneration . clear_spaces ( content )
236+ normalized
236237 )
237238 self .assertIn (
238239 TestSeleniumScriptGeneration .clear_spaces ("raise type(exc)" ),
239- TestSeleniumScriptGeneration . clear_spaces ( content )
240+ normalized
240241 )
241242 self .assertIn (
242243 TestSeleniumScriptGeneration .clear_spaces ("actionId: " ),
243- TestSeleniumScriptGeneration . clear_spaces ( content )
244+ normalized
244245 )
245246 self .assertIn (
246247 TestSeleniumScriptGeneration .clear_spaces ("def test_locsc(self):\n self._1_tx()" ),
247- TestSeleniumScriptGeneration .clear_spaces (content )
248+ normalized
249+ )
250+
251+ self .assertIn (
252+ TestSeleniumScriptGeneration .clear_spaces ("self._current_actionId = None" ),
253+ normalized
254+ )
255+ self .assertIn (
256+ TestSeleniumScriptGeneration .clear_spaces ("self._current_actionId = 'aid-1'" ),
257+ normalized
258+ )
259+
260+ action_id_assignment_pos = normalized .find (
261+ TestSeleniumScriptGeneration .clear_spaces ("self._current_actionId = 'aid-1'" )
262+ )
263+ action_call_pos = normalized .find (
264+ TestSeleniumScriptGeneration .clear_spaces ("self.driver.get('https://example.com')" )
265+ )
266+ self .assertNotEqual (- 1 , action_id_assignment_pos )
267+ self .assertNotEqual (- 1 , action_call_pos )
268+ self .assertLess (action_id_assignment_pos , action_call_pos )
269+
270+ self .assertIn (
271+ TestSeleniumScriptGeneration .clear_spaces ("self._current_actionId is not None" ),
272+ normalized
273+ )
274+ self .assertIn (
275+ TestSeleniumScriptGeneration .clear_spaces ("str(self._current_actionId)" ),
276+ normalized
277+ )
278+ self .assertIn (
279+ TestSeleniumScriptGeneration .clear_spaces ("'actionId: '" ),
280+ normalized
281+ )
282+ self .assertIn (
283+ TestSeleniumScriptGeneration .clear_spaces ("' | '" ),
284+ normalized
285+ )
286+ self .assertIn (
287+ TestSeleniumScriptGeneration .clear_spaces ("str(exc)" ),
288+ normalized
289+ )
290+
291+ def test_actionid_try_except_wraps_non_with_body (self ):
292+ generator = bzt .modules ._apiritif .generator .ApiritifScriptGenerator .__new__ (
293+ bzt .modules ._apiritif .generator .ApiritifScriptGenerator
294+ )
295+ body = [ast .Expr (value = ast .Constant (value = "noop" ))]
296+
297+ wrapped = generator ._gen_actionid_exception_wrapped_body (body )
298+
299+ self .assertEqual (1 , len (wrapped ))
300+ self .assertIsInstance (wrapped [0 ], ast .Try )
301+
302+ wrapped_code = astunparse .unparse (ast .Module (body = wrapped ))
303+ self .assertIn (
304+ TestSeleniumScriptGeneration .clear_spaces ("try:" ),
305+ TestSeleniumScriptGeneration .clear_spaces (wrapped_code )
306+ )
307+ self .assertIn (
308+ TestSeleniumScriptGeneration .clear_spaces ("raise type(exc)" ),
309+ TestSeleniumScriptGeneration .clear_spaces (wrapped_code )
248310 )
249311
250312 @staticmethod
0 commit comments