Replace % and str.format() with f-strings (#875)

* Replace % and str.format() with f-strings.

* Apply suggestions from review.
This commit is contained in:
Felix Fontein
2025-05-01 11:50:10 +02:00
committed by GitHub
parent d8f838c365
commit 641e63b08c
86 changed files with 544 additions and 1036 deletions

View File

@@ -78,7 +78,7 @@ TEST_CASES = [
@pytest.mark.parametrize("value, expected", TEST_CASES)
def test_serialize_asn1_string_as_der(value, expected):
actual = serialize_asn1_string_as_der(value)
print("%s | %s" % (value, base64.b16encode(actual).decode()))
print(f"{value} | {base64.b16encode(actual).decode()}")
assert actual == expected
@@ -121,10 +121,8 @@ def test_test_cases(value, expected, tmp_path):
b_data = fd.read()
hex_str = base64.b16encode(b_data).decode().lower()
print(
"%s | \\x%s"
% (value, "\\x".join([hex_str[i : i + 2] for i in range(0, len(hex_str), 2)]))
)
value = "\\x".join([hex_str[i : i + 2] for i in range(0, len(hex_str), 2)])
print(f"{value} | \\x{value}")
# This is a know edge case where openssl asn1parse does not work properly.
if value != "UTF8:café":

View File

@@ -201,7 +201,7 @@ if (
],
)
def test_parse_dn_component_failure(name, options, message):
with pytest.raises(OpenSSLObjectError, match="^%s$" % re.escape(message)):
with pytest.raises(OpenSSLObjectError, match=f"^{re.escape(message)}$"):
_parse_dn_component(name, **options)
@@ -245,5 +245,5 @@ def test_parse_dn(name, expected):
],
)
def test_parse_dn_failure(name, message):
with pytest.raises(OpenSSLObjectError, match="^%s$" % re.escape(message)):
with pytest.raises(OpenSSLObjectError, match=f"^{re.escape(message)}$"):
_parse_dn(name)

View File

@@ -144,7 +144,7 @@ def test_default_key_params(keytype, size, passphrase, comment):
"ed25519": 256,
}
default_comment = "%s@%s" % (getuser(), gethostname())
default_comment = f"{getuser()}@{gethostname()}"
pair = OpensshKeypair.generate(
keytype=keytype, size=size, passphrase=passphrase, comment=comment
)