mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-09 04:54:16 +00:00
debug statements hook works for non-utf8 files
This commit is contained in:
parent
5c2430e238
commit
2913408db3
2 changed files with 11 additions and 1 deletions
|
|
@ -35,7 +35,7 @@ class ImportStatementParser(ast.NodeVisitor):
|
||||||
|
|
||||||
def check_file_for_debug_statements(filename):
|
def check_file_for_debug_statements(filename):
|
||||||
try:
|
try:
|
||||||
ast_obj = ast.parse(open(filename).read(), filename=filename)
|
ast_obj = ast.parse(open(filename, 'rb').read(), filename=filename)
|
||||||
except SyntaxError:
|
except SyntaxError:
|
||||||
print('{} - Could not parse ast'.format(filename))
|
print('{} - Could not parse ast'.format(filename))
|
||||||
print()
|
print()
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import absolute_import
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import ast
|
import ast
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -77,3 +81,9 @@ def test_returns_zero_for_passing_file():
|
||||||
def test_syntaxerror_file():
|
def test_syntaxerror_file():
|
||||||
ret = debug_statement_hook([get_resource_path('cannot_parse_ast.notpy')])
|
ret = debug_statement_hook([get_resource_path('cannot_parse_ast.notpy')])
|
||||||
assert ret == 1
|
assert ret == 1
|
||||||
|
|
||||||
|
|
||||||
|
def test_non_utf8_file(tmpdir):
|
||||||
|
f_py = tmpdir.join('f.py')
|
||||||
|
f_py.write_binary('# -*- coding: cp1252 -*-\nx = "€"\n'.encode('cp1252'))
|
||||||
|
assert debug_statement_hook((f_py.strpath,)) == 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue