Skip to content

Commit 63273fc

Browse files
author
Julian Lettner
committed
[NFC][lit] Cleanup code using string interpolation
LLVM now requires Python 3.6, so we can use string interpolation to make code more readable.
1 parent cbed865 commit 63273fc

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

llvm/utils/lit/lit/main.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,12 @@ def filter_by_shard(tests, run, shards, lit_config):
179179
# For clarity, generate a preview of the first few test indices in the shard
180180
# to accompany the arithmetic expression.
181181
preview_len = 3
182-
preview = ", ".join([str(i + 1) for i in test_ixs[:preview_len]])
182+
preview = ', '.join([str(i + 1) for i in test_ixs[:preview_len]])
183183
if len(test_ixs) > preview_len:
184-
preview += ", ..."
185-
# TODO(python3): string interpolation
186-
msg = 'Selecting shard {run}/{shards} = size {sel_tests}/{total_tests} = ' \
187-
'tests #({shards}*k)+{run} = [{preview}]'.format(
188-
run=run, shards=shards, sel_tests=len(selected_tests),
189-
total_tests=len(tests), preview=preview)
184+
preview += ', ...'
185+
msg = f'Selecting shard {run}/{shards} = ' \
186+
f'size {len(selected_tests)}/{len(tests)} = ' \
187+
f'tests #({shards}*k)+{run} = [{preview}]'
190188
lit_config.note(msg)
191189
return selected_tests
192190

llvm/utils/lit/lit/reports.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,17 @@ def _write_testsuite(self, file, suite, tests):
104104
failures = sum(1 for t in tests if t.isFailure())
105105

106106
name = suite.config.name.replace('.', '-')
107-
# file.write(f'<testsuite name={quo(name)} tests="{len(tests)}" failures="{failures}" skipped="{skipped}">\n')
108-
file.write('<testsuite name={name} tests="{tests}" failures="{failures}" skipped="{skipped}">\n'.format(
109-
name=quo(name), tests=len(tests), failures=failures, skipped=skipped))
107+
file.write(f'<testsuite name={quo(name)} tests="{len(tests)}" failures="{failures}" skipped="{skipped}">\n')
110108
for test in tests:
111109
self._write_test(file, test, name)
112110
file.write('</testsuite>\n')
113111

114112
def _write_test(self, file, test, suite_name):
115113
path = '/'.join(test.path_in_suite[:-1]).replace('.', '_')
116-
# class_name = f'{suite_name}.{path or suite_name}'
117-
class_name = suite_name + '.' + (path or suite_name)
114+
class_name = f'{suite_name}.{path or suite_name}'
118115
name = test.path_in_suite[-1]
119116
time = test.result.elapsed or 0.0
120-
# file.write(f'<testcase classname={quo(class_name)} name={quo(name)} time="{time:.2f}"')
121-
file.write('<testcase classname={class_name} name={name} time="{time:.2f}"'.format(
122-
class_name=quo(class_name), name=quo(name), time=time))
117+
file.write(f'<testcase classname={quo(class_name)} name={quo(name)} time="{time:.2f}"')
123118

124119
if test.isFailure():
125120
file.write('>\n <failure><![CDATA[')
@@ -140,9 +135,7 @@ def _write_test(self, file, test, suite_name):
140135
file.write(']]></failure>\n</testcase>\n')
141136
elif test.result.code in self.skipped_codes:
142137
reason = self._get_skip_reason(test)
143-
# file.write(f'>\n <skipped message={quo(reason)}/>\n</testcase>\n')
144-
file.write('>\n <skipped message={reason}/>\n</testcase>\n'.format(
145-
reason=quo(reason)))
138+
file.write(f'>\n <skipped message={quo(reason)}/>\n</testcase>\n')
146139
else:
147140
file.write('/>\n')
148141

0 commit comments

Comments
 (0)