Skip to content

Commit 853cbec

Browse files
authored
Merge pull request pre-commit#555 from pre-commit/no_subprocess_touch_tests
Replace calls to touch with open(..., 'a').close()
2 parents f33a254 + a4da7b8 commit 853cbec

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

tests/commands/install_uninstall_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_uninstall(tempdir_factory):
118118

119119

120120
def _get_commit_output(tempdir_factory, touch_file='foo', **kwargs):
121-
cmd_output('touch', touch_file)
121+
open(touch_file, 'a').close()
122122
cmd_output('git', 'add', touch_file)
123123
return cmd_output_mocked_pre_commit_home(
124124
'git', 'commit', '-am', 'Commit!', '--allow-empty',

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _make_conflict():
6868
def in_merge_conflict(tempdir_factory):
6969
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
7070
with cwd(path):
71-
cmd_output('touch', 'dummy')
71+
open('dummy', 'a').close()
7272
cmd_output('git', 'add', 'dummy')
7373
cmd_output('git', 'commit', '-m', 'Add config.')
7474

tests/make_archives_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ def test_make_archive(tempdir_factory):
2020
git_path = git_dir(tempdir_factory)
2121
# Add a files to the git directory
2222
with cwd(git_path):
23-
cmd_output('touch', 'foo')
23+
open('foo', 'a').close()
2424
cmd_output('git', 'add', '.')
2525
cmd_output('git', 'commit', '-m', 'foo')
2626
# We'll use this sha
2727
head_sha = get_head_sha('.')
2828
# And check that this file doesn't exist
29-
cmd_output('touch', 'bar')
29+
open('bar', 'a').close()
3030
cmd_output('git', 'add', '.')
3131
cmd_output('git', 'commit', '-m', 'bar')
3232

tests/store_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_store_require_created(store):
4646
# Should create the store directory
4747
assert os.path.exists(store.directory)
4848
# Should create a README file indicating what the directory is about
49-
with io.open(os.path.join(store.directory, 'README'), 'r') as readme_file:
49+
with io.open(os.path.join(store.directory, 'README')) as readme_file:
5050
readme_contents = readme_file.read()
5151
for text_line in (
5252
'This directory is maintained by the pre-commit project.',
@@ -73,7 +73,7 @@ def test_does_not_recreate_if_directory_already_exists(store):
7373
# Note: we're intentionally leaving out the README file. This is so we can
7474
# know that `Store` didn't call create
7575
os.mkdir(store.directory)
76-
io.open(store.db_path, 'a+').close()
76+
open(store.db_path, 'a').close()
7777
# Call require_created, this should not call create
7878
store.require_created()
7979
assert not os.path.exists(os.path.join(store.directory, 'README'))

0 commit comments

Comments
 (0)