Skip to content

Commit 5f3ccfa

Browse files
committed
address copilot review comments
1 parent 17971de commit 5f3ccfa

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

bzt/modules/_apiritif/generator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2017,7 +2017,6 @@ def _gen_master_test_method(self, try_block, finally_block):
20172017
teardown_marker = ast.Expr(ast_call(func=ast_attr("apiritif.set_stage"), args=[self._gen_expr("teardown")]))
20182018
finally_body.insert(0, teardown_marker)
20192019

2020-
if finally_body:
20212020
body = [ast.Try(
20222021
body=main_body,
20232022
handlers=[],

tests/unit/modules/_selenium/test_selenium_builder.py

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)