Skip to content

Commit db59242

Browse files
committed
Specify encoding in open() call
1 parent 2322277 commit db59242

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

pre_commit_hooks/check_toml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
1313
retval = 0
1414
for filename in args.filenames:
1515
try:
16-
with open(filename) as f:
16+
with open(filename, encoding='UTF-8') as f:
1717
toml.load(f)
1818
except toml.TomlDecodeError as exc:
1919
print(f'{filename}: {exc}')

tests/check_toml_test.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pre_commit_hooks.check_toml import main
22

33

4-
def test_toml_good(tmpdir):
4+
def test_toml_bad(tmpdir):
55
filename = tmpdir.join('f')
66
filename.write("""
77
key = # INVALID
@@ -12,7 +12,7 @@ def test_toml_good(tmpdir):
1212
assert ret == 1
1313

1414

15-
def test_toml_bad(tmpdir):
15+
def test_toml_good(tmpdir):
1616
filename = tmpdir.join('f')
1717
filename.write(
1818
"""
@@ -27,3 +27,10 @@ def test_toml_bad(tmpdir):
2727
)
2828
ret = main((filename.strpath,))
2929
assert ret == 0
30+
31+
32+
def test_toml_good_non_ascii(tmpdir):
33+
filename = tmpdir.join('f')
34+
filename.write_binary('letter = "\N{SNOWMAN}"'.encode())
35+
ret = main((filename.strpath,))
36+
assert ret == 0

0 commit comments

Comments
 (0)