Skip to content

Commit b91306e

Browse files
committed
fix: Fix event tests on the SCXML suit
1 parent 2af1eca commit b91306e

12 files changed

+24
-325
lines changed

statemachine/event_data.py

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from time import time
44
from typing import TYPE_CHECKING
55
from typing import Any
6-
from uuid import uuid4
76

87
if TYPE_CHECKING:
98
from .event import Event
@@ -41,8 +40,6 @@ def __post_init__(self):
4140
self.model = self.machine.model
4241
delay = self.event.delay if self.event and self.event.delay else 0
4342
self.execution_time = time() + (delay / 1000)
44-
if self.send_id is None:
45-
self.send_id = uuid4().hex
4643

4744

4845
@dataclass

statemachine/io/scxml/actions.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,32 @@ def get(self, name, default=None):
9292
return self.kwargs.get(name, default)
9393

9494

95+
class OriginTypeSCXML(str):
96+
"""The origintype of the :ref:`Event` as specified by the SCXML namespace."""
97+
98+
def __eq__(self, other):
99+
return other == "http://www.w3.org/TR/scxml/#SCXMLEventProcessor" or other == "scxml"
100+
101+
95102
class EventDataWrapper:
96103
origin: str = ""
97-
origintype: str = "http://www.w3.org/TR/scxml/#SCXMLEventProcessor"
104+
origintype: str = OriginTypeSCXML("scxml")
98105
"""The origintype of the :ref:`Event` as specified by the SCXML namespace."""
106+
invokeid: str = ""
107+
"""If this event is generated from an invoked child process, the SCXML Processor MUST set
108+
this field to the invoke id of the invocation that triggered the child process.
109+
Otherwise it MUST leave it blank.
110+
"""
99111

100112
def __init__(self, event_data):
101113
self.event_data = event_data
114+
self.sendid = event_data.trigger_data.send_id
102115
if event_data.trigger_data.event is None or event_data.trigger_data.event.internal:
103116
if "error.execution" == event_data.trigger_data.event:
104117
self.type = "platform"
105118
else:
106119
self.type = "internal"
120+
self.origintype = ""
107121
else:
108122
self.type = "external"
109123

@@ -365,12 +379,12 @@ def send_action(*args, **kwargs):
365379

366380
internal = target in ("#_internal", "internal")
367381

382+
send_id = None
368383
if action.id:
369384
send_id = action.id
370-
else:
385+
elif action.idlocation:
371386
send_id = uuid4().hex
372-
if action.idlocation:
373-
setattr(machine.model, action.idlocation, send_id)
387+
setattr(machine.model, action.idlocation, send_id)
374388

375389
delay = ParseTime.parse_delay(action.delay, action.delayexpr, **kwargs)
376390
names = [
@@ -380,6 +394,8 @@ def send_action(*args, **kwargs):
380394
]
381395
params_values = {}
382396
for param in chain(names, action.params):
397+
if param.expr is None:
398+
continue
383399
params_values[param.name] = _eval(param.expr, **kwargs)
384400

385401
Event(id=event, name=event, delay=delay, internal=internal, _sm=machine).put(

statemachine/io/scxml/processor.py

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def __getitem__(self, name: str):
4444
def location(self):
4545
return self.machine.name
4646

47+
def get(self, name: str):
48+
return getattr(self, name)
49+
4750

4851
@dataclass
4952
class SessionData:

statemachine/io/scxml/schema.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class IfBranch(Action):
4949
actions: List[Action] = field(default_factory=list)
5050

5151
def __str__(self):
52-
return self.cond
52+
return self.cond or "<empty cond>"
5353

5454
def append(self, action: Action):
5555
self.actions.append(action)

tests/scxml/w3c/mandatory/test330.fail.md

-31
This file was deleted.

tests/scxml/w3c/mandatory/test333.fail.md

-36
This file was deleted.

tests/scxml/w3c/mandatory/test337.fail.md

-31
This file was deleted.

tests/scxml/w3c/mandatory/test339.fail.md

-31
This file was deleted.

tests/scxml/w3c/mandatory/test351.fail.md

-56
This file was deleted.

tests/scxml/w3c/mandatory/test352.fail.md

-41
This file was deleted.

tests/scxml/w3c/mandatory/test500.fail.md

-43
This file was deleted.

0 commit comments

Comments
 (0)