Replace calls to touch with open(..., 'a').close()

This commit is contained in:
Anthony Sottile 2017-07-08 15:43:36 -07:00
parent f33a254dd8
commit a4da7b8c8c
4 changed files with 6 additions and 6 deletions

View file

@ -118,7 +118,7 @@ def test_uninstall(tempdir_factory):
def _get_commit_output(tempdir_factory, touch_file='foo', **kwargs): def _get_commit_output(tempdir_factory, touch_file='foo', **kwargs):
cmd_output('touch', touch_file) open(touch_file, 'a').close()
cmd_output('git', 'add', touch_file) cmd_output('git', 'add', touch_file)
return cmd_output_mocked_pre_commit_home( return cmd_output_mocked_pre_commit_home(
'git', 'commit', '-am', 'Commit!', '--allow-empty', 'git', 'commit', '-am', 'Commit!', '--allow-empty',

View file

@ -68,7 +68,7 @@ def _make_conflict():
def in_merge_conflict(tempdir_factory): def in_merge_conflict(tempdir_factory):
path = make_consuming_repo(tempdir_factory, 'script_hooks_repo') path = make_consuming_repo(tempdir_factory, 'script_hooks_repo')
with cwd(path): with cwd(path):
cmd_output('touch', 'dummy') open('dummy', 'a').close()
cmd_output('git', 'add', 'dummy') cmd_output('git', 'add', 'dummy')
cmd_output('git', 'commit', '-m', 'Add config.') cmd_output('git', 'commit', '-m', 'Add config.')

View file

@ -20,13 +20,13 @@ def test_make_archive(tempdir_factory):
git_path = git_dir(tempdir_factory) git_path = git_dir(tempdir_factory)
# Add a files to the git directory # Add a files to the git directory
with cwd(git_path): with cwd(git_path):
cmd_output('touch', 'foo') open('foo', 'a').close()
cmd_output('git', 'add', '.') cmd_output('git', 'add', '.')
cmd_output('git', 'commit', '-m', 'foo') cmd_output('git', 'commit', '-m', 'foo')
# We'll use this sha # We'll use this sha
head_sha = get_head_sha('.') head_sha = get_head_sha('.')
# And check that this file doesn't exist # And check that this file doesn't exist
cmd_output('touch', 'bar') open('bar', 'a').close()
cmd_output('git', 'add', '.') cmd_output('git', 'add', '.')
cmd_output('git', 'commit', '-m', 'bar') cmd_output('git', 'commit', '-m', 'bar')

View file

@ -46,7 +46,7 @@ def test_store_require_created(store):
# Should create the store directory # Should create the store directory
assert os.path.exists(store.directory) assert os.path.exists(store.directory)
# Should create a README file indicating what the directory is about # Should create a README file indicating what the directory is about
with io.open(os.path.join(store.directory, 'README'), 'r') as readme_file: with io.open(os.path.join(store.directory, 'README')) as readme_file:
readme_contents = readme_file.read() readme_contents = readme_file.read()
for text_line in ( for text_line in (
'This directory is maintained by the pre-commit project.', 'This directory is maintained by the pre-commit project.',
@ -73,7 +73,7 @@ def test_does_not_recreate_if_directory_already_exists(store):
# Note: we're intentionally leaving out the README file. This is so we can # Note: we're intentionally leaving out the README file. This is so we can
# know that `Store` didn't call create # know that `Store` didn't call create
os.mkdir(store.directory) os.mkdir(store.directory)
io.open(store.db_path, 'a+').close() open(store.db_path, 'a').close()
# Call require_created, this should not call create # Call require_created, this should not call create
store.require_created() store.require_created()
assert not os.path.exists(os.path.join(store.directory, 'README')) assert not os.path.exists(os.path.join(store.directory, 'README'))