XState for Python
XState for Python - work in progress!
How to use
from xstate import Machine
lights = Machine(
{
"id": "lights",
"initial": "green",
"states": {
"green": {"on": {"TIMER": "yellow"},},
"yellow": {"on": {"TIMER": "red"}},
"red": {"on": {"TIMER": "green"}},
},
}
)
state = lights.initial_state # state.value is green
state = lights.transition(state, "TIMER") # state.value is yellow
state = lights.transition(state, "TIMER") # state.value is red
state = lights.transition(state, "TIMER") # state.value is green again
More advanced examples in the "examples" folder
Developing
You can set up your development environment in two different ways.
Remote Containers (recommended if you use VS Code)
UsingPrerequisites
- VS Code IDE and Remote Containers extension
Steps
- Open the folder in a container. This will setup your environment with python (including python and pylance extensions), dependencies and download scxml tests.
- Run
poetry run pytest --cov
to run the tests!👩🔬 (or run theRun tests
task via VS Code or using VS Code Test explorer where you can debug as well)
Or installing the environment on your local drive
Prerequisites
poetry
for package and dependency management
Steps
- Run
poetry install
to create a virtual environment - Make sure test files are present and up to date by running
git submodule update --init
- Run
poetry run pytest --cov
to run the tests!👩🔬 (or run theRun tests
task via VS Code or using VS Code Test explorer where you can debug as well)
SCXML
SCXML tests are ran from the SCION Test Framework module.