Commit fc8f955e authored by Benjamin Tissoires's avatar Benjamin Tissoires
Browse files

ci-fairy: use f-strings instead of .format()



We seem to have been using f-strings since we introduced `lint`, and this
was the third commit on ci-fairy. So basically, it seems that the
f-strings are an accepted requirement.

Convert any .format() into f-strings to have a more homogeneous code base.
Signed-off-by: Benjamin Tissoires's avatarBenjamin Tissoires <benjamin.tissoires@gmail.com>
parent cb1dda1e
......@@ -697,7 +697,7 @@ def delete_image(ctx, repository, project, all, exclude_tag, tag, dry_run):
sys.exit(1)
repos = [r for r in p.repositories.list() if repository is None or repository == r.name]
for repo in repos:
logger.debug('Repository {}'.format(repo.name))
logger.debug(f'Repository {repo.name}')
for t in repo.tags.list(all=True):
if all:
do_delete = True
......@@ -711,13 +711,13 @@ def delete_image(ctx, repository, project, all, exclude_tag, tag, dry_run):
do_delete = False
if do_delete:
logger.info('Deleting tag {}:{}'.format(repo.name, t.name))
logger.info(f'Deleting tag {repo.name}:{t.name}')
if not dry_run:
try:
t.delete()
except gitlab.exceptions.GitlabDeleteError as e:
if e.response_code == 403:
logger.error('Insufficient permissions to delete tag {}:{}'.format(repo.name, t.name))
logger.error(f'Insufficient permissions to delete tag {repo.name}:{t.name}')
sys.exit(1)
else:
raise e
......@@ -805,12 +805,12 @@ def generate_template(ctx, config, root, template, output_file):
configfile = Path(config)
if configfile != '-' and not configfile.is_file():
logger.error('config file {} does not exist or is not a file'.format(configfile))
logger.error(f'config file {configfile} does not exist or is not a file')
sys.exit(1)
templatefile = Path(template)
if not templatefile.is_file():
logger.error('template file {} does not exist or is not a file'.format(templatefile))
logger.error(f'template file {templatefile} does not exist or is not a file')
sys.exit(1)
if output_file is None:
......@@ -832,7 +832,7 @@ def generate_template(ctx, config, root, template, output_file):
else:
data = data[root]
except KeyError:
logger.error('Node {} not found'.format(r))
logger.error(f'Node {r} not found')
sys.exit(1)
templatedir = templatefile.parent
......@@ -1033,8 +1033,8 @@ See https://docs.gitlab.com/ce/user/project/merge_requests/allow_collaboration.h
if failures:
if junit_xml is not None:
suite_id = '{}.merge_request.{}'.format(p.name, merge_request_iid)
suite_name = 'Merge request check ({} !{})'.format(p.name, merge_request_iid)
suite_id = f'{p.name}.merge_request.{merge_request_iid}'
suite_name = f'Merge request check ({p.name} !{merge_request_iid})'
make_junit_xml(junit_xml, suite_id, suite_name, failures)
sys.exit(exit_status)
......
......@@ -44,13 +44,13 @@ def mock_gitlab(gitlab):
repos = []
for i in range(3):
repo = MagicMock()
repo.name = 'repository/{}'.format(i)
repo.name = f'repository/{i}'
repos.append(repo)
tags = []
for t in range(5):
tag = MagicMock()
tag.name = 'tag-{}'.format(t)
tag.name = f'tag-{t}'
tags.append(tag)
repo.tags = MagicMock()
......@@ -819,7 +819,7 @@ def mock_minio(minio):
buckets = []
for i in range(3):
bucket = MagicMock()
bucket.name = 'bucket{}'.format(i)
bucket.name = f'bucket{i}'
buckets.append(bucket)
files = []
......@@ -829,7 +829,7 @@ def mock_minio(minio):
for _dir in range(5):
for _f in range(4):
f = MagicMock()
f.key = 'dir-{}/file-{}'.format(_dir, _f)
f.key = f'dir-{_dir}/file-{_f}'
files.append(f)
def upload_file(src, dst):
......@@ -881,13 +881,13 @@ def write_minio_credentials():
('.', ['hello.txt', '.minio_credentials']),
('minio:', None),
('minio:/', None),
('minio://', ['bucket{}'.format(i) for i in range(3)]),
('minio://bucket1', ['root_file.txt'] + ['dir-{}'.format(i) for i in range(5)]),
('minio://bucket0/', ['root_file.txt'] + ['dir-{}'.format(i) for i in range(5)]),
('minio://', [f'bucket{i}' for i in range(3)]),
('minio://bucket1', ['root_file.txt'] + [f'dir-{i}' for i in range(5)]),
('minio://bucket0/', ['root_file.txt'] + [f'dir-{i}' for i in range(5)]),
('minio://non_existant_bucket', None),
('minio://bucket0/non_existent_dir_or_file', None),
('minio://bucket2/dir-2', ['file-{}'.format(i) for i in range(4)]),
('minio://bucket0/dir-1/', ['file-{}'.format(i) for i in range(4)]),
('minio://bucket2/dir-2', [f'file-{i}' for i in range(4)]),
('minio://bucket0/dir-1/', [f'file-{i}' for i in range(4)]),
('minio://bucket2/dir-0/file-3', ['file-3']),
])
def test_minio_ls(minio, input_path, result_files, caplog):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment