Skip to content

feat: allow_event_without_transition#364

Merged
fgmacedo merged 1 commit intodevelopfrom
macedo/allow_event_without_transition
Mar 5, 2023
Merged

feat: allow_event_without_transition#364
fgmacedo merged 1 commit intodevelopfrom
macedo/allow_event_without_transition

Conversation

@fgmacedo
Copy link
Copy Markdown
Owner

@fgmacedo fgmacedo commented Mar 5, 2023

Added option to ignore unknown events

You can now instantiate a {ref}StateMachine with allow_event_without_transition=True,
so the state machine will allow triggering events that may not lead to a state {ref}transition,
including tolerance to unknown {ref}event triggers.

The default value is False, that keeps the backward compatible behavior of when an
event does not result in a {ref}transition, an exception TransitionNotAllowed will be raised.

>>> from statemachine import StateMachine, State

>>> class ApprovalMachine(StateMachine):
...     pending = State(initial=True)
...     waiting_approval = State()
...     approved = State(final=True)
...
...     start = pending.to(waiting_approval)
...     approve = waiting_approval.to(approved)
...

>>> sm = ApprovalMachine(allow_event_without_transition=True)

>>> sm.send("unknow_event_name")

>>> sm.pending.is_active
True

>>> sm.send("approve")

>>> sm.pending.is_active
True

>>> sm.send("start")

>>> sm.waiting_approval.is_active
True

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 5, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change

Comparison is base (de5d085) 100.00% compared to head (44cec99) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##           develop      #364   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           19        19           
  Lines          924       931    +7     
  Branches       153       154    +1     
=========================================
+ Hits           924       931    +7     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
statemachine/exceptions.py 100.00% <ø> (ø)
statemachine/state.py 100.00% <ø> (ø)
statemachine/event.py 100.00% <100.00%> (ø)
statemachine/event_data.py 100.00% <100.00%> (ø)
statemachine/statemachine.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@fgmacedo fgmacedo marked this pull request as ready for review March 5, 2023 04:22
@fgmacedo fgmacedo merged commit e8c1feb into develop Mar 5, 2023
@fgmacedo fgmacedo deleted the macedo/allow_event_without_transition branch March 5, 2023 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant