Skip to content

Commit 9b1b44e

Browse files
committed
Remove write_file (now unnecessary)
1 parent 71fadeb commit 9b1b44e

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

testing/util.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import absolute_import
22
from __future__ import unicode_literals
33

4-
import io
54
import os.path
65

76

@@ -10,9 +9,3 @@
109

1110
def get_resource_path(path):
1211
return os.path.join(TESTING_DIR, 'resources', path)
13-
14-
15-
def write_file(filename, contents):
16-
"""Hax because coveragepy chokes on nested context managers."""
17-
with io.open(filename, 'w', encoding='UTF-8', newline='') as file_obj:
18-
file_obj.write(contents)

tests/check_merge_conflict_test.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from pre_commit_hooks.check_merge_conflict import detect_merge_conflict
1010
from pre_commit_hooks.util import cmd_output
1111
from testing.util import get_resource_path
12-
from testing.util import write_file
1312

1413

1514
@pytest.fixture
@@ -64,11 +63,11 @@ def f1_is_a_conflict_file(tmpdir):
6463
'>>>>>>>',
6564
)
6665
assert os.path.exists(os.path.join('.git', 'MERGE_MSG'))
67-
yield
66+
yield repo2
6867

6968

7069
@pytest.fixture
71-
def repository_is_pending_merge(tmpdir):
70+
def repository_pending_merge(tmpdir):
7271
# Make a (non-conflicting) merge
7372
repo1 = tmpdir.join('repo1')
7473
repo1_f1 = repo1.join('f1')
@@ -98,7 +97,7 @@ def repository_is_pending_merge(tmpdir):
9897
assert repo2_f1.read() == 'parent\n'
9998
assert repo2_f2.read() == 'child\n'
10099
assert os.path.exists(os.path.join('.git', 'MERGE_HEAD'))
101-
yield
100+
yield repo2
102101

103102

104103
@pytest.mark.usefixtures('f1_is_a_conflict_file')
@@ -107,20 +106,18 @@ def test_merge_conflicts_git():
107106

108107

109108
@pytest.mark.parametrize(
110-
'failing_contents', ('<<<<<<< HEAD\n', '=======\n', '>>>>>>> master\n'),
109+
'contents', (b'<<<<<<< HEAD\n', b'=======\n', b'>>>>>>> master\n'),
111110
)
112-
@pytest.mark.usefixtures('repository_is_pending_merge')
113-
def test_merge_conflicts_failing(failing_contents):
114-
write_file('f2', failing_contents)
111+
def test_merge_conflicts_failing(contents, repository_pending_merge):
112+
repository_pending_merge.join('f2').write_binary(contents)
115113
assert detect_merge_conflict(['f2']) == 1
116114

117115

118116
@pytest.mark.parametrize(
119-
'ok_contents', ('# <<<<<<< HEAD\n', '# =======\n', 'import my_module', ''),
117+
'contents', (b'# <<<<<<< HEAD\n', b'# =======\n', b'import mod', b''),
120118
)
121-
@pytest.mark.usefixtures('f1_is_a_conflict_file')
122-
def test_merge_conflicts_ok(ok_contents):
123-
write_file('f1', ok_contents)
119+
def test_merge_conflicts_ok(contents, f1_is_a_conflict_file):
120+
f1_is_a_conflict_file.join('f1').write_binary(contents)
124121
assert detect_merge_conflict(['f1']) == 0
125122

126123

0 commit comments

Comments
 (0)