Skip to content

Commit af4c11d

Browse files
authored
Remove hard coded outA on port4 assumption (ev3dev#337)
1 parent d62aeb2 commit af4c11d

4 files changed

Lines changed: 28 additions & 9 deletions

File tree

‎tests/motor/ev3dev_port_logger.py‎

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import json
44
import argparse

‎tests/motor/motor_motion_unittest.py‎

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
# Based on the parameterized test case technique described here:
44
#

‎tests/motor/motor_param_unittest.py‎

100644100755
Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
# Based on the parameterized test case technique described here:
44
#
@@ -10,6 +10,7 @@
1010
import ev3dev.ev3 as ev3
1111

1212
import parameterizedtestcase as ptc
13+
import os
1314

1415
from motor_info import motor_info
1516

@@ -495,12 +496,13 @@ def test_time_sp_after_reset(self):
495496
class TestTachoMotorDummy(ptc.ParameterizedTestCase):
496497

497498
def test_dummy_no_message(self):
499+
498500
try:
499501
self.assertEqual(self._param['motor'].speed_d, 100, "Some clever error message {0}".format(self._param['motor'].speed_d))
500-
except:
502+
except Exception:
501503
# Remove traceback info as we don't need it
502504
unittest_exception = sys.exc_info()
503-
raise unittest_exception[0], unittest_exception[1], unittest_exception[2].tb_next
505+
print("%s,%s,%s" % (unittest_exception[0], unittest_exception[1], unittest_exception[2].tb_next))
504506

505507
# Add all the tests to the suite - some tests apply only to certain drivers!
506508

@@ -535,8 +537,26 @@ def AddTachoMotorParameterTestsToSuite( suite, driver_name, params ):
535537
suite.addTest(ptc.ParameterizedTestCase.parameterize(TestTachoMotorDummy, param=params))
536538

537539
if __name__ == '__main__':
538-
for k in motor_info:
539-
file = open('/sys/class/lego-port/port4/set_device', 'w')
540+
port_for_outA = None
541+
542+
# which port has outA?
543+
for filename in os.listdir('/sys/class/lego-port/'):
544+
address_filename = '/sys/class/lego-port/%s/address' % filename
545+
546+
if os.path.exists(address_filename):
547+
with open(address_filename, 'r') as fh:
548+
for line in fh:
549+
if line.rstrip().endswith(':outA'):
550+
port_for_outA = filename
551+
break
552+
553+
if port_for_outA:
554+
break
555+
else:
556+
raise Exception("Could not find port /sys/class/lego-port/ for outA")
557+
558+
for k in motor_info:
559+
file = open('/sys/class/lego-port/%s/set_device' % port_for_outA, 'w')
540560
file.write('{0}\n'.format(k))
541561
file.close()
542562
time.sleep(0.5)
@@ -548,4 +568,3 @@ def AddTachoMotorParameterTestsToSuite( suite, driver_name, params ):
548568
AddTachoMotorParameterTestsToSuite( suite, k, params )
549569
print( '-------------------- TESTING {0} --------------'.format(k))
550570
unittest.TextTestRunner(verbosity=1,buffer=True ).run(suite)
551-

‎tests/motor/motor_run_direct_unittest.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
# Based on the parameterized test case technique described here:
44
#

0 commit comments

Comments
 (0)