Support checking unicode TOML

This commit is contained in:
Max Rozentsveyg 2020-05-16 20:49:10 -04:00
parent 2322277afd
commit 8febacdfed
2 changed files with 10 additions and 4 deletions

View file

@ -13,8 +13,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
retval = 0 retval = 0
for filename in args.filenames: for filename in args.filenames:
try: try:
with open(filename) as f: toml.load(filename)
toml.load(f)
except toml.TomlDecodeError as exc: except toml.TomlDecodeError as exc:
print(f'{filename}: {exc}') print(f'{filename}: {exc}')
retval = 1 retval = 1

View file

@ -1,7 +1,7 @@
from pre_commit_hooks.check_toml import main from pre_commit_hooks.check_toml import main
def test_toml_good(tmpdir): def test_toml_bad(tmpdir):
filename = tmpdir.join('f') filename = tmpdir.join('f')
filename.write(""" filename.write("""
key = # INVALID key = # INVALID
@ -12,7 +12,7 @@ key = # INVALID
assert ret == 1 assert ret == 1
def test_toml_bad(tmpdir): def test_toml_good(tmpdir):
filename = tmpdir.join('f') filename = tmpdir.join('f')
filename.write( filename.write(
""" """
@ -27,3 +27,10 @@ dob = 1979-05-27T07:32:00-08:00 # First class dates
) )
ret = main((filename.strpath,)) ret = main((filename.strpath,))
assert ret == 0 assert ret == 0
def test_toml_good_unicode(tmpdir):
filename = tmpdir.join('f')
filename.write_binary('letter = "\N{SNOWMAN}"\n'.encode())
ret = main((filename.strpath,))
assert ret == 0