1111import multiprocessing
1212import multiprocessing .connection
1313import os
14- import resource
1514import shutil
1615import signal
1716import subprocess
@@ -230,14 +229,14 @@ def copy_also_copy_files():
230229def create_mutants_for_file (filename , output_path ):
231230 input_stat = os .stat (filename )
232231
233- with open (filename ) as f :
232+ with open (filename , encoding = 'utf-8' ) as f :
234233 source = f .read ()
235234
236- with open (output_path , 'w' ) as out :
235+ with open (output_path , 'w' , encoding = 'utf-8' ) as out :
237236 mutant_names , hash_by_function_name = write_all_mutants_to_file (out = out , source = source , filename = filename )
238237
239238 # validate no syntax errors of mutants
240- with open (output_path ) as f :
239+ with open (output_path , encoding = 'utf-8' ) as f :
241240 try :
242241 ast .parse (f .read ())
243242 except (IndentationError , SyntaxError ) as e :
@@ -282,7 +281,7 @@ def __init__(self, *, path):
282281
283282 def load (self ):
284283 try :
285- with open (self .meta_path ) as f :
284+ with open (self .meta_path , encoding = 'utf-8' ) as f :
286285 self .meta = json .load (f )
287286 except FileNotFoundError :
288287 return
@@ -309,7 +308,7 @@ def stop_children(self):
309308 os .kill (pid , SIGTERM )
310309
311310 def save (self ):
312- with open (self .meta_path , 'w' ) as f :
311+ with open (self .meta_path , 'w' , encoding = 'utf-8' ) as f :
313312 json .dump (dict (
314313 exit_code_by_key = self .exit_code_by_key ,
315314 hash_by_function_name = self .hash_by_function_name ,
@@ -507,6 +506,9 @@ def status_printer():
507506 last_update = [datetime (1900 , 1 , 1 )]
508507 update_threshold = timedelta (seconds = 0.1 )
509508
509+ # support the spinner chars on windows
510+ sys .__stdout__ .reconfigure (encoding = 'utf-8' )
511+
510512 def p (s , * , force_output = False ):
511513 if not force_output and (datetime .now () - last_update [0 ]) < update_threshold :
512514 return
@@ -781,7 +783,7 @@ def collect_or_load_stats(runner):
781783def load_stats ():
782784 did_load = False
783785 try :
784- with open ('mutants/mutmut-stats.json' ) as f :
786+ with open ('mutants/mutmut-stats.json' , encoding = 'utf-8' ) as f :
785787 data = json .load (f )
786788 for k , v in data .pop ('tests_by_mangled_function_name' ).items ():
787789 mutmut .tests_by_mangled_function_name [k ] |= set (v )
@@ -795,7 +797,7 @@ def load_stats():
795797
796798
797799def save_stats ():
798- with open ('mutants/mutmut-stats.json' , 'w' ) as f :
800+ with open ('mutants/mutmut-stats.json' , 'w' , encoding = 'utf-8' ) as f :
799801 json .dump (dict (
800802 tests_by_mangled_function_name = {k : list (v ) for k , v in mutmut .tests_by_mangled_function_name .items ()},
801803 duration_by_test = mutmut .duration_by_test ,
@@ -1078,6 +1080,7 @@ def _test_mutation(task: Task):
10781080 # TODO: implement timeout for windows + unix
10791081 # estimated_time_of_tests = m.estimated_time_of_tests_by_mutant[mutant_name]
10801082 # cpu_time_limit = ceil((estimated_time_of_tests + 1) * 2 + process_time()) * 10
1083+ # import resource
10811084 # resource.setrlimit(resource.RLIMIT_CPU, (cpu_time_limit, cpu_time_limit))
10821085
10831086 with CatchOutput ():
@@ -1086,7 +1089,7 @@ def _test_mutation(task: Task):
10861089 return result
10871090 # os._exit(result)
10881091 except Exception as e :
1089- with open (f'error.{ mutant_name } .log' , 'w' ) as log :
1092+ with open (f'error.{ mutant_name } .log' , 'w' , encoding = 'utf-8' ) as log :
10901093 log .write (str (e ))
10911094 log .flush ()
10921095 return - 24
@@ -1120,12 +1123,12 @@ def results(all):
11201123
11211124
11221125def read_mutants_module (path ) -> cst .Module :
1123- with open (Path ('mutants' ) / path ) as f :
1126+ with open (Path ('mutants' ) / path , encoding = 'utf-8' ) as f :
11241127 return cst .parse_module (f .read ())
11251128
11261129
11271130def read_orig_module (path ) -> cst .Module :
1128- with open (path ) as f :
1131+ with open (path , encoding = 'utf-8' ) as f :
11291132 return cst .parse_module (f .read ())
11301133
11311134
@@ -1226,7 +1229,7 @@ def apply_mutant(mutant_name):
12261229
12271230 new_module : cst .Module = orig_module .deep_replace (original_function , mutant_function ) # type: ignore
12281231
1229- with open (path , 'w' ) as f :
1232+ with open (path , 'w' , encoding = 'utf-8' ) as f :
12301233 f .write (new_module .code )
12311234
12321235
0 commit comments