pre-commit-hooks/tests/check_encoding_test.py
2021-11-11 19:26:18 +02:00

17 lines
456 B
Python

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