Skip to content

Commit

Permalink
Merge pull request #42 from nobrayner/patch-1
Browse files Browse the repository at this point in the history
test: added history state test
  • Loading branch information
davidkpiano committed Aug 12, 2021
2 parents 79edfa1 + 2076ebd commit 5df68b9
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/test_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,49 @@ def test_final_state():
red_timeout_state = lights.transition(red_stop_state, "TIMEOUT")

assert red_timeout_state.value == "green"



fan = Machine(
{
"id": "fan",
"initial": "fanOff",
"states": {
"fanOff": {
"on": {
"POWER": "#fan.fanOn.hist",
"HIGH_POWER": "fanOn.highPowerHist",
},
},
"fanOn": {
"initial": "first",
"states": {
"first": {"on": {"SWITCH": "second"}},
"second": {"on": {"SWITCH": "third"}},
"third": {},
"hist": {"type": "history", "history": "shallow"},
"highPowerHist": {"type": "history", "target": "third"},
},
"on": {"POWER": "fanOff"},
},
},
}
)


def test_history_state():
on_state = fan.transition(fan.initial_state, "POWER")

assert on_state.value == "fanOn.first"

on_second_state = fan.transition(on_state, "SWITCH")

assert on_second_state.value == "fanOn.second"

off_state = fan.transition(on_second_state, "POWER")

assert off_state.value == "fanOff"

on_second_state = fan.transition(off_state, "POWER")

assert on_second_state.value == "fanOn.second"

0 comments on commit 5df68b9

Please sign in to comment.