Add check for text file encodings

This commit is contained in:
Ville Skyttä 2021-11-11 19:23:42 +02:00
parent 56b4a7e506
commit 69d0dfbab2
5 changed files with 58 additions and 0 deletions

View 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