Some manual .format() -> f-strings

This commit is contained in:
Anthony Sottile 2020-01-12 11:13:39 -08:00
parent aefbe71765
commit 9000e9dd41
27 changed files with 133 additions and 173 deletions

View file

@ -291,13 +291,11 @@ def test_minimum_pre_commit_version_failing():
cfg = {'repos': [], 'minimum_pre_commit_version': '999'}
cfgv.validate(cfg, CONFIG_SCHEMA)
assert str(excinfo.value) == (
'\n'
'==> At Config()\n'
'==> At key: minimum_pre_commit_version\n'
'=====> pre-commit version 999 is required but version {} is '
'installed. Perhaps run `pip install --upgrade pre-commit`.'.format(
C.VERSION,
)
f'\n'
f'==> At Config()\n'
f'==> At key: minimum_pre_commit_version\n'
f'=====> pre-commit version 999 is required but version {C.VERSION} '
f'is installed. Perhaps run `pip install --upgrade pre-commit`.'
)

View file

@ -1,4 +1,4 @@
import pipes
import shlex
import pytest
@ -118,12 +118,12 @@ def test_rev_info_update_does_not_freeze_if_already_sha(out_of_date):
def test_autoupdate_up_to_date_repo(up_to_date, tmpdir, store):
contents = (
'repos:\n'
'- repo: {}\n'
' rev: {}\n'
' hooks:\n'
' - id: foo\n'
).format(up_to_date, git.head_rev(up_to_date))
f'repos:\n'
f'- repo: {up_to_date}\n'
f' rev: {git.head_rev(up_to_date)}\n'
f' hooks:\n'
f' - id: foo\n'
)
cfg = tmpdir.join(C.CONFIG_FILE)
cfg.write(contents)
@ -278,7 +278,7 @@ def test_loses_formatting_when_not_detectable(out_of_date, store, tmpdir):
' ],\n'
' }}\n'
']\n'.format(
pipes.quote(out_of_date.path), out_of_date.original_rev,
shlex.quote(out_of_date.path), out_of_date.original_rev,
)
)
cfg = tmpdir.join(C.CONFIG_FILE)
@ -286,12 +286,12 @@ def test_loses_formatting_when_not_detectable(out_of_date, store, tmpdir):
assert autoupdate(str(cfg), store, freeze=False, tags_only=False) == 0
expected = (
'repos:\n'
'- repo: {}\n'
' rev: {}\n'
' hooks:\n'
' - id: foo\n'
).format(out_of_date.path, out_of_date.head_rev)
f'repos:\n'
f'- repo: {out_of_date.path}\n'
f' rev: {out_of_date.head_rev}\n'
f' hooks:\n'
f' - id: foo\n'
)
assert cfg.read() == expected
@ -358,12 +358,12 @@ def test_hook_disppearing_repo_raises(hook_disappearing, store):
def test_autoupdate_hook_disappearing_repo(hook_disappearing, tmpdir, store):
contents = (
'repos:\n'
'- repo: {}\n'
' rev: {}\n'
' hooks:\n'
' - id: foo\n'
).format(hook_disappearing.path, hook_disappearing.original_rev)
f'repos:\n'
f'- repo: {hook_disappearing.path}\n'
f' rev: {hook_disappearing.original_rev}\n'
f' hooks:\n'
f' - id: foo\n'
)
cfg = tmpdir.join(C.CONFIG_FILE)
cfg.write(contents)

View file

@ -52,11 +52,11 @@ def test_shebang_posix_not_on_path():
def test_shebang_posix_on_path(tmpdir):
tmpdir.join('python{}'.format(sys.version_info[0])).ensure()
tmpdir.join(f'python{sys.version_info[0]}').ensure()
with mock.patch.object(sys, 'platform', 'posix'):
with mock.patch.object(os, 'defpath', tmpdir.strpath):
expected = '#!/usr/bin/env python{}'.format(sys.version_info[0])
expected = f'#!/usr/bin/env python{sys.version_info[0]}'
assert shebang() == expected

View file

@ -1,5 +1,5 @@
import os.path
import pipes
import shlex
import sys
import time
from unittest import mock
@ -580,8 +580,7 @@ def test_lots_of_files(store, tempdir_factory):
# Write a crap ton of files
for i in range(400):
filename = '{}{}'.format('a' * 100, i)
open(filename, 'w').close()
open(f'{"a" * 100}{i}', 'w').close()
cmd_output('git', 'add', '.')
install(C.CONFIG_FILE, store, hook_types=['pre-commit'])
@ -673,7 +672,7 @@ def test_local_hook_passes(cap_out, store, repo_with_passing_hook):
'id': 'identity-copy',
'name': 'identity-copy',
'entry': '{} -m pre_commit.meta_hooks.identity'.format(
pipes.quote(sys.executable),
shlex.quote(sys.executable),
),
'language': 'system',
'files': r'\.py$',
@ -893,7 +892,7 @@ def test_args_hook_only(cap_out, store, repo_with_passing_hook):
'id': 'identity-copy',
'name': 'identity-copy',
'entry': '{} -m pre_commit.meta_hooks.identity'.format(
pipes.quote(sys.executable),
shlex.quote(sys.executable),
),
'language': 'system',
'files': r'\.py$',

View file

@ -99,9 +99,7 @@ def test_log_and_exit(cap_out, mock_store_dir):
printed = cap_out.get()
log_file = os.path.join(mock_store_dir, 'pre-commit.log')
assert printed == (
'msg: FatalError: hai\n' 'Check the log at {}\n'.format(log_file)
)
assert printed == f'msg: FatalError: hai\nCheck the log at {log_file}\n'
assert os.path.exists(log_file)
with open(log_file) as f:

View file

@ -1,5 +1,5 @@
import os.path
import pipes
import shlex
from pre_commit.languages.ruby import _install_rbenv
from pre_commit.prefix import Prefix
@ -21,7 +21,7 @@ def test_install_rbenv(tempdir_factory):
cmd_output(
'bash', '-c',
'. {} && rbenv --help'.format(
pipes.quote(prefix.path('rbenv-default', 'bin', 'activate')),
shlex.quote(prefix.path('rbenv-default', 'bin', 'activate')),
),
)
@ -35,6 +35,6 @@ def test_install_rbenv_with_version(tempdir_factory):
cmd_output(
'bash', '-c',
'. {} && rbenv install --help'.format(
pipes.quote(prefix.path('rbenv-1.9.3p547', 'bin', 'activate')),
shlex.quote(prefix.path('rbenv-1.9.3p547', 'bin', 'activate')),
),
)

View file

@ -805,9 +805,9 @@ def test_hook_id_not_present(tempdir_factory, store, fake_log_handler):
with pytest.raises(SystemExit):
_get_hook(config, store, 'i-dont-exist')
assert fake_log_handler.handle.call_args[0][0].msg == (
'`i-dont-exist` is not present in repository file://{}. '
'Typo? Perhaps it is introduced in a newer version? '
'Often `pre-commit autoupdate` fixes this.'.format(path)
f'`i-dont-exist` is not present in repository file://{path}. '
f'Typo? Perhaps it is introduced in a newer version? '
f'Often `pre-commit autoupdate` fixes this.'
)