mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-29 10:16:52 +00:00
Merge pull request #281 from pre-commit/remove_write_file
Remove write_file (now unnecessary)
This commit is contained in:
commit
8971d2fa75
2 changed files with 9 additions and 19 deletions
|
|
@ -1,7 +1,6 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import io
|
||||
import os.path
|
||||
|
||||
|
||||
|
|
@ -10,9 +9,3 @@ TESTING_DIR = os.path.abspath(os.path.dirname(__file__))
|
|||
|
||||
def get_resource_path(path):
|
||||
return os.path.join(TESTING_DIR, 'resources', path)
|
||||
|
||||
|
||||
def write_file(filename, contents):
|
||||
"""Hax because coveragepy chokes on nested context managers."""
|
||||
with io.open(filename, 'w', encoding='UTF-8', newline='') as file_obj:
|
||||
file_obj.write(contents)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import pytest
|
|||
from pre_commit_hooks.check_merge_conflict import detect_merge_conflict
|
||||
from pre_commit_hooks.util import cmd_output
|
||||
from testing.util import get_resource_path
|
||||
from testing.util import write_file
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
|
@ -64,11 +63,11 @@ def f1_is_a_conflict_file(tmpdir):
|
|||
'>>>>>>>',
|
||||
)
|
||||
assert os.path.exists(os.path.join('.git', 'MERGE_MSG'))
|
||||
yield
|
||||
yield repo2
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def repository_is_pending_merge(tmpdir):
|
||||
def repository_pending_merge(tmpdir):
|
||||
# Make a (non-conflicting) merge
|
||||
repo1 = tmpdir.join('repo1')
|
||||
repo1_f1 = repo1.join('f1')
|
||||
|
|
@ -98,7 +97,7 @@ def repository_is_pending_merge(tmpdir):
|
|||
assert repo2_f1.read() == 'parent\n'
|
||||
assert repo2_f2.read() == 'child\n'
|
||||
assert os.path.exists(os.path.join('.git', 'MERGE_HEAD'))
|
||||
yield
|
||||
yield repo2
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('f1_is_a_conflict_file')
|
||||
|
|
@ -107,20 +106,18 @@ def test_merge_conflicts_git():
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'failing_contents', ('<<<<<<< HEAD\n', '=======\n', '>>>>>>> master\n'),
|
||||
'contents', (b'<<<<<<< HEAD\n', b'=======\n', b'>>>>>>> master\n'),
|
||||
)
|
||||
@pytest.mark.usefixtures('repository_is_pending_merge')
|
||||
def test_merge_conflicts_failing(failing_contents):
|
||||
write_file('f2', failing_contents)
|
||||
def test_merge_conflicts_failing(contents, repository_pending_merge):
|
||||
repository_pending_merge.join('f2').write_binary(contents)
|
||||
assert detect_merge_conflict(['f2']) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'ok_contents', ('# <<<<<<< HEAD\n', '# =======\n', 'import my_module', ''),
|
||||
'contents', (b'# <<<<<<< HEAD\n', b'# =======\n', b'import mod', b''),
|
||||
)
|
||||
@pytest.mark.usefixtures('f1_is_a_conflict_file')
|
||||
def test_merge_conflicts_ok(ok_contents):
|
||||
write_file('f1', ok_contents)
|
||||
def test_merge_conflicts_ok(contents, f1_is_a_conflict_file):
|
||||
f1_is_a_conflict_file.join('f1').write_binary(contents)
|
||||
assert detect_merge_conflict(['f1']) == 0
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue