|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Based on the parameterized test case technique described here: |
| 4 | +# |
| 5 | +# http://eli.thegreenplace.net/2011/08/02/python-unit-testing-parametrized-test-cases |
| 6 | + |
| 7 | +import unittest |
| 8 | +import time |
| 9 | +import ev3dev.ev3 as ev3 |
| 10 | + |
| 11 | +import parameterizedtestcase as ptc |
| 12 | + |
| 13 | +from motor_info import motor_info |
| 14 | + |
| 15 | +class TestMotorRunDirect(ptc.ParameterizedTestCase): |
| 16 | + |
| 17 | + @classmethod |
| 18 | + def setUpClass(cls): |
| 19 | + pass |
| 20 | + |
| 21 | + @classmethod |
| 22 | + def tearDownClass(cls): |
| 23 | + pass |
| 24 | + |
| 25 | + def initialize_motor(self): |
| 26 | + self._param['motor'].command = 'reset' |
| 27 | + |
| 28 | + def run_direct_duty_cycles(self,stop_action,duty_cycles): |
| 29 | + self._param['motor'].stop_action = stop_action |
| 30 | + self._param['motor'].command = 'run-direct' |
| 31 | + |
| 32 | + for i in duty_cycles: |
| 33 | + self._param['motor'].duty_cycle_sp = i |
| 34 | + time.sleep(0.5) |
| 35 | + |
| 36 | + self._param['motor'].command = 'stop' |
| 37 | + |
| 38 | + def test_stop_coast_duty_cycles(self): |
| 39 | + self.initialize_motor() |
| 40 | + self.run_direct_duty_cycles('coast',[0,20,40,60,80,100,66,33,0,-20,-40,-60,-80,-100,-66,-33,0]) |
| 41 | + |
| 42 | +# Add all the tests to the suite - some tests apply only to certain drivers! |
| 43 | + |
| 44 | +def AddTachoMotorRunDirectTestsToSuite( suite, driver_name, params ): |
| 45 | + suite.addTest(ptc.ParameterizedTestCase.parameterize(TestMotorRunDirect, param=params)) |
| 46 | + |
| 47 | +if __name__ == '__main__': |
| 48 | + params = { 'motor': ev3.Motor('outA'), 'port': 'outA', 'driver_name': 'lego-ev3-l-motor' } |
| 49 | + |
| 50 | + suite = unittest.TestSuite() |
| 51 | + |
| 52 | + AddTachoMotorRunDirectTestsToSuite( suite, 'lego-ev3-l-motor', params ) |
| 53 | + |
| 54 | + unittest.TextTestRunner(verbosity=1,buffer=True ).run(suite) |
0 commit comments