Skip to content

Commit

Permalink
fix: Fix event tests on the SCXML suit
Browse files Browse the repository at this point in the history
  • Loading branch information
fgmacedo committed Dec 23, 2024
1 parent 0d57a45 commit 105d736
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 325 deletions.
3 changes: 0 additions & 3 deletions statemachine/event_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from time import time
from typing import TYPE_CHECKING
from typing import Any
from uuid import uuid4

if TYPE_CHECKING:
from .event import Event
Expand Down Expand Up @@ -41,8 +40,6 @@ def __post_init__(self):
self.model = self.machine.model
delay = self.event.delay if self.event and self.event.delay else 0
self.execution_time = time() + (delay / 1000)
if self.send_id is None:
self.send_id = uuid4().hex


@dataclass
Expand Down
24 changes: 20 additions & 4 deletions statemachine/io/scxml/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,32 @@ def get(self, name, default=None):
return self.kwargs.get(name, default)


class OriginTypeSCXML(str):
"""The origintype of the :ref:`Event` as specified by the SCXML namespace."""

def __eq__(self, other):
return other == "http://www.w3.org/TR/scxml/#SCXMLEventProcessor" or other == "scxml"


class EventDataWrapper:
origin: str = ""
origintype: str = "http://www.w3.org/TR/scxml/#SCXMLEventProcessor"
origintype: str = OriginTypeSCXML("scxml")
"""The origintype of the :ref:`Event` as specified by the SCXML namespace."""
invokeid: str = ""
"""If this event is generated from an invoked child process, the SCXML Processor MUST set
this field to the invoke id of the invocation that triggered the child process.
Otherwise it MUST leave it blank.
"""

def __init__(self, event_data):
self.event_data = event_data
self.sendid = event_data.trigger_data.send_id
if event_data.trigger_data.event is None or event_data.trigger_data.event.internal:
if "error.execution" == event_data.trigger_data.event:
self.type = "platform"
else:
self.type = "internal"
self.origintype = ""
else:
self.type = "external"

Expand Down Expand Up @@ -365,12 +379,12 @@ def send_action(*args, **kwargs):

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

send_id = None
if action.id:
send_id = action.id
else:
elif action.idlocation:
send_id = uuid4().hex
if action.idlocation:
setattr(machine.model, action.idlocation, send_id)
setattr(machine.model, action.idlocation, send_id)

delay = ParseTime.parse_delay(action.delay, action.delayexpr, **kwargs)
names = [
Expand All @@ -380,6 +394,8 @@ def send_action(*args, **kwargs):
]
params_values = {}
for param in chain(names, action.params):
if param.expr is None:
continue

Check warning on line 398 in statemachine/io/scxml/actions.py

View check run for this annotation

Codecov / codecov/patch

statemachine/io/scxml/actions.py#L398

Added line #L398 was not covered by tests
params_values[param.name] = _eval(param.expr, **kwargs)

Event(id=event, name=event, delay=delay, internal=internal, _sm=machine).put(
Expand Down
3 changes: 3 additions & 0 deletions statemachine/io/scxml/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def __getitem__(self, name: str):
def location(self):
return self.machine.name

def get(self, name: str):
return getattr(self, name)


@dataclass
class SessionData:
Expand Down
2 changes: 1 addition & 1 deletion statemachine/io/scxml/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class IfBranch(Action):
actions: List[Action] = field(default_factory=list)

def __str__(self):
return self.cond
return self.cond or "<empty cond>"

Check warning on line 52 in statemachine/io/scxml/schema.py

View check run for this annotation

Codecov / codecov/patch

statemachine/io/scxml/schema.py#L52

Added line #L52 was not covered by tests

def append(self, action: Action):
self.actions.append(action)
Expand Down
31 changes: 0 additions & 31 deletions tests/scxml/w3c/mandatory/test330.fail.md

This file was deleted.

36 changes: 0 additions & 36 deletions tests/scxml/w3c/mandatory/test333.fail.md

This file was deleted.

31 changes: 0 additions & 31 deletions tests/scxml/w3c/mandatory/test337.fail.md

This file was deleted.

31 changes: 0 additions & 31 deletions tests/scxml/w3c/mandatory/test339.fail.md

This file was deleted.

56 changes: 0 additions & 56 deletions tests/scxml/w3c/mandatory/test351.fail.md

This file was deleted.

41 changes: 0 additions & 41 deletions tests/scxml/w3c/mandatory/test352.fail.md

This file was deleted.

43 changes: 0 additions & 43 deletions tests/scxml/w3c/mandatory/test500.fail.md

This file was deleted.

Loading

0 comments on commit 105d736

Please sign in to comment.