|
1 | 1 | from typing import cast |
2 | 2 |
|
3 | 3 | from isar.eventhandlers.eventhandler import EventHandlerMapping, State |
4 | | -from isar.models.events import EmptyMessage |
| 4 | +from isar.models.events import AbortedMission, EmptyMessage |
5 | 5 | from isar.state_machine.state_machine import StateMachine |
6 | 6 | from isar.state_machine.states.going_to_recharging import GoingToRecharging |
7 | 7 | from isar.state_machine.states.home import Home |
8 | 8 | from isar.state_machine.states.lockdown import Lockdown |
| 9 | +from isar.state_machine.states.monitor import Monitor |
9 | 10 | from isar.state_machine.states.recharging import Recharging |
| 11 | +from isar.state_machine.states.recharging_with_mission import RechargingWithMission |
10 | 12 |
|
11 | 13 |
|
12 | 14 | def test_going_to_recharging_goes_to_recharge( |
@@ -77,3 +79,41 @@ def test_recharging_continues_when_battery_low( |
77 | 79 | transition = event_handler.handler(10.0) |
78 | 80 |
|
79 | 81 | assert transition is None |
| 82 | + |
| 83 | + |
| 84 | +def test_continuing_mission_when_battery_high( |
| 85 | + sync_state_machine: StateMachine, |
| 86 | +) -> None: |
| 87 | + sync_state_machine.current_state = RechargingWithMission( |
| 88 | + sync_state_machine, mission=AbortedMission(name="test", id="test_id") |
| 89 | + ) |
| 90 | + returning_home_state: State = cast(State, sync_state_machine.current_state) |
| 91 | + event_handler: EventHandlerMapping | None = ( |
| 92 | + returning_home_state.get_event_handler_by_name("robot_battery_update_event") |
| 93 | + ) |
| 94 | + |
| 95 | + assert event_handler is not None |
| 96 | + |
| 97 | + transition = event_handler.handler(100.0) |
| 98 | + |
| 99 | + sync_state_machine.current_state = transition(sync_state_machine) |
| 100 | + assert type(sync_state_machine.current_state) is Monitor |
| 101 | + |
| 102 | + |
| 103 | +def test_cancelling_mission_when_recharging_with_mission( |
| 104 | + sync_state_machine: StateMachine, |
| 105 | +) -> None: |
| 106 | + sync_state_machine.current_state = RechargingWithMission( |
| 107 | + sync_state_machine, mission=AbortedMission(name="test", id="test_id") |
| 108 | + ) |
| 109 | + returning_home_state: State = cast(State, sync_state_machine.current_state) |
| 110 | + event_handler: EventHandlerMapping | None = ( |
| 111 | + returning_home_state.get_event_handler_by_name("stop_mission_event") |
| 112 | + ) |
| 113 | + |
| 114 | + assert event_handler is not None |
| 115 | + |
| 116 | + transition = event_handler.handler("test_id") |
| 117 | + |
| 118 | + sync_state_machine.current_state = transition(sync_state_machine) |
| 119 | + assert type(sync_state_machine.current_state) is Recharging |
0 commit comments