XState for Python - work in progress!
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 againMore advanced examples in the "examples" folder
You can set up your development environment in two different ways.
Using Remote Containers (recommended if you use VS Code)
Prerequisites
- 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 --covto run the tests! 👩🔬 (or run theRun teststask via VS Code or using VS Code Test explorer where you can debug as well)
Prerequisites
poetryfor package and dependency management
Steps
- Run
poetry installto create a virtual environment - Make sure test files are present and up to date by running
git submodule update --init - Run
poetry run pytest --covto run the tests! 👩🔬 (or run theRun teststask via VS Code or using VS Code Test explorer where you can debug as well)
SCXML tests are ran from the SCION Test Framework module.