mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 03:26:53 +00:00
Remove dependency on plumbum
This commit is contained in:
parent
c9b6161fab
commit
713fab4bc7
12 changed files with 99 additions and 55 deletions
|
|
@ -2,7 +2,6 @@ from __future__ import absolute_import
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import os
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -25,16 +24,6 @@ def test_main_failing(tmpdir, input_src, expected_ret, output_src):
|
|||
assert io.open(filename).read() == output_src
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def in_tmpdir(tmpdir):
|
||||
pwd = os.getcwd()
|
||||
os.chdir(tmpdir.strpath)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
os.chdir(pwd)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('in_tmpdir')
|
||||
def test_respects_config_file():
|
||||
with io.open('setup.cfg', 'w') as setup_cfg:
|
||||
|
|
|
|||
|
|
@ -1,35 +1,35 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from plumbum import local
|
||||
|
||||
from pre_commit_hooks.check_added_large_files import find_large_added_files
|
||||
from pre_commit_hooks.check_added_large_files import main
|
||||
from pre_commit_hooks.util import cmd_output
|
||||
from testing.util import cwd
|
||||
from testing.util import write_file
|
||||
|
||||
|
||||
def test_nothing_added(temp_git_dir):
|
||||
with local.cwd(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
assert find_large_added_files(['f.py'], 0) == 0
|
||||
|
||||
|
||||
def test_adding_something(temp_git_dir):
|
||||
with local.cwd(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
write_file('f.py', "print('hello world')")
|
||||
local['git']('add', 'f.py')
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
# Should fail with max size of 0
|
||||
assert find_large_added_files(['f.py'], 0) == 1
|
||||
|
||||
|
||||
def test_add_something_giant(temp_git_dir):
|
||||
with local.cwd(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
write_file('f.py', 'a' * 10000)
|
||||
|
||||
# Should not fail when not added
|
||||
assert find_large_added_files(['f.py'], 0) == 0
|
||||
|
||||
local['git']('add', 'f.py')
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
# Should fail with strict bound
|
||||
assert find_large_added_files(['f.py'], 0) == 1
|
||||
|
|
@ -42,20 +42,20 @@ def test_add_something_giant(temp_git_dir):
|
|||
|
||||
|
||||
def test_added_file_not_in_pre_commits_list(temp_git_dir):
|
||||
with local.cwd(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
write_file('f.py', "print('hello world')")
|
||||
local['git']('add', 'f.py')
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
# Should pass even with a size of 0
|
||||
assert find_large_added_files(['g.py'], 0) == 0
|
||||
|
||||
|
||||
def test_integration(temp_git_dir):
|
||||
with local.cwd(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
assert main(argv=[]) == 0
|
||||
|
||||
write_file('f.py', 'a' * 10000)
|
||||
local['git']('add', 'f.py')
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
# Should not fail with default
|
||||
assert main(argv=['f.py']) == 0
|
||||
|
|
|
|||
|
|
@ -1,66 +1,66 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from plumbum import local
|
||||
|
||||
from pre_commit_hooks.check_case_conflict import find_conflicting_filenames
|
||||
from pre_commit_hooks.check_case_conflict import main
|
||||
from pre_commit_hooks.util import cmd_output
|
||||
from testing.util import cwd
|
||||
from testing.util import write_file
|
||||
|
||||
|
||||
def test_nothing_added(temp_git_dir):
|
||||
with local.cwd(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
assert find_conflicting_filenames(['f.py']) == 0
|
||||
|
||||
|
||||
def test_adding_something(temp_git_dir):
|
||||
with local.cwd(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
write_file('f.py', "print('hello world')")
|
||||
local['git']('add', 'f.py')
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
assert find_conflicting_filenames(['f.py']) == 0
|
||||
|
||||
|
||||
def test_adding_something_with_conflict(temp_git_dir):
|
||||
with local.cwd(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
write_file('f.py', "print('hello world')")
|
||||
local['git']('add', 'f.py')
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
write_file('F.py', "print('hello world')")
|
||||
local['git']('add', 'F.py')
|
||||
cmd_output('git', 'add', 'F.py')
|
||||
|
||||
assert find_conflicting_filenames(['f.py', 'F.py']) == 1
|
||||
|
||||
|
||||
def test_added_file_not_in_pre_commits_list(temp_git_dir):
|
||||
with local.cwd(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
write_file('f.py', "print('hello world')")
|
||||
local['git']('add', 'f.py')
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
assert find_conflicting_filenames(['g.py']) == 0
|
||||
|
||||
|
||||
def test_file_conflicts_with_committed_file(temp_git_dir):
|
||||
with local.cwd(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
write_file('f.py', "print('hello world')")
|
||||
local['git']('add', 'f.py')
|
||||
local['git']('commit', '--no-verify', '-m', 'Add f.py')
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
cmd_output('git', 'commit', '--no-verify', '-m', 'Add f.py')
|
||||
|
||||
write_file('F.py', "print('hello world')")
|
||||
local['git']('add', 'F.py')
|
||||
cmd_output('git', 'add', 'F.py')
|
||||
|
||||
assert find_conflicting_filenames(['F.py']) == 1
|
||||
|
||||
|
||||
def test_integration(temp_git_dir):
|
||||
with local.cwd(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
assert main(argv=[]) == 0
|
||||
|
||||
write_file('f.py', "print('hello world')")
|
||||
local['git']('add', 'f.py')
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
assert main(argv=['f.py']) == 0
|
||||
|
||||
write_file('F.py', "print('hello world')")
|
||||
local['git']('add', 'F.py')
|
||||
cmd_output('git', 'add', 'F.py')
|
||||
|
||||
assert main(argv=['F.py']) == 1
|
||||
|
|
|
|||
|
|
@ -3,11 +3,19 @@ from __future__ import print_function
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
from plumbum import local
|
||||
|
||||
from pre_commit_hooks.util import cmd_output
|
||||
from testing.util import cwd
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def in_tmpdir(tmpdir):
|
||||
with cwd(tmpdir.strpath):
|
||||
yield tmpdir
|
||||
|
||||
|
||||
@pytest.yield_fixture
|
||||
def temp_git_dir(tmpdir):
|
||||
git_dir = tmpdir.join('gits').strpath
|
||||
local['git']('init', git_dir)
|
||||
cmd_output('git', 'init', git_dir)
|
||||
yield git_dir
|
||||
|
|
|
|||
|
|
@ -1,10 +1,12 @@
|
|||
from plumbum import local
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit_hooks.trailing_whitespace_fixer import fix_trailing_whitespace
|
||||
from testing.util import cwd
|
||||
|
||||
|
||||
def test_fixes_trailing_whitespace(tmpdir):
|
||||
with local.cwd(tmpdir.strpath):
|
||||
with cwd(tmpdir.strpath):
|
||||
for filename, contents in (
|
||||
('foo.py', 'foo \nbar \n'),
|
||||
('bar.py', 'bar\t\nbaz\t\n'),
|
||||
|
|
|
|||
17
tests/util_test.py
Normal file
17
tests/util_test.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.util import CalledProcessError
|
||||
from pre_commit_hooks.util import cmd_output
|
||||
|
||||
|
||||
def test_raises_on_error():
|
||||
with pytest.raises(CalledProcessError):
|
||||
cmd_output('sh', '-c', 'exit 1')
|
||||
|
||||
|
||||
def test_output():
|
||||
ret = cmd_output('sh', '-c', 'echo hi')
|
||||
assert ret == 'hi\n'
|
||||
Loading…
Add table
Add a link
Reference in a new issue