def _on_LOADING(self, tc: Telecom) -> Telecom: if self.robot.is_moving(): return Telecom(command=Command.MOVING) if not tc.payload: return Telecom(command=Command.LOADED_INVALID, errors=['no payload']) try: self.robot.load_positions(tc.payload) return Telecom(command=Command.LOADED_OK) except Exception as e: return Telecom(command=Command.LOADED_INVALID, errors=[str(e)])
def test_exchange_through_transmitter(self, init_robot): # -- given -- robot, transmitter, *_ = init_robot # -- when -- robot.exchange(Telecom(command=Command.MOVING)) # -- then -- transmitter.exchange.assert_called_once()
def test_send_tc_move(self, init_transmitter): # given robot, tr = init_transmitter # when tc = Telecom(command=Command.MOVE) tm = tr.exchange(tc) # then assert tm.command == Command.MOVED
def test_send_tc_on_loading_with_payload(self, init_transmitter): # given robot, tr = init_transmitter # when tc = Telecom(command=Command.LOADING, payload=['foo']) tm = tr.exchange(tc) # then assert tm.command == Command.LOADED_OK
def test_send_tc_on_loading_without_payload(self, init_transmitter): # given robot, tr = init_transmitter tc = Telecom(command=Command.LOADING) # when tm = tr.exchange(tc) # then assert tm.command == Command.LOADED_INVALID
def test_send_tc_ready_for_loading(self, init_transmitter): # given robot, tr = init_transmitter tc = Telecom(command=Command.READY_FOR_LOADING) # when tm = tr.exchange(tc) # then assert tm.command == Command.READY_FOR_LOADING
def test_send_tc_move_BUG(self, init_transmitter): # given robot, tr = init_transmitter # when robot.run.side_effect = ValueError("Mocked Exception") tc = Telecom(command=Command.MOVE) tm = tr.exchange(tc) # then assert tm.command == Command.INVALID
def test_send_tc_on_loading_when_robot_raise_error(self, init_transmitter): # given robot, tr = init_transmitter robot.load_positions.side_effect = ValueError('Mocked Exception') # when tc = Telecom(command=Command.LOADING, payload=['foo']) tm = tr.exchange(tc) # then assert tm.command == Command.LOADED_INVALID
def test_send_tc_on_loading_when_moving(self, init_transmitter): # given robot, tr = init_transmitter tc = Telecom(command=Command.LOADING) # when robot.is_moving.return_value = True tm = tr.exchange(tc) # then assert tm.command == Command.MOVING
def _on_MOVE(self, tc: Telecom) -> Telecom: try: self.robot.run() return Telecom(command=Command.MOVED) except Exception as e: return Telecom(command=Command.INVALID, errors=[str(e)])
def _on_READY_FOR_LOADING(self, tc: Telecom) -> Telecom: if self.robot.is_moving(): return Telecom(command=Command.MOVING) return Telecom(command=tc.command)
def test_new_telecom(self): tc = Telecom(command=Command.READY_FOR_LOADING)