Skip to content

Commit 8292004

Browse files
committed
Fixed unit ttests for -11-ev3dev kernel
- Removed motor_unittest.py - it has been split into smaller pieces - Replaced stop_command with stop_action - Created unit test for the run-direct command
1 parent 926e9d7 commit 8292004

File tree

5 files changed

+69
-676
lines changed

5 files changed

+69
-676
lines changed

tests/motor/motor_info.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
motor_info = {
22
'lego-ev3-l-motor': {'motion_type': 'rotation',
33
'count_per_rot': 360,
4-
'encoder_polarity': 'normal',
54
'max_speed': 1050,
65
'position_p': 80000,
76
'position_i': 0,
@@ -12,7 +11,6 @@
1211
'speed_d': 0 },
1312
'lego-ev3-m-motor': {'motion_type': 'rotation',
1413
'count_per_rot': 360,
15-
'encoder_polarity': 'normal',
1614
'max_speed': 1560,
1715
'position_p': 160000,
1816
'position_i': 0,
@@ -23,7 +21,6 @@
2321
'speed_d': 0 },
2422
'lego-nxt-motor': {'motion_type': 'rotation',
2523
'count_per_rot': 360,
26-
'encoder_polarity': 'normal',
2724
'max_speed': 1020,
2825
'position_p': 80000,
2926
'position_i': 0,
@@ -35,7 +32,6 @@
3532
'fi-l12-ev3-50': {'motion_type': 'linear',
3633
'count_per_m': 2000,
3734
'full_travel_count': 100,
38-
'encoder_polarity': 'inversed',
3935
'max_speed': 24,
4036
'position_p': 40000,
4137
'position_i': 0,
@@ -48,7 +44,6 @@
4844
'fi-l12-ev3-100': {'motion_type': 'linear',
4945
'count_per_m': 2000,
5046
'full_travel_count': 200,
51-
'encoder_polarity': 'inversed',
5247
'max_speed': 24,
5348
'position_p': 40000,
5449
'position_i': 0,
@@ -58,4 +53,4 @@
5853
'speed_i': 60,
5954
'speed_d': 0,
6055
}
61-
}
56+
}

tests/motor/motor_motion_unittest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def tearDownClass(cls):
2525
def initialize_motor(self):
2626
self._param['motor'].command = 'reset'
2727

28-
def run_to_positions(self,stop_command,command,speed_sp,positions,tolerance):
29-
self._param['motor'].stop_command = stop_command
28+
def run_to_positions(self,stop_action,command,speed_sp,positions,tolerance):
29+
self._param['motor'].stop_action = stop_action
3030
self._param['motor'].speed_sp = speed_sp
3131

3232
target = self._param['motor'].position

tests/motor/motor_param_unittest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import unittest
88
import time
9+
import sys
910
import ev3dev.ev3 as ev3
1011

1112
import parameterizedtestcase as ptc
@@ -491,6 +492,16 @@ def test_time_sp_after_reset(self):
491492
self._param['motor'].command = 'reset'
492493
self.assertEqual(self._param['motor'].speed_d, 0)
493494

495+
class TestTachoMotorDummy(ptc.ParameterizedTestCase):
496+
497+
def test_dummy_no_message(self):
498+
try:
499+
self.assertEqual(self._param['motor'].speed_d, 100, "Some clever error message {0}".format(self._param['motor'].speed_d))
500+
except:
501+
# Remove traceback info as we don't need it
502+
unittest_exception = sys.exc_info()
503+
raise unittest_exception[0], unittest_exception[1], unittest_exception[2].tb_next
504+
494505
# Add all the tests to the suite - some tests apply only to certain drivers!
495506

496507
def AddTachoMotorParameterTestsToSuite( suite, driver_name, params ):
@@ -521,6 +532,7 @@ def AddTachoMotorParameterTestsToSuite( suite, driver_name, params ):
521532
suite.addTest(ptc.ParameterizedTestCase.parameterize(TestTachoMotorStopActionValue, param=params))
522533
suite.addTest(ptc.ParameterizedTestCase.parameterize(TestTachoMotorStopActionsValue, param=params))
523534
suite.addTest(ptc.ParameterizedTestCase.parameterize(TestTachoMotorTimeSpValue, param=params))
535+
suite.addTest(ptc.ParameterizedTestCase.parameterize(TestTachoMotorDummy, param=params))
524536

525537
if __name__ == '__main__':
526538
for k in motor_info:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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

Comments
 (0)