Skip to content

Commit 45bdd98

Browse files
committed
Python2+3: tests import correctly
1 parent 7abeec9 commit 45bdd98

22 files changed

+219
-159
lines changed

tools/build_travis.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,6 @@ def run_test_linking(dry_run, vendor):
414414
if os.system(cmdline) != 0:
415415
sys.exit(1)
416416

417-
def run_test_testsuite(dry_run, vendor):
418-
cmdline = "python tools/singletest.py --version"
419-
print "Executing: " + cmdline
420-
if not dry_run:
421-
if os.system(cmdline) != 0:
422-
sys.exit(1)
423-
424417
if __name__ == "__main__":
425418
parser = ArgumentParser()
426419

@@ -434,4 +427,3 @@ def run_test_testsuite(dry_run, vendor):
434427

435428
run_builds("-s" in sys.argv, options.vendor)
436429
run_test_linking("-s" in sys.argv, options.vendor)
437-
run_test_testsuite("-s" in sys.argv, options.vendor)

tools/detect_targets.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
See the License for the specific language governing permissions and
1616
limitations under the License.
1717
"""
18+
from __future__ import print_function
1819
import sys
1920
import os
2021
import re
@@ -67,8 +68,8 @@ def main():
6768

6869
# Only prints matrix of supported toolchains
6970
if options.supported_toolchains:
70-
print mcu_toolchain_matrix(
71-
platform_filter=options.general_filter_regex)
71+
print(mcu_toolchain_matrix(
72+
platform_filter=options.general_filter_regex))
7273
exit(0)
7374

7475
# If auto_detect attribute is present, we assume other auto-detection
@@ -81,23 +82,23 @@ def main():
8182
for mut in muts.values():
8283
if re.match(mcu_filter, mut['mcu']):
8384
interface_version = get_interface_version(mut['disk'])
84-
print ""
85-
print "[mbed] Detected %s, port %s, mounted %s, interface version %s:" % \
86-
(mut['mcu'], mut['port'], mut['disk'], interface_version)
87-
88-
print "[mbed] Supported toolchains for %s" % mut['mcu']
89-
print mcu_toolchain_matrix(platform_filter=mut['mcu'])
85+
print("")
86+
print("[mbed] Detected %s, port %s, mounted %s, interface "
87+
"version %s:" %
88+
(mut['mcu'], mut['port'], mut['disk'], interface_version))
89+
print("[mbed] Supported toolchains for %s" % mut['mcu'])
90+
print(mcu_toolchain_matrix(platform_filter=mut['mcu']))
9091
count += 1
9192

9293
if count == 0:
93-
print "[mbed] No mbed targets were detected on your system."
94+
print("[mbed] No mbed targets were detected on your system.")
9495

9596
except KeyboardInterrupt:
96-
print "\n[CTRL+c] exit"
97+
print("\n[CTRL+c] exit")
9798
except Exception as exc:
9899
import traceback
99100
traceback.print_exc(file=sys.stdout)
100-
print "[ERROR] %s" % str(exc)
101+
print("[ERROR] %s" % str(exc))
101102
sys.exit(1)
102103

103104
def get_interface_version(mount_point):

tools/host_tests/__init__.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@
1515
limitations under the License.
1616
"""
1717

18-
from host_registry import HostRegistry
18+
from .host_registry import HostRegistry
1919

2020
# Host test supervisors
21-
from echo import EchoTest
22-
from rtc_auto import RTCTest
23-
from stdio_auto import StdioTest
24-
from hello_auto import HelloTest
25-
from detect_auto import DetectPlatformTest
26-
from default_auto import DefaultAuto
27-
from dev_null_auto import DevNullTest
28-
from wait_us_auto import WaitusTest
29-
from tcpecho_server_auto import TCPEchoServerTest
30-
from udpecho_server_auto import UDPEchoServerTest
31-
from tcpecho_client_auto import TCPEchoClientTest
32-
from udpecho_client_auto import UDPEchoClientTest
33-
from wfi_auto import WFITest
34-
from serial_nc_rx_auto import SerialNCRXTest
35-
from serial_nc_tx_auto import SerialNCTXTest
36-
from serial_complete_auto import SerialCompleteTest
21+
from .echo import EchoTest
22+
from .rtc_auto import RTCTest
23+
from .stdio_auto import StdioTest
24+
from .hello_auto import HelloTest
25+
from .detect_auto import DetectPlatformTest
26+
from .default_auto import DefaultAuto
27+
from .dev_null_auto import DevNullTest
28+
from .wait_us_auto import WaitusTest
29+
from .tcpecho_server_auto import TCPEchoServerTest
30+
from .udpecho_server_auto import UDPEchoServerTest
31+
from .tcpecho_client_auto import TCPEchoClientTest
32+
from .udpecho_client_auto import UDPEchoClientTest
33+
from .wfi_auto import WFITest
34+
from .serial_nc_rx_auto import SerialNCRXTest
35+
from .serial_nc_tx_auto import SerialNCTXTest
36+
from .serial_complete_auto import SerialCompleteTest
3737

