test: Avoid F541 (f-string without any placeholders)

This commit is contained in:
MarcoFalke 2024-12-04 14:42:27 +01:00
parent 11f68cc810
commit fae76393bd
No known key found for this signature in database
19 changed files with 30 additions and 29 deletions

View file

@ -117,9 +117,9 @@ int trace_outbound_message(struct pt_regs *ctx) {
def print_message(event, inbound):
print(f"%s %s msg '%s' from peer %d (%s, %s) with %d bytes: %s" %
(
f"Warning: incomplete message (only %d out of %d bytes)!" % (
print("{} {} msg '{}' from peer {} ({}, {}) with {} bytes: {}".format(
"Warning: incomplete message (only {} out of {} bytes)!".format(
len(event.msg), event.msg_size) if len(event.msg) < event.msg_size else "",
"inbound" if inbound else "outbound",
event.msg_type.decode("utf-8"),

View file

@ -102,7 +102,7 @@ class AnchorsTest(BitcoinTestFramework):
self.nodes[0].addconnection(ONION_ADDR, 'block-relay-only', v2transport=False)
self.log.debug("Stop node")
with self.nodes[0].assert_debug_log([f"DumpAnchors: Flush 1 outbound block-relay-only peer addresses to anchors.dat"]):
with self.nodes[0].assert_debug_log(["DumpAnchors: Flush 1 outbound block-relay-only peer addresses to anchors.dat"]):
self.stop_node(0)
# Manually close keep_alive proxy connection
onion_proxy.stop()

View file

@ -165,8 +165,8 @@ class AssumeutxoTest(BitcoinTestFramework):
with self.nodes[0].assert_debug_log([log_msg]):
self.nodes[0].assert_start_raises_init_error(expected_msg=error_msg)
expected_error_msg = f"Error: A fatal internal error occurred, see debug.log for details: Assumeutxo data not found for the given blockhash '7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a'."
error_details = f"Assumeutxo data not found for the given blockhash"
expected_error_msg = "Error: A fatal internal error occurred, see debug.log for details: Assumeutxo data not found for the given blockhash '7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a7a'."
error_details = "Assumeutxo data not found for the given blockhash"
expected_error(log_msg=error_details, error_msg=expected_error_msg)
# resurrect node again
@ -417,7 +417,7 @@ class AssumeutxoTest(BitcoinTestFramework):
assert_equal(n0.getblockchaininfo()["blocks"], FINAL_HEIGHT)
self.log.info(f"Check that dumptxoutset works for past block heights")
self.log.info("Check that dumptxoutset works for past block heights")
# rollback defaults to the snapshot base height
dump_output2 = n0.dumptxoutset('utxos2.dat', "rollback")
check_dump_output(dump_output2)

View file

@ -72,7 +72,7 @@ class ConfArgsTest(BitcoinTestFramework):
self.log.debug('Verifying garbage in config can be detected')
with open(conf_path, 'a', encoding='utf-8') as conf:
conf.write(f'garbage\n')
conf.write('garbage\n')
self.nodes[0].assert_start_raises_init_error(
extra_args=['-regtest'],
expected_msg='Error: Error reading configuration file: parse error on line 1: garbage',
@ -98,7 +98,7 @@ class ConfArgsTest(BitcoinTestFramework):
# Check that startup fails if conf= is set in bitcoin.conf or in an included conf file
bad_conf_file_path = self.nodes[0].datadir_path / "bitcoin_bad.conf"
util.write_config(bad_conf_file_path, n=0, chain='', extra_config=f'conf=some.conf\n')
util.write_config(bad_conf_file_path, n=0, chain='', extra_config='conf=some.conf\n')
conf_in_config_file_err = 'Error: Error reading configuration file: conf cannot be set in the configuration file; use includeconf= if you want to include additional config files'
self.nodes[0].assert_start_raises_init_error(
extra_args=[f'-conf={bad_conf_file_path}'],

View file

@ -130,7 +130,7 @@ class BIP66Test(BitcoinTestFramework):
block.hashMerkleRoot = block.calc_merkle_root()
block.solve()
with self.nodes[0].assert_debug_log(expected_msgs=[f'Block validation error: mandatory-script-verify-flag-failed (Non-canonical DER signature)']):
with self.nodes[0].assert_debug_log(expected_msgs=['Block validation error: mandatory-script-verify-flag-failed (Non-canonical DER signature)']):
peer.send_and_ping(msg_block(block))
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
peer.sync_with_ping()

View file

@ -34,7 +34,7 @@ class FeatureFrameworkMiniWalletTest(BitcoinTestFramework):
def test_wallet_tagging(self):
"""Verify that tagged wallet instances are able to send funds."""
self.log.info(f"Test tagged wallet instances...")
self.log.info("Test tagged wallet instances...")
node = self.nodes[0]
untagged_wallet = self.wallets[0][1]
for i in range(10):

View file

@ -51,8 +51,8 @@ class LoadblockTest(BitcoinTestFramework):
cfg.write(f"port={node_url.port}\n")
cfg.write(f"host={node_url.hostname}\n")
cfg.write(f"output_file={bootstrap_file}\n")
cfg.write(f"max_height=100\n")
cfg.write(f"netmagic=fabfb5da\n")
cfg.write("max_height=100\n")
cfg.write("netmagic=fabfb5da\n")
cfg.write(f"input={blocks_dir}\n")
cfg.write(f"genesis={genesis_block}\n")
cfg.write(f"hashlist={hash_list.name}\n")

View file

@ -209,7 +209,7 @@ class RESTTest (BitcoinTestFramework):
self.test_rest_request(f"/getutxos/{spending[0]}-+1", ret_type=RetType.OBJ, status=400)
self.test_rest_request(f"/getutxos/{spending[0]}--1", ret_type=RetType.OBJ, status=400)
self.test_rest_request(f"/getutxos/{spending[0]}aa-1234", ret_type=RetType.OBJ, status=400)
self.test_rest_request(f"/getutxos/aa-1234", ret_type=RetType.OBJ, status=400)
self.test_rest_request("/getutxos/aa-1234", ret_type=RetType.OBJ, status=400)
# Test limits
long_uri = '/'.join([f"{txid}-{n_}" for n_ in range(20)])

View file

@ -393,7 +393,7 @@ class UTXOCacheTracepointTest(BitcoinTestFramework):
bpf = BPF(text=utxocache_flushes_program, usdt_contexts=[ctx], debug=0, cflags=["-Wno-error=implicit-function-declaration"])
bpf["utxocache_flush"].open_perf_buffer(handle_utxocache_flush)
self.log.info(f"prune blockchain to trigger a flush for pruning")
self.log.info("prune blockchain to trigger a flush for pruning")
expected_flushes.append({"mode": "NONE", "for_prune": True, "size": 0})
self.nodes[0].pruneblockchain(315)
@ -401,7 +401,7 @@ class UTXOCacheTracepointTest(BitcoinTestFramework):
bpf.cleanup()
self.log.info(
f"check that we don't expect additional flushes and that the handle_* function succeeded")
"check that we don't expect additional flushes and that the handle_* function succeeded")
assert_equal(0, len(expected_flushes))
assert_equal(EXPECTED_HANDLE_FLUSH_SUCCESS, handle_flush_succeeds)

View file

@ -26,7 +26,7 @@ class DataCarrierTest(BitcoinTestFramework):
[],
["-datacarrier=0"],
["-datacarrier=1", f"-datacarriersize={MAX_OP_RETURN_RELAY - 1}"],
["-datacarrier=1", f"-datacarriersize=2"],
["-datacarrier=1", "-datacarriersize=2"],
]
def test_null_data_transaction(self, node: TestNode, data, success: bool) -> None:

View file

@ -231,7 +231,7 @@ class MempoolTRUC(BitcoinTestFramework):
assert_greater_than_or_equal(TRUC_CHILD_MAX_VSIZE, tx_v3_child_large2["tx"].get_vsize())
assert_greater_than(tx_v3_parent_large2["tx"].get_vsize() + tx_v3_child_large2["tx"].get_vsize(), 10000)
assert_raises_rpc_error(-26, f"too-long-mempool-chain, exceeds ancestor size limit", node.sendrawtransaction, tx_v3_child_large2["hex"])
assert_raises_rpc_error(-26, "too-long-mempool-chain, exceeds ancestor size limit", node.sendrawtransaction, tx_v3_child_large2["hex"])
self.check_mempool([tx_v3_parent_large2["txid"]])
@cleanup(extra_args=["-datacarriersize=1000"])

View file

@ -86,7 +86,7 @@ class P2PHandshakeTest(BitcoinTestFramework):
DESIRABLE_SERVICE_FLAGS_PRUNED, expect_disconnect=False)
self.log.info("Check that feeler connections get disconnected immediately")
with node.assert_debug_log([f"feeler connection completed"]):
with node.assert_debug_log(["feeler connection completed"]):
self.add_outbound_connection(node, "feeler", NODE_NONE, wait_for_disconnect=True)
self.log.info("Check that connecting to ourself leads to immediate disconnect")

View file

@ -67,14 +67,14 @@ class DumptxoutsetTest(BitcoinTestFramework):
assert_raises_rpc_error(
-8, "Couldn't open file {}.incomplete for writing".format(invalid_path), node.dumptxoutset, invalid_path, "latest")
self.log.info(f"Test that dumptxoutset with unknown dump type fails")
self.log.info("Test that dumptxoutset with unknown dump type fails")
assert_raises_rpc_error(
-8, 'Invalid snapshot type "bogus" specified. Please specify "rollback" or "latest"', node.dumptxoutset, 'utxos.dat', "bogus")
self.log.info(f"Test that dumptxoutset failure does not leave the network activity suspended when it was on previously")
self.log.info("Test that dumptxoutset failure does not leave the network activity suspended when it was on previously")
self.check_expected_network(node, True)
self.log.info(f"Test that dumptxoutset failure leaves the network activity suspended when it was off")
self.log.info("Test that dumptxoutset failure leaves the network activity suspended when it was off")
node.setnetworkactive(False)
self.check_expected_network(node, False)
node.setnetworkactive(True)

View file

@ -327,7 +327,7 @@ class CAddress:
elif self.net == self.NET_CJDNS:
self.ip = socket.inet_ntop(socket.AF_INET6, addr_bytes)
else:
raise Exception(f"Address type not supported")
raise Exception("Address type not supported")
self.port = int.from_bytes(f.read(2), "big")
@ -354,7 +354,7 @@ class CAddress:
elif self.net == self.NET_CJDNS:
r += socket.inet_pton(socket.AF_INET6, self.ip)
else:
raise Exception(f"Address type not supported")
raise Exception("Address type not supported")
r += self.port.to_bytes(2, "big")
return r

View file

@ -195,7 +195,7 @@ class Socks5Connection():
if not self.serv.keep_alive:
self.conn.close()
else:
logger.debug(f"Keeping client connection alive")
logger.debug("Keeping client connection alive")
class Socks5Server():
def __init__(self, conf):

View file

@ -157,7 +157,7 @@ class WalletBackupTest(BitcoinTestFramework):
node.pruneblockchain(250)
# The backup should be updated with the latest height (locator) for
# the backup to load successfully this close to the prune height
node.restorewallet(f'pruned', node.datadir_path / 'wallet_pruned.bak')
node.restorewallet('pruned', node.datadir_path / 'wallet_pruned.bak')
def run_test(self):
self.log.info("Generating initial blockchain")

View file

@ -49,7 +49,7 @@ class WalletFastRescanTest(BitcoinTestFramework):
assert_equal(len(descriptors), NUM_DESCRIPTORS)
w.backupwallet(WALLET_BACKUP_FILENAME)
self.log.info(f"Create txs sending to end range address of each descriptor, triggering top-ups")
self.log.info("Create txs sending to end range address of each descriptor, triggering top-ups")
for i in range(NUM_BLOCKS):
self.log.info(f"Block {i+1}/{NUM_BLOCKS}")
for desc_info in w.listdescriptors()['descriptors']:

View file

@ -53,8 +53,8 @@ class WalletMultisigDescriptorPSBTTest(BitcoinTestFramework):
for i, node in enumerate(self.nodes):
node.createwallet(wallet_name=f"{self.name}_{i}", blank=True, descriptors=True, disable_private_keys=True)
multisig = node.get_wallet_rpc(f"{self.name}_{i}")
external = multisig.getdescriptorinfo(f"wsh(sortedmulti({self.M},{f','.join(external_xpubs)}))")
internal = multisig.getdescriptorinfo(f"wsh(sortedmulti({self.M},{f','.join(internal_xpubs)}))")
external = multisig.getdescriptorinfo(f"wsh(sortedmulti({self.M},{','.join(external_xpubs)}))")
internal = multisig.getdescriptorinfo(f"wsh(sortedmulti({self.M},{','.join(internal_xpubs)}))")
result = multisig.importdescriptors([
{ # receiving addresses (internal: False)
"desc": external["descriptor"],

View file

@ -226,6 +226,7 @@ fn lint_py_lint() -> LintResult {
"F405", // foo_function may be undefined, or defined from star imports: bar_module
"F406", // "from module import *" only allowed at module level
"F407", // an undefined __future__ feature name was imported
"F541", // f-string without any placeholders
"F601", // dictionary key name repeated with different values
"F602", // dictionary key variable name repeated with different values
"F621", // too many expressions in an assignment with star-unpacking