Skip to content

Commit e229ebd

Browse files
committed
Resolve lint warnings
1 parent ceda80f commit e229ebd

3 files changed

Lines changed: 34 additions & 35 deletions

File tree

corpus_test/generate_report.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ def format_difference(compare: Iterable[Result], base: Iterable[Result]) -> str:
165165
:param base: The results to compare against
166166
"""
167167

168-
compare_set = set(result.corpus_entry for result in compare)
169-
base_set = set(result.corpus_entry for result in base)
168+
compare_set = {result.corpus_entry for result in compare}
169+
base_set = {result.corpus_entry for result in base}
170170

171171
s = str(len(compare_set))
172172

@@ -293,6 +293,22 @@ def report_slowest(results_dir: str, python_versions: str, minifier_sha: str) ->
293293
for entry in sorted(summary.entries.values(), key=lambda entry: entry.time, reverse=True)[:10]:
294294
yield f'| {entry.corpus_entry} | {entry.original_size} | {entry.minified_size} | {entry.time:.3f} |'
295295

296+
def format_size_change_detail(summary, base_summary) -> str:
297+
mean_percent_of_original_change = summary.mean_percent_of_original - base_summary.mean_percent_of_original
298+
299+
s = f'{summary.mean_percent_of_original:.3f}% ({mean_percent_of_original_change:+.3f}%'
300+
301+
got_bigger_count = len(list(summary.compare_size_increase(base_summary)))
302+
got_smaller_count = len(list(summary.compare_size_decrease(base_summary)))
303+
304+
if got_bigger_count > 0:
305+
s += f', {got_bigger_count} :chart_with_upwards_trend:'
306+
if got_smaller_count > 0:
307+
s += f', {got_smaller_count} :chart_with_downwards_trend:'
308+
309+
s += ')'
310+
311+
return s
296312

297313
def report(results_dir: str, minifier_ref: str, minifier_sha: str, base_ref: str, base_sha: str) -> Iterable[str]:
298314
"""
@@ -336,28 +352,11 @@ def report(results_dir: str, minifier_ref: str, minifier_sha: str, base_ref: str
336352

337353
mean_time_change = summary.mean_time - base_summary.mean_time
338354

339-
def format_size_change_detail() -> str:
340-
mean_percent_of_original_change = summary.mean_percent_of_original - base_summary.mean_percent_of_original
341-
342-
s = f'{summary.mean_percent_of_original:.3f}% ({mean_percent_of_original_change:+.3f}%'
343-
344-
got_bigger_count = len(list(summary.compare_size_increase(base_summary)))
345-
got_smaller_count = len(list(summary.compare_size_decrease(base_summary)))
346-
347-
if got_bigger_count > 0:
348-
s += f', {got_bigger_count} :chart_with_upwards_trend:'
349-
if got_smaller_count > 0:
350-
s += f', {got_smaller_count} :chart_with_downwards_trend:'
351-
352-
s += ')'
353-
354-
return s
355-
356355
yield (
357356
f'| {python_version} ' +
358357
f'| {summary.valid_count} ' +
359358
f'| {summary.mean_time:.3f} ({mean_time_change:+.3f}) ' +
360-
f'| {format_size_change_detail()} ' +
359+
f'| {format_size_change_detail(summary, base_summary)} ' +
361360
f'| {format_difference(summary.larger_than_original(), base_summary.larger_than_original())} ' +
362361
f'| {format_difference(summary.recursion_error(), base_summary.recursion_error())} ' +
363362
f'| {format_difference(summary.unstable_minification(), base_summary.unstable_minification())} ' +

corpus_test/generate_results.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from result import Result, ResultWriter
1212

1313
try:
14-
RE = RecursionError
14+
RError = RecursionError
1515
except NameError:
1616
# Python 2
17-
class RE(Exception):
17+
class RError(Exception):
1818
pass
1919

2020

@@ -46,7 +46,7 @@ def minify_corpus_entry(corpus_path, corpus_entry):
4646

4747
result.outcome = 'Minified'
4848

49-
except RE:
49+
except RError:
5050
# Source is too deep
5151
result.outcome = 'RecursionError'
5252

@@ -60,7 +60,7 @@ def minify_corpus_entry(corpus_path, corpus_entry):
6060
result.time = end_time - start_time
6161
result.outcome = 'UnstableMinification'
6262

63-
except AssertionError as assertion_error:
63+
except AssertionError:
6464
result.outcome = 'Exception: AssertionError'
6565

6666
except Exception as exception:
@@ -113,7 +113,7 @@ def corpus_test(corpus_path, results_path, sha, regenerate_results):
113113
if entry in result_writer:
114114
continue
115115

116-
logging.debug('Corpus entry [' + entry + ']')
116+
logging.debug('Corpus entry [%s]', entry)
117117

118118
result = minify_corpus_entry(corpus_path, entry)
119119
result_writer.write(result)

corpus_test/result.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(self, results_path):
7979
def __enter__(self):
8080
self.results = open(self._results_path, 'r')
8181
header = self.results.readline()
82-
assert header == 'corpus_entry,original_size,minified_size,time,result\n' or header == ''
82+
assert header in ['corpus_entry,original_size,minified_size,time,result\n', '']
8383
return self
8484

8585
def __exit__(self, exc_type, exc_val, exc_tb):
@@ -99,12 +99,12 @@ def __next__(self):
9999

100100
if line == '':
101101
raise StopIteration
102-
else:
103-
result_line = line.split(',')
104-
return Result(
105-
result_line[0],
106-
int(result_line[1]),
107-
int(result_line[2]),
108-
float(result_line[3]),
109-
result_line[4].rstrip()
110-
)
102+
103+
result_line = line.split(',')
104+
return Result(
105+
result_line[0],
106+
int(result_line[1]),
107+
int(result_line[2]),
108+
float(result_line[3]),
109+
result_line[4].rstrip()
110+
)

0 commit comments

Comments
 (0)