Пример #1
0
    def test_turn_motor_backwards(self):
        mock_parallel = mock.Mock()
        stepper = StepperMotor(self.MOTOR_INPUTS)
        stepper.parallel_interface = mock_parallel

        # turn -2.5 x rotation (24) == 60 x steps
        new_state = stepper.turn_motor(-2.5)
        self.assertEqual(new_state, 12)
        self.assertEqual(mock_parallel.setData.call_count, 60)
        # check last few steps were correct, going backwards to half a turn
        self.assertEqual([c[0][0] for c in mock_parallel.setData.call_args_list[-3:]], [0x09, 0x0B, 0x0A])
Пример #2
0
    def test_turn_motor_nowhere(self):
        "Ensure that 0 cycles doens't break!"
        mock_parallel = mock.Mock()
        stepper = StepperMotor(self.MOTOR_INPUTS, state=11)
        stepper.parallel_interface = mock_parallel

        # turn 0 x rotation == 0 x steps
        new_state = stepper.turn_motor(0)
        # stayed at offset 11
        self.assertEqual(new_state, 11)
        self.assertEqual(mock_parallel.setData.call_count, 0)
        self.assertEqual(mock_parallel.setData.call_args, None)
Пример #3
0
    def test_turn_motor_nowhere(self):
        "Ensure that 0 cycles doens't break!"
        mock_parallel = mock.Mock()
        stepper = StepperMotor(self.MOTOR_INPUTS, state=11)
        stepper.parallel_interface = mock_parallel

        # turn 0 x rotation == 0 x steps
        new_state = stepper.turn_motor(0)
        # stayed at offset 11
        self.assertEqual(new_state, 11)
        self.assertEqual(mock_parallel.setData.call_count, 0)
        self.assertEqual(mock_parallel.setData.call_args, None)
Пример #4
0
    def test_turn_motor_backwards(self):
        mock_parallel = mock.Mock()
        stepper = StepperMotor(self.MOTOR_INPUTS)
        stepper.parallel_interface = mock_parallel

        # turn -2.5 x rotation (24) == 60 x steps
        new_state = stepper.turn_motor(-2.5)
        self.assertEqual(new_state, 12)
        self.assertEqual(mock_parallel.setData.call_count, 60)
        # check last few steps were correct, going backwards to half a turn
        self.assertEqual(
            [c[0][0] for c in mock_parallel.setData.call_args_list[-3:]],
            [0X09, 0X0B, 0x0A])
Пример #5
0
    def test_turn_motor(self):
        mock_parallel = mock.Mock()
        stepper = StepperMotor(self.MOTOR_INPUTS, state=2)
        stepper.parallel_interface = mock_parallel

        # turn 1 x rotation == 24 x steps
        new_state = stepper.turn_motor(1)
        # returned to state 2 (starting point)
        self.assertEqual(new_state, 2)
        # called parallel 24 times for full cycle
        self.assertEqual(mock_parallel.setData.call_count, 24)
        # test the last few commands were forwards
        ##mock_parallel.setData.assert_has_calls(self.MOTOR_INPUTS[3:] + self.MOTOR_INPUTS[:3])
        self.assertEqual([c[0][0] for c in mock_parallel.setData.call_args_list[-4:]], [0x0D, 0x05, 0x07, 0x06])
Пример #6
0
    def test_turn_motor(self):
        mock_parallel = mock.Mock()
        stepper = StepperMotor(self.MOTOR_INPUTS, state=2)
        stepper.parallel_interface = mock_parallel

        # turn 1 x rotation == 24 x steps
        new_state = stepper.turn_motor(1)
        # returned to state 2 (starting point)
        self.assertEqual(new_state, 2)
        # called parallel 24 times for full cycle
        self.assertEqual(mock_parallel.setData.call_count, 24)
        # test the last few commands were forwards
        ##mock_parallel.setData.assert_has_calls(self.MOTOR_INPUTS[3:] + self.MOTOR_INPUTS[:3])
        self.assertEqual(
            [c[0][0] for c in mock_parallel.setData.call_args_list[-4:]],
            [0x0D, 0X05, 0X07, 0x06])