mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 19:46:54 +00:00
Add check for text file encodings
This commit is contained in:
parent
56b4a7e506
commit
69d0dfbab2
5 changed files with 58 additions and 0 deletions
17
tests/check_encoding_test.py
Normal file
17
tests/check_encoding_test.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import pytest
|
||||
|
||||
from pre_commit_hooks.check_encoding import main
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('content', 'encoding', 'expected'),
|
||||
(
|
||||
(b'Hello!', 'ascii', 0),
|
||||
(b'Hello!', 'unknown-encoding', 2),
|
||||
('Hello ☃!'.encode(), 'ascii', 1),
|
||||
),
|
||||
)
|
||||
def test_has_encoding(content, encoding, expected, tmpdir):
|
||||
path = tmpdir.join('path')
|
||||
path.write(content, 'wb')
|
||||
assert main(('--encoding', encoding, str(path))) == expected
|
||||
Loading…
Add table
Add a link
Reference in a new issue