mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-08 20:44:18 +00:00
Simplify the tests
This commit is contained in:
parent
b64436cdda
commit
a99475afa0
14 changed files with 144 additions and 201 deletions
|
|
@ -4,63 +4,61 @@ from __future__ import unicode_literals
|
|||
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 cwd(temp_git_dir):
|
||||
with temp_git_dir.as_cwd():
|
||||
assert find_conflicting_filenames(['f.py']) == 0
|
||||
|
||||
|
||||
def test_adding_something(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
write_file('f.py', "print('hello world')")
|
||||
with temp_git_dir.as_cwd():
|
||||
temp_git_dir.join('f.py').write("print('hello world')")
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
assert find_conflicting_filenames(['f.py']) == 0
|
||||
|
||||
|
||||
def test_adding_something_with_conflict(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
write_file('f.py', "print('hello world')")
|
||||
with temp_git_dir.as_cwd():
|
||||
temp_git_dir.join('f.py').write("print('hello world')")
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
write_file('F.py', "print('hello world')")
|
||||
temp_git_dir.join('F.py').write("print('hello world')")
|
||||
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 cwd(temp_git_dir):
|
||||
write_file('f.py', "print('hello world')")
|
||||
with temp_git_dir.as_cwd():
|
||||
temp_git_dir.join('f.py').write("print('hello world')")
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
assert find_conflicting_filenames(['g.py']) == 0
|
||||
|
||||
|
||||
def test_file_conflicts_with_committed_file(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
write_file('f.py', "print('hello world')")
|
||||
with temp_git_dir.as_cwd():
|
||||
temp_git_dir.join('f.py').write("print('hello world')")
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
cmd_output('git', 'commit', '--no-verify', '-m', 'Add f.py')
|
||||
|
||||
write_file('F.py', "print('hello world')")
|
||||
temp_git_dir.join('F.py').write("print('hello world')")
|
||||
cmd_output('git', 'add', 'F.py')
|
||||
|
||||
assert find_conflicting_filenames(['F.py']) == 1
|
||||
|
||||
|
||||
def test_integration(temp_git_dir):
|
||||
with cwd(temp_git_dir):
|
||||
with temp_git_dir.as_cwd():
|
||||
assert main(argv=[]) == 0
|
||||
|
||||
write_file('f.py', "print('hello world')")
|
||||
temp_git_dir.join('f.py').write("print('hello world')")
|
||||
cmd_output('git', 'add', 'f.py')
|
||||
|
||||
assert main(argv=['f.py']) == 0
|
||||
|
||||
write_file('F.py', "print('hello world')")
|
||||
temp_git_dir.join('F.py').write("print('hello world')")
|
||||
cmd_output('git', 'add', 'F.py')
|
||||
|
||||
assert main(argv=['F.py']) == 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue