From e72c9fb5a9ff2547ecd6bf52d3a5b2a4fea5a1a2 Mon Sep 17 00:00:00 2001 From: Max R Date: Sun, 15 Jun 2025 20:42:08 -0400 Subject: [PATCH] Fix encoding issue on Windows --- sync_pre_commit_deps.py | 2 +- tests/sync_pre_commit_deps_test.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sync_pre_commit_deps.py b/sync_pre_commit_deps.py index fdc28ec..9897087 100644 --- a/sync_pre_commit_deps.py +++ b/sync_pre_commit_deps.py @@ -47,7 +47,7 @@ def main(argv: Sequence[str] | None = None) -> int: yaml.preserve_quotes = True yaml.indent(yaml_mapping, yaml_sequence, yaml_offset) - with open(filename) as f: + with open(filename, encoding='utf-8') as f: loaded = yaml.load(f) # TODO - validate schema? diff --git a/tests/sync_pre_commit_deps_test.py b/tests/sync_pre_commit_deps_test.py index 8f5517a..c12c13d 100644 --- a/tests/sync_pre_commit_deps_test.py +++ b/tests/sync_pre_commit_deps_test.py @@ -35,15 +35,25 @@ ' - mypy==0.123\n', id='local hook shadows supported lib', ), + pytest.param( + 'repos:\n' + '- repo: https://github.com/psf/black\n' + ' rev: 23.3.0\n' + ' hooks:\n' + ' - name: \N{SNOWMAN} black\n' + ' id: black\n', + id='unicode no-op', + ), ), ) def test_main_noop(tmpdir, s): cfg = tmpdir.join('.pre-commit-config.yaml') - cfg.write(s) + cfg.write_binary(s.encode()) assert not main((str(cfg),)) - assert cfg.read() == s + with open(cfg, encoding='utf-8') as f: + assert f.read() == s def test_main_writes_all(tmpdir):