From e229ebdcc4977752a061fb6db37293b21c453ad1 Mon Sep 17 00:00:00 2001 From: Daniel Flook Date: Mon, 14 Oct 2024 16:12:19 +0100 Subject: [PATCH] Resolve lint warnings --- corpus_test/generate_report.py | 39 ++++++++++++++++----------------- corpus_test/generate_results.py | 10 ++++----- corpus_test/result.py | 20 ++++++++--------- 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/corpus_test/generate_report.py b/corpus_test/generate_report.py index cea21f9a..336491f8 100644 --- a/corpus_test/generate_report.py +++ b/corpus_test/generate_report.py @@ -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)) @@ -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]: """ @@ -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())} ' + diff --git a/corpus_test/generate_results.py b/corpus_test/generate_results.py index 01e0fd51..ade3fce1 100644 --- a/corpus_test/generate_results.py +++ b/corpus_test/generate_results.py @@ -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 @@ -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' @@ -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: @@ -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) diff --git a/corpus_test/result.py b/corpus_test/result.py index b02e4ac1..61320f0e 100644 --- a/corpus_test/result.py +++ b/corpus_test/result.py @@ -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): @@ -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() + )