1818# Check if 'serial' module is installed
1919try :
2020 from serial import Serial
21- except ImportError , e :
22- print "Error: Can't import 'serial' module: %s" % e
21+ except ImportError as e :
22+ print ( "Error: Can't import 'serial' module: %s" % e )
2323 exit (- 1 )
2424
2525import os
2929from time import sleep , time
3030from optparse import OptionParser
3131
32- import host_tests_plugins
32+ from . import host_tests_plugins
3333
3434# This is a little tricky. We need to add upper directory to path so
3535# we can find packages we want from the same level as other files do
3939from tools .test_api import get_module_avail
4040
4141
42- class Mbed :
42+ class Mbed ( object ) :
4343 """ Base class for a host driven test
4444 """
4545 def __init__ (self ):
@@ -117,7 +117,7 @@ def __init__(self):
117117 self .serial_timeout = 1
118118
119119 self .timeout = self .DEFAULT_TOUT if self .options .timeout is None else self .options .timeout
120- print 'MBED: Instrumentation: "%s" and disk: "%s"' % (self .port , self .disk )
120+ print ( 'MBED: Instrumentation: "%s" and disk: "%s"' % (self .port , self .disk ) )
121121
122122 def init_serial_params (self , serial_baud = 9600 , serial_timeout = 1 ):
123123 """ Initialize port parameters.
@@ -183,11 +183,11 @@ def pool_for_serial_init(self, serial_baud, serial_timeout, pooling_loops=40, in
183183 stdout .write ('.' )
184184 stdout .flush ()
185185 else :
186- print "...port ready!"
186+ print ( "...port ready!" )
187187 result = True
188188 break
189189 if not result and last_error :
190- print last_error
190+ print ( last_error )
191191 return result
192192
193193 def set_serial_timeout (self , timeout ):
@@ -221,7 +221,7 @@ def serial_readline(self, timeout=5):
221221 c = self .serial .read (1 )
222222 result += c
223223 except Exception as e :
224- print "MBED: %s" % str (e )
224+ print ( "MBED: %s" % str (e ) )
225225 result = None
226226 break
227227 if c == '\n ' :
@@ -298,7 +298,7 @@ def flush(self):
298298 return result
299299
300300
301- class HostTestResults :
301+ class HostTestResults ( object ) :
302302 """ Test results set by host tests
303303 """
304304 def __init__ (self ):
@@ -389,8 +389,8 @@ def run(self):
389389 self .print_result (result )
390390 else :
391391 self .notify ("HOST: Passive mode..." )
392- except Exception , e :
393- print str (e )
392+ except Exception as e :
393+ print ( str (e ) )
394394 self .print_result (self .RESULT_ERROR )
395395
396396 def setup (self ):
@@ -406,7 +406,7 @@ def setup(self):
406406 def notify (self , message ):
407407 """ On screen notification function
408408 """
409- print message
409+ print ( message )
410410 stdout .flush ()
411411
412412 def print_result (self , result ):
0 commit comments