1- #!/usr/bin/env python
1+ #!/usr/bin/env python3
22
33# Based on the parameterized test case technique described here:
44#
1010import ev3dev .ev3 as ev3
1111
1212import parameterizedtestcase as ptc
13+ import os
1314
1415from motor_info import motor_info
1516
@@ -495,12 +496,13 @@ def test_time_sp_after_reset(self):
495496class 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
537539if __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-
0 commit comments