Skip to content

Commit c7b38fb

Browse files
committed
Run CI tests also on windows
1 parent 8ed5a9c commit c7b38fb

File tree

4 files changed

+22
-19
lines changed

4 files changed

+22
-19
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ on: [push, pull_request]
44

55
jobs:
66
tests:
7-
name: Test Python ${{ matrix.python-version }}
8-
# Todo: Revert to ubuntu-latest when Python 3.7 support no longer needed
9-
runs-on: ubuntu-22.04
7+
name: Test ${{ matrix.os }} - ${{ matrix.python-version }}
8+
runs-on: ${{ matrix.os }}
109
strategy:
1110
fail-fast: false
1211
matrix:
1312
python-version: ["3.13", "3.12", "3.11", "3.10", "3.9"]
13+
os: [ubuntu-latest, windows-latest]
1414
steps:
1515
- name: Checkout
1616
uses: actions/checkout@v3

e2e_projects/config/tests/test_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ def test_max_stack_depth():
2121
def test_data_exists():
2222
path = (Path("data") / "data.json").resolve()
2323
assert path.exists()
24-
with open(path) as f:
24+
with open(path, encoding='utf-8') as f:
2525
data = json.load(f)
2626
assert data['comment'] == 'this should be copied to the mutants folder'

mutmut/__main__.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import multiprocessing
1212
import multiprocessing.connection
1313
import os
14-
import resource
1514
import shutil
1615
import signal
1716
import subprocess
@@ -230,14 +229,14 @@ def copy_also_copy_files():
230229
def 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):
781783
def 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

797799
def 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

11221125
def 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

11271130
def 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

tests/e2e/test_e2e_result_snapshots.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ def read_all_stats_for_project(project_path: Path) -> dict[str, dict]:
2929
continue
3030
data = SourceFileMutationData(path=p)
3131
data.load()
32-
stats[str(data.meta_path)] = data.exit_code_by_key
32+
stats[str(data.meta_path.as_posix())] = data.exit_code_by_key
3333

3434
return stats
3535

3636

3737
def read_json_file(path: Path):
38-
with open(path, 'r') as file:
38+
with open(path, 'r', encoding='utf-8') as file:
3939
return json.load(file)
4040

4141

4242
def write_json_file(path: Path, data: Any):
43-
with open(path, 'w') as file:
43+
with open(path, 'w', encoding='utf-8') as file:
4444
json.dump(data, file, indent=2)
4545

4646

0 commit comments

Comments
 (0)