Skip to content

Commit

Permalink
Specify encoding in open() call
Browse files Browse the repository at this point in the history
  • Loading branch information
mxr committed May 17, 2020
1 parent 2322277 commit 9fd5b16
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pre_commit_hooks/check_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
retval = 0
for filename in args.filenames:
try:
with open(filename) as f:
with open(filename, encoding='UTF-8') as f:
toml.load(f)
except toml.TomlDecodeError as exc:
print(f'{filename}: {exc}')
Expand Down
11 changes: 9 additions & 2 deletions tests/check_toml_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pre_commit_hooks.check_toml import main


def test_toml_good(tmpdir):
def test_toml_bad(tmpdir):
filename = tmpdir.join('f')
filename.write("""
key = # INVALID
Expand All @@ -12,7 +12,7 @@ def test_toml_good(tmpdir):
assert ret == 1


def test_toml_bad(tmpdir):
def test_toml_good(tmpdir):
filename = tmpdir.join('f')
filename.write(
"""
Expand All @@ -27,3 +27,10 @@ def test_toml_bad(tmpdir):
)
ret = main((filename.strpath,))
assert ret == 0


def test_toml_good_unicode(tmpdir):
filename = tmpdir.join('f')
filename.write_binary('letter = "\N{SNOWMAN}"'.encode())
ret = main((filename.strpath,))
assert ret == 0

0 comments on commit 9fd5b16

Please sign in to comment.