From fae76393bdbf867176e65447799d6ee3d3567b18 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Wed, 4 Dec 2024 14:42:27 +0100 Subject: [PATCH] test: Avoid F541 (f-string without any placeholders) --- contrib/tracing/log_raw_p2p_msgs.py | 6 +++--- test/functional/feature_anchors.py | 2 +- test/functional/feature_assumeutxo.py | 6 +++--- test/functional/feature_config_args.py | 4 ++-- test/functional/feature_dersig.py | 2 +- test/functional/feature_framework_miniwallet.py | 2 +- test/functional/feature_loadblock.py | 4 ++-- test/functional/interface_rest.py | 2 +- test/functional/interface_usdt_utxocache.py | 4 ++-- test/functional/mempool_datacarrier.py | 2 +- test/functional/mempool_truc.py | 2 +- test/functional/p2p_handshake.py | 2 +- test/functional/rpc_dumptxoutset.py | 6 +++--- test/functional/test_framework/messages.py | 4 ++-- test/functional/test_framework/socks5.py | 2 +- test/functional/wallet_backup.py | 2 +- test/functional/wallet_fast_rescan.py | 2 +- test/functional/wallet_multisig_descriptor_psbt.py | 4 ++-- test/lint/test_runner/src/main.rs | 1 + 19 files changed, 30 insertions(+), 29 deletions(-) diff --git a/contrib/tracing/log_raw_p2p_msgs.py b/contrib/tracing/log_raw_p2p_msgs.py index bd51c2eb7d934..9cda7fd08d4d0 100755 --- a/contrib/tracing/log_raw_p2p_msgs.py +++ b/contrib/tracing/log_raw_p2p_msgs.py @@ -117,9 +117,9 @@ 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"), diff --git a/test/functional/feature_anchors.py b/test/functional/feature_anchors.py index 5ca46c1366440..154461e739dd9 100755 --- a/test/functional/feature_anchors.py +++ b/test/functional/feature_anchors.py @@ -102,7 +102,7 @@ def run_test(self): 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() diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py index 138b3234621b2..8addb7e2385f7 100755 --- a/test/functional/feature_assumeutxo.py +++ b/test/functional/feature_assumeutxo.py @@ -165,8 +165,8 @@ def expected_error(log_msg="", error_msg=""): 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 @@ def check_dump_output(output): 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) diff --git a/test/functional/feature_config_args.py b/test/functional/feature_config_args.py index 1852fd28215fa..7bcee88fda3c4 100755 --- a/test/functional/feature_config_args.py +++ b/test/functional/feature_config_args.py @@ -72,7 +72,7 @@ def test_negated_config(self): 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 @@ def test_config_file_parser(self): # 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}'], diff --git a/test/functional/feature_dersig.py b/test/functional/feature_dersig.py index 1d18803f45ab1..f6b832106b121 100755 --- a/test/functional/feature_dersig.py +++ b/test/functional/feature_dersig.py @@ -130,7 +130,7 @@ def run_test(self): 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() diff --git a/test/functional/feature_framework_miniwallet.py b/test/functional/feature_framework_miniwallet.py index f723f7f31ee09..464f18eb48892 100755 --- a/test/functional/feature_framework_miniwallet.py +++ b/test/functional/feature_framework_miniwallet.py @@ -34,7 +34,7 @@ def test_tx_padding(self): 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): diff --git a/test/functional/feature_loadblock.py b/test/functional/feature_loadblock.py index 1519c132b9895..0e6ec14c77399 100755 --- a/test/functional/feature_loadblock.py +++ b/test/functional/feature_loadblock.py @@ -51,8 +51,8 @@ def run_test(self): 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") diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py index ba6e960476b98..ed117ae08b05f 100755 --- a/test/functional/interface_rest.py +++ b/test/functional/interface_rest.py @@ -209,7 +209,7 @@ def run_test(self): 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)]) diff --git a/test/functional/interface_usdt_utxocache.py b/test/functional/interface_usdt_utxocache.py index ad98a3a16287d..1617c580f30a6 100755 --- a/test/functional/interface_usdt_utxocache.py +++ b/test/functional/interface_usdt_utxocache.py @@ -393,7 +393,7 @@ def handle_utxocache_flush(_, data, __): 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 @@ def handle_utxocache_flush(_, data, __): 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) diff --git a/test/functional/mempool_datacarrier.py b/test/functional/mempool_datacarrier.py index ed6ad8461a138..48e636caa2221 100755 --- a/test/functional/mempool_datacarrier.py +++ b/test/functional/mempool_datacarrier.py @@ -26,7 +26,7 @@ def set_test_params(self): [], ["-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: diff --git a/test/functional/mempool_truc.py b/test/functional/mempool_truc.py index ff7542832699d..435b61f24f33c 100755 --- a/test/functional/mempool_truc.py +++ b/test/functional/mempool_truc.py @@ -231,7 +231,7 @@ def test_nondefault_package_limits(self): 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"]) diff --git a/test/functional/p2p_handshake.py b/test/functional/p2p_handshake.py index 18307a2824777..4148790c196b6 100755 --- a/test/functional/p2p_handshake.py +++ b/test/functional/p2p_handshake.py @@ -86,7 +86,7 @@ def run_test(self): 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") diff --git a/test/functional/rpc_dumptxoutset.py b/test/functional/rpc_dumptxoutset.py index ad05060210d1d..292744116b26f 100755 --- a/test/functional/rpc_dumptxoutset.py +++ b/test/functional/rpc_dumptxoutset.py @@ -67,14 +67,14 @@ def run_test(self): 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) diff --git a/test/functional/test_framework/messages.py b/test/functional/test_framework/messages.py index 1f566a1348a24..b4a5d9d5efa69 100755 --- a/test/functional/test_framework/messages.py +++ b/test/functional/test_framework/messages.py @@ -327,7 +327,7 @@ def deserialize_v2(self, f): 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 @@ def serialize_v2(self): 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 diff --git a/test/functional/test_framework/socks5.py b/test/functional/test_framework/socks5.py index 33726eaaaed61..0cd16a3ff53ad 100644 --- a/test/functional/test_framework/socks5.py +++ b/test/functional/test_framework/socks5.py @@ -195,7 +195,7 @@ def handle(self): 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): diff --git a/test/functional/wallet_backup.py b/test/functional/wallet_backup.py index 83267f77e17d9..7c88f64dcf382 100755 --- a/test/functional/wallet_backup.py +++ b/test/functional/wallet_backup.py @@ -157,7 +157,7 @@ def test_pruned_wallet_backup(self): 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") diff --git a/test/functional/wallet_fast_rescan.py b/test/functional/wallet_fast_rescan.py index 4ac441516e5f6..6cee0d3660848 100755 --- a/test/functional/wallet_fast_rescan.py +++ b/test/functional/wallet_fast_rescan.py @@ -49,7 +49,7 @@ def run_test(self): 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']: diff --git a/test/functional/wallet_multisig_descriptor_psbt.py b/test/functional/wallet_multisig_descriptor_psbt.py index 2e0b0d1a41b1a..a69185b3a5f69 100755 --- a/test/functional/wallet_multisig_descriptor_psbt.py +++ b/test/functional/wallet_multisig_descriptor_psbt.py @@ -53,8 +53,8 @@ def participants_create_multisigs(self, external_xpubs, internal_xpubs): 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"], diff --git a/test/lint/test_runner/src/main.rs b/test/lint/test_runner/src/main.rs index 42c880052ebd0..854c84a2d3e5f 100644 --- a/test/lint/test_runner/src/main.rs +++ b/test/lint/test_runner/src/main.rs @@ -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