mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 03:56:54 +00:00
Adds remove-tabs hook
Inpired by initial work done by Lucas-C: https://github.com/Lucas-C/pre-commit-hooks
This commit is contained in:
parent
b7abd18ceb
commit
f7da3dff91
4 changed files with 91 additions and 0 deletions
31
tests/remove_tabs_test.py
Normal file
31
tests/remove_tabs_test.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.remove_tabs import main as remove_tabs
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
('input_s', 'expected'),
|
||||
(
|
||||
('foo \t\nbar', 'foo \nbar'),
|
||||
('bar\n\tbaz\n', 'bar\n baz\n'),
|
||||
),
|
||||
)
|
||||
def test_remove_tabs(input_s, expected, tmpdir):
|
||||
path = tmpdir.join('file.txt')
|
||||
path.write(input_s)
|
||||
assert remove_tabs(('--whitespaces-count=4', path.strpath)) == 1
|
||||
assert path.read() == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('arg'), ('', '--', 'a.b', 'a/b'))
|
||||
def test_badopt(arg):
|
||||
with pytest.raises(SystemExit) as excinfo:
|
||||
remove_tabs(['--whitespaces-count', arg])
|
||||
assert excinfo.value.code == 2
|
||||
|
||||
|
||||
def test_nothing_to_fix():
|
||||
assert remove_tabs(['--whitespaces-count=4', __file__]) == 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue