Skip to content

Commit 52a104d

Browse files
committed
fix: SCXML Parsing of if/else element
1 parent 842976d commit 52a104d

5 files changed

Lines changed: 23 additions & 7 deletions

File tree

statemachine/io/scxml.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,23 @@ def parse_if(element): # noqa: C901
122122
# Save the current branch before starting a new one
123123
if current_cond is not None:
124124
branches.append((current_cond, current_actions))
125-
elif tag == "else":
126-
else_branch = current_actions
127125

128126
# Update for the new branch
129-
current_cond = _normalize_cond(child.attrib.get("cond"))
130-
current_actions = []
127+
if tag == "elseif":
128+
current_cond = _normalize_cond(child.attrib.get("cond"))
129+
current_actions = []
130+
elif tag == "else":
131+
current_cond = None
132+
current_actions = else_branch # Start collecting actions for else
131133
else:
132134
# Add the action to the current branch
133135
current_actions.append(parse_element(child))
134136

135137
# Add the last branch if needed
136138
if current_cond is not None:
137139
branches.append((current_cond, current_actions))
140+
else:
141+
else_branch = current_actions
138142

139143
def if_action(*args, **kwargs):
140144
machine = kwargs["machine"]

statemachine/statemachine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,4 +316,4 @@ def send(self, event: str, *args, **kwargs):
316316

317317
@property
318318
def is_terminated(self):
319-
return self._engine.is_terminated
319+
return not self._engine._running

tests/test_multiple_destinations.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ def on_validate(self):
153153
# then
154154
assert machine.completed.is_active
155155

156+
assert machine.is_terminated
157+
156158
with pytest.raises(exceptions.TransitionNotAllowed, match="Can't validate when in Completed."):
157159
assert machine.validate()
158160

tests/w3c_tests/test_testcases.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22

33
"""
44
Test cases as defined by W3C SCXML Test Suite
5-
"""
5+
6+
- https://www.w3.org/Voice/2013/scxml-irp/
7+
- https://alexzhornyak.github.io/SCXML-tutorial/Tests/ecma/W3C/Mandatory/Auto/report__USCXML_2_0_0___msvc2015_32bit__Win7_1.html
8+
- https://github.com/alexzhornyak/PyBlendSCXML/tree/master/w3c_tests
9+
- https://github.com/jbeard4/SCION/wiki/Pseudocode-for-SCION-step-algorithm
10+
11+
""" # noqa: E501
612

713

814
def test_usecase(testcase_path, sm_class):
9-
# sm._graph().write_png(f"{testcase_path.name}.png")
15+
# from statemachine.contrib.diagram import DotGraphMachine
16+
17+
# DotGraphMachine(sm_class).get_graph().write_png(
18+
# testcase_path.parent / f"{testcase_path.stem}.png"
19+
# )
1020
sm = sm_class()
1121
assert isinstance(sm, StateMachine)
1222
assert sm.current_state.id == "pass"
File renamed without changes.

0 commit comments

Comments
 (0)