Skip to content

Commit

Permalink
Resolve lint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dflook committed Oct 14, 2024
1 parent ceda80f commit e229ebd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
39 changes: 19 additions & 20 deletions corpus_test/generate_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def format_difference(compare: Iterable[Result], base: Iterable[Result]) -> str:
:param base: The results to compare against
"""

compare_set = set(result.corpus_entry for result in compare)
base_set = set(result.corpus_entry for result in base)
compare_set = {result.corpus_entry for result in compare}
base_set = {result.corpus_entry for result in base}

s = str(len(compare_set))

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

def format_size_change_detail(summary, base_summary) -> str:
mean_percent_of_original_change = summary.mean_percent_of_original - base_summary.mean_percent_of_original

s = f'{summary.mean_percent_of_original:.3f}% ({mean_percent_of_original_change:+.3f}%'

got_bigger_count = len(list(summary.compare_size_increase(base_summary)))
got_smaller_count = len(list(summary.compare_size_decrease(base_summary)))

if got_bigger_count > 0:
s += f', {got_bigger_count} :chart_with_upwards_trend:'
if got_smaller_count > 0:
s += f', {got_smaller_count} :chart_with_downwards_trend:'

s += ')'

return s

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

mean_time_change = summary.mean_time - base_summary.mean_time

def format_size_change_detail() -> str:
mean_percent_of_original_change = summary.mean_percent_of_original - base_summary.mean_percent_of_original

s = f'{summary.mean_percent_of_original:.3f}% ({mean_percent_of_original_change:+.3f}%'

got_bigger_count = len(list(summary.compare_size_increase(base_summary)))
got_smaller_count = len(list(summary.compare_size_decrease(base_summary)))

if got_bigger_count > 0:
s += f', {got_bigger_count} :chart_with_upwards_trend:'
if got_smaller_count > 0:
s += f', {got_smaller_count} :chart_with_downwards_trend:'

s += ')'

return s

yield (
f'| {python_version} ' +
f'| {summary.valid_count} ' +
f'| {summary.mean_time:.3f} ({mean_time_change:+.3f}) ' +
f'| {format_size_change_detail()} ' +
f'| {format_size_change_detail(summary, base_summary)} ' +
f'| {format_difference(summary.larger_than_original(), base_summary.larger_than_original())} ' +
f'| {format_difference(summary.recursion_error(), base_summary.recursion_error())} ' +
f'| {format_difference(summary.unstable_minification(), base_summary.unstable_minification())} ' +
Expand Down
10 changes: 5 additions & 5 deletions corpus_test/generate_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from result import Result, ResultWriter

try:
RE = RecursionError
RError = RecursionError
except NameError:
# Python 2
class RE(Exception):
class RError(Exception):
pass


Expand Down Expand Up @@ -46,7 +46,7 @@ def minify_corpus_entry(corpus_path, corpus_entry):

result.outcome = 'Minified'

except RE:
except RError:
# Source is too deep
result.outcome = 'RecursionError'

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

except AssertionError as assertion_error:
except AssertionError:
result.outcome = 'Exception: AssertionError'

except Exception as exception:
Expand Down Expand Up @@ -113,7 +113,7 @@ def corpus_test(corpus_path, results_path, sha, regenerate_results):
if entry in result_writer:
continue

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

result = minify_corpus_entry(corpus_path, entry)
result_writer.write(result)
Expand Down
20 changes: 10 additions & 10 deletions corpus_test/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __init__(self, results_path):
def __enter__(self):
self.results = open(self._results_path, 'r')
header = self.results.readline()
assert header == 'corpus_entry,original_size,minified_size,time,result\n' or header == ''
assert header in ['corpus_entry,original_size,minified_size,time,result\n', '']
return self

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

if line == '':
raise StopIteration
else:
result_line = line.split(',')
return Result(
result_line[0],
int(result_line[1]),
int(result_line[2]),
float(result_line[3]),
result_line[4].rstrip()
)

result_line = line.split(',')
return Result(
result_line[0],
int(result_line[1]),
int(result_line[2]),
float(result_line[3]),
result_line[4].rstrip()
)

0 comments on commit e229ebd

Please sign in to comment.