示例#1
0
    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()
示例#3
0
 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
示例#4
0
 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
示例#5
0
 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
示例#6
0
 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
示例#7
0
 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
示例#8
0
 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
示例#9
0
 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
示例#10
0
 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)])
示例#11
0
 def _on_READY_FOR_LOADING(self, tc: Telecom) -> Telecom:
     if self.robot.is_moving():
         return Telecom(command=Command.MOVING)
     return Telecom(command=tc.command)
示例#12
0
 def test_new_telecom(self):
     tc = Telecom(command=Command.READY_FOR_LOADING)