Skip to content

Conversation

@fgmacedo
Copy link
Owner

@fgmacedo fgmacedo commented Dec 3, 2024

Adds support for comparison operators into {ref}Condition expressions.

The following comparison operators are supported:

  1. > — Greather than.
  2. >= — Greather than or equal.
  3. == — Equal.
  4. != — Not equal.
  5. < — Lower than.
  6. <= — Lower than or equal.

Example:

>>> from statemachine import StateMachine, State, Event

>>> class AnyConditionSM(StateMachine):
...     start = State(initial=True)
...     end = State(final=True)
...
...     submit = Event(
...         start.to(end, cond="order_value > 100"),
...         name="finish order",
...     )
...
...     order_value: float = 0

>>> sm = AnyConditionSM()
>>> sm.submit()
Traceback (most recent call last):
TransitionNotAllowed: Can't finish order when in Start.

>>> sm.order_value = 135.0
>>> sm.submit()
>>> sm.current_state.id
'end'

@fgmacedo fgmacedo force-pushed the macedo/boolean-expression-comparison branch 2 times, most recently from c300057 to 2658917 Compare December 3, 2024 16:32
@fgmacedo fgmacedo force-pushed the macedo/boolean-expression-comparison branch from 2658917 to c4eace0 Compare December 3, 2024 17:13
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 3, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
1 Accepted issue

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@fgmacedo fgmacedo merged commit b1ef079 into develop Dec 3, 2024
13 checks passed
@fgmacedo fgmacedo deleted the macedo/boolean-expression-comparison branch December 3, 2024 17:18
@fgmacedo fgmacedo added this to the 2.5.0 milestone Dec 3, 2024
@codecov
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (1f91cc4) to head (c4eace0).
Report is 9 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff            @@
##           develop      #507   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           25        25           
  Lines         1601      1631   +30     
  Branches       255       257    +2     
=========================================
+ Hits          1601      1631   +30     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants