Skip to content

Latest commit

 

History

History
65 lines (44 loc) · 2.29 KB

README.md

File metadata and controls

65 lines (44 loc) · 2.29 KB

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.

Using Remote Containers (recommended if you use VS Code)

Prerequisites

Steps

  1. Open the folder in a container. This will setup your environment with python (including python and pylance extensions), dependencies and download scxml tests.
  2. Run poetry run pytest --cov to run the tests! 👩‍🔬 (or run the Run 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

  1. Run poetry install to create a virtual environment
  2. Make sure test files are present and up to date by running git submodule update --init
  3. Run poetry run pytest --cov to run the tests! 👩‍🔬 (or run the Run 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.

Related Projects