66
77from result import Result , ResultReader
88
9- ENHANCED_REPORT = False
9+ ENHANCED_REPORT = True
10+
1011
1112@dataclass
1213class ResultSet :
14+ """
15+ A set of results from minifying a corpus using a specific version of Python and a specific version of python-minifier
16+ """
17+
1318 python_version : str
1419 sha : str
1520
@@ -106,7 +111,16 @@ def compare_size_decrease(self, base: 'ResultSet') -> Iterable[Result]:
106111 if result .minified_size < base_result .minified_size :
107112 yield result
108113
114+
109115def result_summary (results_dir : str , python_version : str , sha : str ) -> ResultSet :
116+ """
117+ Return a summary of the results for a specific version of Python and a specific version of python-minifier
118+
119+ :param results_dir: The directory containing the results
120+ :param python_version: The version of Python
121+ :param sha: The git sha of the version of python-minifier
122+ """
123+
110124 summary = ResultSet (python_version , sha )
111125
112126 results_file_path = os .path .join (results_dir , 'results_' + python_version + '_' + sha + '.csv' )
@@ -118,7 +132,20 @@ def result_summary(results_dir: str, python_version: str, sha: str) -> ResultSet
118132
119133 return summary
120134
135+
121136def format_difference (compare : Iterable [Result ], base : Iterable [Result ]) -> str :
137+ """
138+ Return a string representing the difference between two sets of results
139+
140+ The returned string will include:
141+ - the size of the compare set
142+ - the number of new entries in the compare set that are not in the base set
143+ - and the number of entries that are in the base set but not in the compare set.
144+
145+ :param compare: The results we are interested in
146+ :param base: The results to compare against
147+ """
148+
122149 compare_set = set (result .corpus_entry for result in compare )
123150 base_set = set (result .corpus_entry for result in base )
124151
@@ -139,6 +166,18 @@ def format_difference(compare: Iterable[Result], base: Iterable[Result]) -> str:
139166
140167
141168def report (results_dir : str , minifier_ref : str , minifier_sha : str , base_ref : str , base_sha : str ) -> Iterable [str ]:
169+ """
170+ Generate a report comparing the results of two versions of python-minifier
171+
172+ The report is generated as a markdown string.
173+
174+ :param results_dir: The directory containing the results
175+ :param minifier_ref: The git ref of the version of python-minifier
176+ :param minifier_sha: The git sha of the version of python-minifier
177+ :param base_ref: The git ref of the base version of python-minifier we are comparing against
178+ :param base_sha: The git sha of the base version of python-minifier we are comparing against
179+ """
180+
142181 yield f'''
143182# Python Minifier Test Report
144183
@@ -186,14 +225,14 @@ def format_size_change_detail() -> str:
186225 return s
187226
188227 yield (
189- f'| { python_version } ' +
190- f'| { summary .valid_count } ' +
191- f'| { summary .mean_time :.3f} ({ mean_time_change :+.3f} ) ' +
192- f'| { format_size_change_detail ()} ' +
193- f'| { format_difference (summary .larger_than_original (), base_summary .larger_than_original ())} ' +
194- f'| { format_difference (summary .recursion_error (), base_summary .recursion_error ())} ' +
195- f'| { format_difference (summary .unstable_minification (), base_summary .unstable_minification ())} ' +
196- f'| { format_difference (summary .exception (), base_summary .exception ())} '
228+ f'| { python_version } ' +
229+ f'| { summary .valid_count } ' +
230+ f'| { summary .mean_time :.3f} ({ mean_time_change :+.3f} ) ' +
231+ f'| { format_size_change_detail ()} ' +
232+ f'| { format_difference (summary .larger_than_original (), base_summary .larger_than_original ())} ' +
233+ f'| { format_difference (summary .recursion_error (), base_summary .recursion_error ())} ' +
234+ f'| { format_difference (summary .unstable_minification (), base_summary .unstable_minification ())} ' +
235+ f'| { format_difference (summary .exception (), base_summary .exception ())} '
197236 )
198237
199238 if ENHANCED_REPORT :
@@ -242,6 +281,7 @@ def format_size_change_detail() -> str:
242281 for entry in sorted (summary .entries .values (), key = lambda entry : entry .time , reverse = True )[:10 ]:
243282 yield f'| { entry .corpus_entry } | { entry .original_size } | { entry .minified_size } | { entry .time :.3f} |'
244283
284+
245285def main ():
246286 parser = argparse .ArgumentParser (description = 'Generate a test report for a given python-minifier ref' )
247287 parser .add_argument ('results_dir' , type = str , help = 'Path to results directory' , default = 'results' )
0 commit comments