Skip to content

Commit 1dd39fb

Browse files
committed
Python2+3: mbed test --compile
1 parent c93a2bf commit 1dd39fb

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

tools/test.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
1919
TEST BUILD & RUN
2020
"""
21+
from __future__ import print_function, division, absolute_import
2122
import sys
2223
import os
2324
import json
@@ -36,8 +37,8 @@
3637
from tools.targets import TARGET_MAP
3738
from tools.utils import mkdir, ToolException, NotSupportedException, args_error
3839
from tools.test_exporters import ReportExporter, ResultExporterType
39-
from utils import argparse_filestring_type, argparse_lowercase_type, argparse_many
40-
from utils import argparse_dir_not_parent
40+
from tools.utils import argparse_filestring_type, argparse_lowercase_type, argparse_many
41+
from tools.utils import argparse_dir_not_parent
4142
from tools.toolchains import mbedToolchain, TOOLCHAIN_PATHS, TOOLCHAIN_CLASSES
4243
from tools.settings import CLI_COLOR_MAP
4344

@@ -164,7 +165,8 @@
164165
if fnmatch.fnmatch(testname, name):
165166
tests[testname] = test
166167
else:
167-
print "[Warning] Test with name '%s' was not found in the available tests" % (name)
168+
print("[Warning] Test with name '%s' was not found in the "
169+
"available tests" % (name))
168170
else:
169171
tests = all_tests
170172

@@ -211,18 +213,18 @@
211213
build_profile=profile)
212214

213215
library_build_success = True
214-
except ToolException, e:
216+
except ToolException as e:
215217
# ToolException output is handled by the build log
216218
pass
217-
except NotSupportedException, e:
219+
except NotSupportedException as e:
218220
# NotSupportedException is handled by the build log
219221
pass
220-
except Exception, e:
222+
except Exception as e:
221223
# Some other exception occurred, print the error message
222-
print e
224+
print(e)
223225

224226
if not library_build_success:
225-
print "Failed to build library"
227+
print("Failed to build library")
226228
else:
227229
# Build all the tests
228230

@@ -252,9 +254,9 @@
252254
try:
253255
with open(options.test_spec, 'w') as f:
254256
f.write(json.dumps(test_spec_data, indent=2))
255-
except IOError, e:
256-
print "[ERROR] Error writing test spec to file"
257-
print e
257+
except IOError as e:
258+
print("[ERROR] Error writing test spec to file")
259+
print(e)
258260

259261
# If a path to a JUnit build report spec is provided, write it to a file
260262
if options.build_report_junit:
@@ -264,7 +266,7 @@
264266
# Print memory map summary on screen
265267
if build_report:
266268
print
267-
print print_build_memory_usage(build_report)
269+
print(print_build_memory_usage(build_report))
268270

269271
print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")
270272
status = print_report_exporter.report(build_report)
@@ -276,13 +278,13 @@
276278
else:
277279
sys.exit(1)
278280

279-
except KeyboardInterrupt, e:
280-
print "\n[CTRL+c] exit"
281-
except ConfigException, e:
281+
except KeyboardInterrupt as e:
282+
print("\n[CTRL+c] exit")
283+
except ConfigException as e:
282284
# Catching ConfigException here to prevent a traceback
283-
print "[ERROR] %s" % str(e)
284-
except Exception,e:
285+
print("[ERROR] %s" % str(e))
286+
except Exception as e:
285287
import traceback
286288
traceback.print_exc(file=sys.stdout)
287-
print "[ERROR] %s" % str(e)
289+
print("[ERROR] %s" % str(e))
288290
sys.exit(1)

tools/test_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import datetime
3030
import threading
3131
import ctypes
32+
import functools
3233
from colorama import Fore, Back, Style
3334
from prettytable import PrettyTable
3435
from copy import copy
@@ -52,7 +53,7 @@
5253
from tools.utils import NotSupportedException
5354
from tools.utils import construct_enum
5455
from tools.memap import MemapParser
55-
from tools.targets import TARGET_MAP
56+
from tools.targets import TARGET_MAP, Target
5657
import tools.test_configs as TestConfig
5758
from tools.test_db import BaseDBAccess
5859
from tools.build_api import build_project, build_mbed_libs, build_lib
@@ -2216,7 +2217,7 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
22162217
execution_directory = "."
22172218
base_path = norm_relative_path(build_path, execution_directory)
22182219

2219-
target_name = target if isinstance(target, str) else target.name
2220+
target_name = target.name if isinstance(target, Target) else target
22202221
cfg, _, _ = get_config(base_source_paths, target_name, toolchain_name)
22212222

22222223
baud_rate = 9600

tools/toolchains/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ def scan_repository(self, path):
795795

796796
def copy_files(self, files_paths, trg_path, resources=None, rel_path=None):
797797
# Handle a single file
798-
if isinstance(files_paths, list):
798+
if not isinstance(files_paths, list):
799799
files_paths = [files_paths]
800800

801801
for source in files_paths:
@@ -1291,7 +1291,6 @@ def get_config_header(self):
12911291
self.config_file = None # this means "config file not present"
12921292
changed = True
12931293
elif crt_data != prev_data: # different content of config file
1294-
print("changed!")
12951294
with open(self.config_file, "w") as f:
12961295
f.write(crt_data)
12971296
changed = True

0 commit comments

Comments
 (0)