Skip to content

Commit 0757b05

Browse files
committed
cleanup
1 parent 6474508 commit 0757b05

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

src/robot/running/steprunner.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,22 @@ def _get_type(self, data, first, datacondition):
9191

9292
def run(self, data, name=None):
9393
IfRunner.current_if_stack.append(data)
94-
first = True
95-
condition_matched = False
96-
for datacondition, body in data.bodies:
97-
branch_to_execute, result = self._branch_to_be_executed(data, first, datacondition, body, condition_matched)
98-
condition_matched = condition_matched or branch_to_execute
99-
with StatusReporter(self._context, result, dry_run_lib_kw=not branch_to_execute):
100-
if branch_to_execute:
101-
runner = StepRunner(self._context, self._templated)
102-
runner.run_steps(body)
103-
first = False
104-
IfRunner.current_if_stack.pop()
94+
try:
95+
first = True
96+
condition_matched = False
97+
for datacondition, body in data.bodies:
98+
condition_matched = self._run_if_branch(body, condition_matched, data, datacondition, first)
99+
first = False
100+
finally:
101+
IfRunner.current_if_stack.pop()
102+
103+
def _run_if_branch(self, body, condition_matched, data, datacondition, first):
104+
branch_to_execute, result = self._branch_to_be_executed(data, first, datacondition, body, condition_matched)
105+
with StatusReporter(self._context, result, dry_run_lib_kw=not branch_to_execute):
106+
if branch_to_execute:
107+
runner = StepRunner(self._context, self._templated)
108+
runner.run_steps(body)
109+
return condition_matched or branch_to_execute
105110

106111
def _branch_to_be_executed(self, data, first, datacondition, body, condition_matched_already):
107112
data_type = self._get_type(data, first, datacondition)
@@ -110,25 +115,30 @@ def _branch_to_be_executed(self, data, first, datacondition, body, condition_mat
110115
if not condition_result:
111116
unresolved_condition = datacondition[0]
112117
if not condition_matched_already and not self._context.dry_run:
113-
condition, _ = VariableReplacer().replace([unresolved_condition], (), variables=self._context.variables)
114-
resolved_condition = condition[0]
115-
if is_unicode(resolved_condition):
116-
condition_result = evaluate_expression(resolved_condition, self._context.variables)
117-
else:
118-
condition_result = bool(resolved_condition)
118+
condition_result = self._resolve_condition(unresolved_condition)
119119
branch_to_execute = self._is_branch_to_execute(condition_matched_already,
120120
condition_result,
121121
body)
122122
result = KeywordResult(kwname=self._get_name(unresolved_condition),
123123
type=data_type)
124124
return branch_to_execute, result
125125

126+
def _resolve_condition(self, unresolved_condition):
127+
condition, _ = VariableReplacer().replace([unresolved_condition], (), variables=self._context.variables)
128+
resolved_condition = condition[0]
129+
if is_unicode(resolved_condition):
130+
return evaluate_expression(resolved_condition, self._context.variables)
131+
return bool(resolved_condition)
132+
126133
def _is_branch_to_execute(self, condition_matched_already, condition_result, body):
127134
if self._context.dry_run:
128-
current = IfRunner.current_if_stack[-1]
129-
return current not in IfRunner.current_if_stack[:-1]
135+
return not self._is_already_executing_this_if()
130136
return not condition_matched_already and condition_result and body
131137

138+
def _is_already_executing_this_if(self):
139+
current = IfRunner.current_if_stack[-1]
140+
return current in IfRunner.current_if_stack[:-1]
141+
132142
def _get_name(self, condition):
133143
if not condition:
134144
return ''

0 commit comments

Comments
 (0)