@@ -80,7 +80,7 @@ def mutate_and_print(path_to_input_file: str, path_to_root: str) -> bool:
8080 cmd .append (path_to_print_ [0 ])
8181 cmd .append (path_to_print_ [1 ])
8282
83- relative_path_to_mut_html = Path (path_to_root ).relative_to ("." )
83+ relative_path_to_mut_html = Path (path_to_mut_html ).relative_to (path_to_root )
8484 path_to_mut_output = f"output/{ relative_path_to_mut_html } "
8585
8686 def copy_files_if_needed () -> None :
@@ -143,30 +143,16 @@ def copy_mutated_file() -> None:
143143 return True
144144
145145
146- def main () -> None :
147- parser = argparse .ArgumentParser ()
148-
149- parser .add_argument ("input_file" , type = str , help = "TODO" )
150- parser .add_argument ("root_path" , type = str , help = "TODO" )
151- parser .add_argument (
152- "--long" ,
153- action = "store_true" ,
154- help = "Run the fuzzer in long mode (more iterations)." ,
155- )
156-
157- args = parser .parse_args ()
158-
159- path_to_input_file = args .input_file
160- path_to_root = args .root_path
161-
146+ def fuzz_test (
147+ * , path_to_input_file : str , path_to_root : str , total_mutations : int = 20
148+ ) -> None :
162149 shutil .rmtree ("output" , ignore_errors = True )
163150 Path ("output" ).mkdir (parents = True , exist_ok = True )
164151
165- total_runs = 200 if args .long else 20
166152 success_count , failure_count = 0 , 0
167- for i in range (1 , total_runs + 1 ):
153+ for i in range (1 , total_mutations + 1 ):
168154 print ( # noqa: T201
169- f"html2pdf4doc_fuzzer print cycle #{ i } /{ total_runs } — "
155+ f"html2pdf4doc_fuzzer print cycle #{ i } /{ total_mutations } — "
170156 f"So far: 🟢{ success_count } / 🔴{ failure_count } " ,
171157 flush = True ,
172158 )
@@ -176,18 +162,44 @@ def main() -> None:
176162 else :
177163 failure_count += 1
178164
179- assert total_runs > 0
180- success_rate_percent = (success_count / total_runs ) * 100
165+ assert total_mutations > 0
166+ success_rate_percent = (success_count / total_mutations ) * 100
181167
182168 print ( # noqa: T201
183169 f"html2pdf4doc_fuzzer: finished { '✅' if failure_count == 0 else '❌' } — "
184- f"Success rate: { success_count } /{ total_runs } ({ success_rate_percent } %)" ,
170+ f"Success rate: { success_count } /{ total_mutations } ({ success_rate_percent } %)" ,
185171 flush = True ,
186172 )
187173
188174 if failure_count > 0 :
189175 sys .exit (1 )
190176
191177
178+ def main () -> None :
179+ parser = argparse .ArgumentParser ()
180+
181+ parser .add_argument ("input_file" , type = str , help = "TODO" )
182+ parser .add_argument ("root_path" , type = str , help = "TODO" )
183+ parser .add_argument (
184+ "--total-mutations" ,
185+ type = int ,
186+ choices = range (1 , 1001 ),
187+ required = True ,
188+ help = "An integer between 1 and 1000" ,
189+ )
190+
191+ args = parser .parse_args ()
192+
193+ path_to_input_file = args .input_file
194+ path_to_root = args .root_path
195+ total_mutations = args .total_mutations
196+
197+ fuzz_test (
198+ path_to_input_file = path_to_input_file ,
199+ path_to_root = path_to_root ,
200+ total_mutations = total_mutations ,
201+ )
202+
203+
192204if __name__ == "__main__" :
193205 main ()
0 commit comments