3838
# Populate registry with supervising objects
3939
HOSTREGISTRY = HostRegistry()

tools/host_tests/default_auto.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17+
from __future__ import print_function
1718

1819
from sys import stdout
1920

@@ -30,7 +31,7 @@ def test(self, selftest):
3031
return selftest.RESULT_IO_SERIAL
3132
stdout.write(c)
3233
stdout.flush()
33-
except KeyboardInterrupt, _:
34+
except KeyboardInterrupt:
3435
selftest.notify("\r\n[CTRL+C] exit")
3536
result = selftest.RESULT_ERROR
3637
return result

tools/host_tests/host_tests_plugins/__init__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,27 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17+
from __future__ import print_function
1718

18-
import host_test_registry
19+
from . import host_test_registry
1920

2021
# This plugins provide 'flashing' methods to host test scripts
21-
import module_copy_mbed
22-
import module_copy_shell
23-
import module_copy_silabs
22+
from . import module_copy_mbed
23+
from . import module_copy_shell
24+
from . import module_copy_silabs
2425

2526
try:
26-
import module_copy_smart
27+
from . import module_copy_smart
2728
except:
2829
pass
2930

3031
#import module_copy_firefox
31-
import module_copy_mps2
32+
from . import module_copy_mps2
3233

3334
# Plugins used to reset certain platform
34-
import module_reset_mbed
35-
import module_reset_silabs
36-
import module_reset_mps2
35+
from . import module_reset_mbed
36+
from . import module_reset_silabs
37+
from . import module_reset_mps2
3738

3839

3940
# Plugin registry instance
@@ -77,4 +78,4 @@ def get_plugin_caps(type):
7778
def print_plugin_info():
7879
""" Prints plugins' information in user friendly way
7980
"""
80-
print HOST_TEST_PLUGIN_REGISTRY
81+
print(HOST_TEST_PLUGIN_REGISTRY)

tools/host_tests/host_tests_plugins/host_test_plugins.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17+
from __future__ import print_function
1718

1819
from os import access, F_OK
1920
from sys import stdout
@@ -58,16 +59,13 @@ def execute(self, capabilitity, *args, **kwargs):
5859
def print_plugin_error(self, text):
5960
""" Function prints error in console and exits always with False
6061
"""
61-
print "Plugin error: %s::%s: %s"% (self.name, self.type, text)
62+
print("Plugin error: %s::%s: %s" % (self.name, self.type, text))
6263
return False
6364

6465
def print_plugin_info(self, text, NL=True):
6566
""" Function prints notification in console and exits always with True
6667
"""
67-
if NL:
68-
print "Plugin info: %s::%s: %s"% (self.name, self.type, text)
69-
else:
70-
print "Plugin info: %s::%s: %s"% (self.name, self.type, text),
68+
print("Plugin info: %s::%s: %s"% (self.name, self.type, text))
7169
return True
7270

7371
def print_plugin_char(self, char):

tools/host_tests/host_tests_plugins/host_test_registry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17+
from __future__ import print_function
1718

1819
class HostTestRegistry:
1920
""" Simple class used to register and store
@@ -23,7 +24,7 @@ class HostTestRegistry:
2324
PLUGINS = {} # 'Plugin Name' : Plugin Object
2425

2526
def print_error(self, text):
26-
print "Plugin load failed. Reason: %s"% text
27+
print("Plugin load failed. Reason: %s" % text)
2728

2829
def register_plugin(self, plugin):
2930
""" Registers and stores plugin inside registry for further use.

tools/host_tests/host_tests_plugins/module_copy_mbed.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17+
from __future__ import print_function
1718

1819
from shutil import copy
19-
from host_test_plugins import HostTestPluginBase
20+
from .host_test_plugins import HostTestPluginBase
2021
from time import sleep
2122

2223

@@ -32,7 +33,7 @@ def generic_mbed_copy(self, image_path, destination_disk):
3233
destination_disk += '/'
3334
try:
3435
copy(image_path, destination_disk)
35-
except Exception, e:
36+
except Exception as e:
3637
self.print_plugin_error("shutil.copy('%s', '%s')"% (image_path, destination_disk))
3738
self.print_plugin_error("Error: %s"% str(e))
3839
result = False

tools/host_tests/host_tests_plugins/module_copy_mps2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17+
from __future__ import print_function
1718

1819
import re
1920
import os, shutil
2021
from os.path import join
21-
from host_test_plugins import HostTestPluginBase
2222
from time import sleep
23+
from .host_test_plugins import HostTestPluginBase
2324

2425

2526
class HostTestPluginCopyMethod_MPS2(HostTestPluginBase):

tools/host_tests/host_tests_plugins/module_copy_shell.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17+
from __future__ import print_function
1718

1819
import os
1920
from os.path import join, basename
20-
from host_test_plugins import HostTestPluginBase
2121
from time import sleep
2222

23+
from .host_test_plugins import HostTestPluginBase
2324

2425
class HostTestPluginCopyMethod_Shell(HostTestPluginBase):
2526

0 commit comments

Comments
 (0)