Skip to content

Commit 8febacd

Browse files
committed
Support checking unicode TOML
1 parent 2322277 commit 8febacd

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

pre_commit_hooks/check_toml.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +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:
17-
toml.load(f)
16+
toml.load(filename)
1817
except toml.TomlDecodeError as exc:
1918
print(f'{filename}: {exc}')
2019
retval = 1

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_unicode(tmpdir):
33+
filename = tmpdir.join('f')
34+
filename.write_binary('letter = "\N{SNOWMAN}"\n'.encode())
35+
ret = main((filename.strpath,))
36+
assert ret == 0

0 commit comments

Comments
 (0)