mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
Python code modernization, 1/n (#1141)
* Remove unicode text prefixes. * Replace str.format() uses with f-strings. * Replace % with f-strings, and do some cleanup. * Fix wrong variable. * Avoid unnecessary string conversion.
This commit is contained in:
@@ -39,7 +39,7 @@ def test_parse_string(input, expected):
|
||||
])
|
||||
def test_parse_int(input):
|
||||
assert parse_modern(input) == input
|
||||
with pytest.raises(TypeError, match="^must be an octal string, got {value}L?$".format(value=input)):
|
||||
with pytest.raises(TypeError, match=f"^must be an octal string, got {input}L?$"):
|
||||
parse_octal_string_only(input)
|
||||
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ from ..test_support.docker_image_archive_stubbing import (
|
||||
|
||||
|
||||
def assert_no_logging(msg):
|
||||
raise AssertionError('Should not have logged anything but logged %s' % msg)
|
||||
raise AssertionError(f'Should not have logged anything but logged {msg}')
|
||||
|
||||
|
||||
def capture_logging(messages):
|
||||
@@ -41,7 +41,7 @@ def test_archived_image_action_when_missing(tar_file_name):
|
||||
fake_name = 'a:latest'
|
||||
fake_id = 'a1'
|
||||
|
||||
expected = 'Archived image %s to %s, since none present' % (fake_name, tar_file_name)
|
||||
expected = f'Archived image {fake_name} to {tar_file_name}, since none present'
|
||||
|
||||
actual = ImageManager.archived_image_action(assert_no_logging, tar_file_name, fake_name, api_image_id(fake_id))
|
||||
|
||||
@@ -65,7 +65,7 @@ def test_archived_image_action_when_invalid(tar_file_name):
|
||||
|
||||
write_irrelevant_tar(tar_file_name)
|
||||
|
||||
expected = 'Archived image %s to %s, overwriting an unreadable archive file' % (fake_name, tar_file_name)
|
||||
expected = f'Archived image {fake_name} to {tar_file_name}, overwriting an unreadable archive file'
|
||||
|
||||
actual_log = []
|
||||
actual = ImageManager.archived_image_action(
|
||||
@@ -88,9 +88,7 @@ def test_archived_image_action_when_obsolete_by_id(tar_file_name):
|
||||
|
||||
write_imitation_archive(tar_file_name, old_id, [fake_name])
|
||||
|
||||
expected = 'Archived image %s to %s, overwriting archive with image %s named %s' % (
|
||||
fake_name, tar_file_name, old_id, fake_name
|
||||
)
|
||||
expected = f'Archived image {fake_name} to {tar_file_name}, overwriting archive with image {old_id} named {fake_name}'
|
||||
actual = ImageManager.archived_image_action(assert_no_logging, tar_file_name, fake_name, api_image_id(new_id))
|
||||
|
||||
assert actual == expected
|
||||
@@ -103,11 +101,9 @@ def test_archived_image_action_when_obsolete_by_name(tar_file_name):
|
||||
|
||||
write_imitation_archive(tar_file_name, fake_id, [old_name])
|
||||
|
||||
expected = 'Archived image %s to %s, overwriting archive with image %s named %s' % (
|
||||
new_name, tar_file_name, fake_id, old_name
|
||||
)
|
||||
expected = f'Archived image {new_name} to {tar_file_name}, overwriting archive with image {fake_id} named {old_name}'
|
||||
actual = ImageManager.archived_image_action(assert_no_logging, tar_file_name, new_name, api_image_id(fake_id))
|
||||
|
||||
print('actual : %s', actual)
|
||||
print('expected : %s', expected)
|
||||
print(f'actual : {actual}')
|
||||
print(f'expected : {expected}')
|
||||
assert actual == expected
|
||||
|
||||
@@ -32,4 +32,4 @@ def test_validate_cidr_positives(cidr, expected):
|
||||
def test_validate_cidr_negatives(cidr):
|
||||
with pytest.raises(ValueError) as e:
|
||||
validate_cidr(cidr)
|
||||
assert '"{0}" is not a valid CIDR'.format(cidr) == str(e.value)
|
||||
assert f'"{cidr}" is not a valid CIDR' == str(e.value)
|
||||
|
||||
@@ -75,7 +75,7 @@ def test_get_docker_environment(mocker, docker_swarm_service):
|
||||
mocker.patch.object(
|
||||
docker_swarm_service,
|
||||
'format_environment',
|
||||
side_effect=lambda d: ['{0}={1}'.format(key, value) for key, value in d.items()],
|
||||
side_effect=lambda d: [f'{key}={value}' for key, value in d.items()],
|
||||
)
|
||||
# Test with env dict and file
|
||||
result = docker_swarm_service.get_docker_environment(
|
||||
@@ -207,7 +207,7 @@ def test_has_list_changed(docker_swarm_service):
|
||||
)
|
||||
assert docker_swarm_service.has_list_changed(
|
||||
['sleep', '3400'],
|
||||
[u'sleep', u'3600'],
|
||||
['sleep', '3600'],
|
||||
sort_lists=False
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user