dist/tools/compile_and_test_for_board: use f-strings where possible
This commit is contained in:
parent
9254cffdda
commit
5204c29890
@ -182,10 +182,10 @@ def check_is_board(riotdir, board):
|
|||||||
:returns: board name
|
:returns: board name
|
||||||
"""
|
"""
|
||||||
if board == 'common':
|
if board == 'common':
|
||||||
raise ValueError("'%s' is not a board" % board)
|
raise ValueError(f"'{board}' is not a board")
|
||||||
board_dir = os.path.join(riotdir, 'boards', board)
|
board_dir = os.path.join(riotdir, 'boards', board)
|
||||||
if not os.path.isdir(board_dir):
|
if not os.path.isdir(board_dir):
|
||||||
raise ValueError("Cannot find '%s' in %s/boards" % (board, riotdir))
|
raise ValueError(f"Cannot find '{board}' in {riotdir}/boards")
|
||||||
return board
|
return board
|
||||||
|
|
||||||
|
|
||||||
@ -254,7 +254,7 @@ class RIOTApplication():
|
|||||||
logging.basicConfig(stream=self.log_stream)
|
logging.basicConfig(stream=self.log_stream)
|
||||||
else:
|
else:
|
||||||
self.testcase = None
|
self.testcase = None
|
||||||
self.logger = logging.getLogger('%s.%s' % (board, appdir))
|
self.logger = logging.getLogger(f'{board}.{appdir}')
|
||||||
|
|
||||||
# Currently not handling absolute directories or outside of RIOT
|
# Currently not handling absolute directories or outside of RIOT
|
||||||
assert is_in_directory(self.resultdir, resultdir), \
|
assert is_in_directory(self.resultdir, resultdir), \
|
||||||
@ -392,7 +392,7 @@ class RIOTApplication():
|
|||||||
create_directory(self.resultdir, clean=True)
|
create_directory(self.resultdir, clean=True)
|
||||||
self._skip(
|
self._skip(
|
||||||
'disabled_has_no_tests',
|
'disabled_has_no_tests',
|
||||||
"{} has no tests".format(self.appdir)
|
f"{self.appdir} has no tests"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -422,7 +422,7 @@ class RIOTApplication():
|
|||||||
else:
|
else:
|
||||||
self._skip(
|
self._skip(
|
||||||
'skip.no_test',
|
'skip.no_test',
|
||||||
"{} has no tests".format(self.appdir)
|
f"{self.appdir} has no tests"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.logger.info('Success')
|
self.logger.info('Success')
|
||||||
@ -479,7 +479,7 @@ class RIOTApplication():
|
|||||||
|
|
||||||
# Run setup-tasks, output is only kept in case of error
|
# Run setup-tasks, output is only kept in case of error
|
||||||
for taskname, taskargs in setuptasks.items():
|
for taskname, taskargs in setuptasks.items():
|
||||||
taskname = '%s.%s' % (name, taskname)
|
taskname = f'{name}.{taskname}'
|
||||||
self.logger.info('Run %s', taskname)
|
self.logger.info('Run %s', taskname)
|
||||||
try:
|
try:
|
||||||
self.make(taskargs)
|
self.make(taskargs)
|
||||||
@ -503,7 +503,7 @@ class RIOTApplication():
|
|||||||
Returns `output` if it is there, None if not.
|
Returns `output` if it is there, None if not.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with open(self._outfile('%s.success' % name),
|
with open(self._outfile(f'{name}.success'),
|
||||||
encoding='utf-8') as outputfd:
|
encoding='utf-8') as outputfd:
|
||||||
self.logger.info('Nothing to be done for %s', name)
|
self.logger.info('Nothing to be done for %s', name)
|
||||||
return outputfd.read()
|
return outputfd.read()
|
||||||
@ -515,7 +515,7 @@ class RIOTApplication():
|
|||||||
"""Handle exception during make step `name`."""
|
"""Handle exception during make step `name`."""
|
||||||
output = ' '.join(err.cmd) + '\n'
|
output = ' '.join(err.cmd) + '\n'
|
||||||
output += err.output + '\n'
|
output += err.output + '\n'
|
||||||
output += 'Return value: %s\n' % err.returncode
|
output += f'Return value: {err.returncode}\n'
|
||||||
outfile = self._write_resultfile(name, 'failed', output)
|
outfile = self._write_resultfile(name, 'failed', output)
|
||||||
|
|
||||||
self.logger.warning(output)
|
self.logger.warning(output)
|
||||||
@ -523,10 +523,10 @@ class RIOTApplication():
|
|||||||
if self.testcase:
|
if self.testcase:
|
||||||
self.testcase.stderr += err.output + '\n'
|
self.testcase.stderr += err.output + '\n'
|
||||||
if name == "test":
|
if name == "test":
|
||||||
self.testcase.add_failure_info("{} failed".format(err.cmd),
|
self.testcase.add_failure_info(f"{err.cmd} failed",
|
||||||
err.output)
|
err.output)
|
||||||
else:
|
else:
|
||||||
self.testcase.add_error_info("{} had an error".format(err.cmd),
|
self.testcase.add_error_info(f"{err.cmd} had an error",
|
||||||
err.output)
|
err.output)
|
||||||
raise ErrorInTest(name, self, outfile)
|
raise ErrorInTest(name, self, outfile)
|
||||||
|
|
||||||
@ -537,7 +537,7 @@ class RIOTApplication():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Delete previous status files
|
# Delete previous status files
|
||||||
resultfiles = glob.glob(self._outfile('%s.*' % name))
|
resultfiles = glob.glob(self._outfile(f'{name}.*'))
|
||||||
for resultfile in resultfiles:
|
for resultfile in resultfiles:
|
||||||
try:
|
try:
|
||||||
os.remove(resultfile)
|
os.remove(resultfile)
|
||||||
@ -545,7 +545,7 @@ class RIOTApplication():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# Create new file
|
# Create new file
|
||||||
filename = '%s.%s' % (name, status)
|
filename = f'{name}.{status}'
|
||||||
outfile = self._outfile(filename)
|
outfile = self._outfile(filename)
|
||||||
|
|
||||||
with open(outfile, 'w+', encoding='utf-8',
|
with open(outfile, 'w+', encoding='utf-8',
|
||||||
@ -595,9 +595,9 @@ def _test_failed_summary(errors, relpathstart=None):
|
|||||||
|
|
||||||
summary = ''
|
summary = ''
|
||||||
for step, errs in sorted(errors_dict.items()):
|
for step, errs in sorted(errors_dict.items()):
|
||||||
summary += 'Failures during %s:\n' % step
|
summary += f'Failures during {step}:\n'
|
||||||
for appdir, errorfile in errs:
|
for appdir, errorfile in errs:
|
||||||
summary += '- [%s](%s)\n' % (appdir, errorfile)
|
summary += f'- [{appdir}]({errorfile})\n'
|
||||||
# Separate sections with a new line
|
# Separate sections with a new line
|
||||||
summary += '\n'
|
summary += '\n'
|
||||||
|
|
||||||
@ -755,7 +755,7 @@ def main(args):
|
|||||||
with open(report_file, "w+", encoding="utf-8") as report:
|
with open(report_file, "w+", encoding="utf-8") as report:
|
||||||
junit_xml.TestSuite.to_file(
|
junit_xml.TestSuite.to_file(
|
||||||
report,
|
report,
|
||||||
[junit_xml.TestSuite('compile_and_test_for_{}'.format(board),
|
[junit_xml.TestSuite(f'compile_and_test_for_{board}',
|
||||||
[app.testcase for app in applications])]
|
[app.testcase for app in applications])]
|
||||||
)
|
)
|
||||||
if num_errors:
|
if num_errors:
|
||||||
|
|||||||
@ -10,7 +10,7 @@ def test_help_message():
|
|||||||
script = 'compile_and_test_for_board.py'
|
script = 'compile_and_test_for_board.py'
|
||||||
|
|
||||||
# Read the help message from executing the script
|
# Read the help message from executing the script
|
||||||
help_bytes = subprocess.check_output(['./%s' % script, '--help'])
|
help_bytes = subprocess.check_output([f'./{script}', '--help'])
|
||||||
help_msg = help_bytes.decode('utf-8')
|
help_msg = help_bytes.decode('utf-8')
|
||||||
|
|
||||||
docstring = compile_and_test_for_board.__doc__
|
docstring = compile_and_test_for_board.__doc__
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user