Skip to content

Commit

Permalink
Remove write_file (now unnecessary)
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Mar 26, 2018
1 parent 71fadeb commit 9b1b44e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
7 changes: 0 additions & 7 deletions testing/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import io
import os.path


Expand All @@ -10,9 +9,3 @@

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)
21 changes: 9 additions & 12 deletions tests/check_merge_conflict_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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


Expand Down

0 comments on commit 9b1b44e

Please sign in to comment.