def testForward100Percent(self, mock_class): #mock_class.is_output.return_value = True m = Motor(Motor_0_Pins) self.assertTrue(m.gpio.set_low.called, "Expect a call to set_low") m.forward(100) m.gpio.set_high.assert_called_with(Motor_0_Pins.pwm)
def testEncoderInput2(self): # Check what we receive from the second encoder input when the motor turns. m = Motor() e = Encoder() m.forward() self.assertTrue(e.get_input(2)) m.stop() m.backward() self.assertTrue(e.get_input(2))
def testEncoderInput1(self): # We check what we receive from the first input when the motor turns. m = Motor() e = Encoder() m.forward() self.assertTrue(e.get_input(1)) m.stop() m.backward() self.assertTrue(e.get_input(1))
def testMotorInitialisation(self, mock_class): m = Motor(Motor_0_Pins) calls = [ unittest.mock.call(Motor_0_Pins.current), unittest.mock.call(Motor_0_Pins.direction), unittest.mock.call(Motor_0_Pins.pwm) ] m.gpio.set_low.assert_has_calls(calls)
def testEncoderForward(self): # The combination of the 2 inputs provide a 0-3 binary count, the sequence in which the values # appear indicates the direction of the motor. m = Motor() e = Encoder() m.forward() values = [] for x in range(100): values.append(e.get_value()) m.stop()
def create_required_motors(self): return { DriveSystem.MotorPosition.left: Motor(), DriveSystem.MotorPosition.right: Motor() }
def testCurrentIncreaseWithHigherOutput(self): m = Motor() m.forward(20) drain = m.current_drain() self.assertGreater( drain, 0, "The current drain should not be 0 when the motor is running") m.forward(40) self.assertGreater( m.current_drain(), drain, "The current drain should be greater at 40% than at 20%") drain = m.current_drain() m.forward(60) self.assertGreater( m.current_drain(), drain, "The current drain should be greater at 60% than at 40%") drain = m.current_drain() m.forward(80) self.assertGreater( m.current_drain(), drain, "The current drain should be greater at 80% than at 60%") drain = m.current_drain() m.forward(100) self.assertGreater( m.current_drain(), drain, "The current drain should be greater at 100% than at 80%") m.stop()
def testBackward50Percent(self): m = Motor() m.backward(50) self.assertGreater( m.current_drain(), 0, "The current drain should not be 0 when the motor is running")