diff --git a/contrib/zmq/zmq_sub27.py b/contrib/zmq/zmq_sub27.py --- a/contrib/zmq/zmq_sub27.py +++ b/contrib/zmq/zmq_sub27.py @@ -15,7 +15,7 @@ zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "hashtx") zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "rawblock") zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "rawtx") -zmqSubSocket.connect("tcp://127.0.0.1:%i" % port) +zmqSubSocket.connect("tcp://127.0.0.1:{}".format(port)) try: while True: diff --git a/share/qt/extract_strings_qt.py b/share/qt/extract_strings_qt.py --- a/share/qt/extract_strings_qt.py +++ b/share/qt/extract_strings_qt.py @@ -81,17 +81,14 @@ #endif """) f.write('static const char UNUSED *bitcoin_strings[] = {\n') -f.write('QT_TRANSLATE_NOOP("bitcoin-core", "%s"),\n' % - (os.getenv('PACKAGE_NAME'),)) -f.write('QT_TRANSLATE_NOOP("bitcoin-core", "%s"),\n' % - (os.getenv('COPYRIGHT_HOLDERS'),)) +f.write('QT_TRANSLATE_NOOP("bitcoin-core", "{}"),\n'.format((os.getenv('PACKAGE_NAME'),))) +f.write('QT_TRANSLATE_NOOP("bitcoin-core", "{}"),\n'.format((os.getenv('COPYRIGHT_HOLDERS'),))) if os.getenv('COPYRIGHT_HOLDERS_SUBSTITUTION') != os.getenv('PACKAGE_NAME'): - f.write('QT_TRANSLATE_NOOP("bitcoin-core", "%s"),\n' % - (os.getenv('COPYRIGHT_HOLDERS_SUBSTITUTION'),)) + f.write('QT_TRANSLATE_NOOP("bitcoin-core", "{}"),\n'.format( + (os.getenv('COPYRIGHT_HOLDERS_SUBSTITUTION'),))) messages.sort(key=operator.itemgetter(0)) for (msgid, msgstr) in messages: if msgid != EMPTY: - f.write('QT_TRANSLATE_NOOP("bitcoin-core", %s),\n' % - ('\n'.join(msgid))) + f.write('QT_TRANSLATE_NOOP("bitcoin-core", {}),\n'.format('\n'.join(msgid))) f.write('};\n') f.close() diff --git a/test/functional/combine_logs.py b/test/functional/combine_logs.py --- a/test/functional/combine_logs.py +++ b/test/functional/combine_logs.py @@ -53,12 +53,12 @@ Delegates to generator function get_log_events() to provide individual log events for each of the input log files.""" - files = [("test", "%s/test_framework.log" % tmp_dir)] + files = [("test", "{}/test_framework.log".format(tmp_dir))] for i in itertools.count(): logfile = "{}/node{}/regtest/debug.log".format(tmp_dir, i) if not os.path.isfile(logfile): break - files.append(("node%d" % i, logfile)) + files.append(("node{}".format(i), logfile)) return heapq.merge(*[get_log_events(source, f) for source, f in files]) @@ -89,8 +89,7 @@ # Flush the final event yield LogEvent(timestamp=timestamp, source=source, event=event.rstrip()) except FileNotFoundError: - print("File %s could not be opened. Continuing without it." % - logfile, file=sys.stderr) + print("File {} could not be opened. Continuing without it.".format(logfile), file=sys.stderr) def print_logs(log_events, color=False, html=False): diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -104,8 +104,8 @@ log_stdout = tempfile.SpooledTemporaryFile(max_size=2**16) log_stderr = tempfile.SpooledTemporaryFile(max_size=2**16) test_argv = t.split() - tmpdir = [os.path.join("--tmpdir=%s", "%s_%s") % - (self.tmpdir, re.sub(".py$", "", t), portseed)] + tmpdir = [os.path.join("--tmpdir={}", "{}_{}").format( + self.tmpdir, re.sub(".py$", "", t), portseed)] name = t time0 = time.time() process = subprocess.Popen([os.path.join(self.tests_dir, test_argv[0])] + test_argv[1:] + self.flags + portseed_arg + tmpdir, @@ -178,18 +178,18 @@ # Create a set to store arguments and create the passon string tests = set(arg for arg in unknown_args if arg[:2] != "--") passon_args = [arg for arg in unknown_args if arg[:2] == "--"] - passon_args.append("--configfile=%s" % configfile) + passon_args.append("--configfile={}".format(configfile)) # Set up logging logging_level = logging.INFO if args.quiet else logging.DEBUG logging.basicConfig(format='%(message)s', level=logging_level) # Create base test directory - tmpdir = os.path.join("%s", "bitcoin_test_runner_%s") % ( - args.tmpdirprefix, datetime.datetime.now().strftime("%Y%m%d_%H%M%S")) + tmpdir = os.path.join("{}", "bitcoin_test_runner_{:%Y%m%d_%H%M%S}").format( + args.tmpdirprefix, datetime.datetime.now()) os.makedirs(tmpdir) - logging.debug("Temporary test directory at %s" % tmpdir) + logging.debug("Temporary test directory at {}".format(tmpdir)) enable_wallet = config["components"].getboolean("ENABLE_WALLET") enable_utils = config["components"].getboolean("ENABLE_UTILS") @@ -280,7 +280,7 @@ try: pidofOutput = subprocess.check_output(["pidof", "bitcoind"]) if pidofOutput is not None and pidofOutput != b'': - print("%sWARNING!%s There is already a bitcoind process running on this system. Tests may fail unexpectedly due to resource contention!" % ( + print("{}WARNING!{} There is already a bitcoind process running on this system. Tests may fail unexpectedly due to resource contention!".format( BOLD[1], BOLD[0])) except (OSError, subprocess.SubprocessError): pass @@ -288,7 +288,7 @@ # Warn if there is a cache directory cache_dir = os.path.join(build_dir, "test", "cache") if os.path.isdir(cache_dir): - print("%sWARNING!%s There is a cache directory here: %s. If tests fail unexpectedly, try deleting the cache directory." % ( + print("{}WARNING!{} There is a cache directory here: {}. If tests fail unexpectedly, try deleting the cache directory.".format( BOLD[1], BOLD[0], cache_dir)) # Set env vars @@ -299,12 +299,13 @@ build_dir, 'src', 'bitcoin-cli' + exeext) flags = [os.path.join("--srcdir={}".format(build_dir), "src")] + args - flags.append("--cachedir=%s" % cache_dir) + flags.append("--cachedir={}".format(cache_dir)) if enable_coverage: coverage = RPCCoverage() flags.append(coverage.flag) - logging.debug("Initializing coverage directory at %s" % coverage.dir) + logging.debug( + "Initializing coverage directory at {}".format(coverage.dir)) else: coverage = None @@ -312,7 +313,7 @@ # Populate cache try: subprocess.check_output( - [os.path.join(tests_dir, 'create_cache.py')] + flags + [os.path.join("--tmpdir=%s", "cache") % tmpdir]) + [os.path.join(tests_dir, 'create_cache.py')] + flags + [os.path.join("--tmpdir={}", "cache") .format(tmpdir)]) except Exception as e: print(e.output) raise e @@ -376,14 +377,14 @@ test_results.append(test_result) if test_result.status == "Passed": - print("%s%s%s passed, Duration: %s s" % ( + print("{}{}{} passed, Duration: {} s".format( BOLD[1], test_result.name, BOLD[0], test_result.time)) elif test_result.status == "Skipped": - print("%s%s%s skipped" % - (BOLD[1], test_result.name, BOLD[0])) + print("{}{}{} skipped".format( + BOLD[1], test_result.name, BOLD[0])) else: - print("%s%s%s failed, Duration: %s s\n" % - (BOLD[1], test_result.name, BOLD[0], test_result.time)) + print("{}{}{} failed, Duration: {} s\n".format( + BOLD[1], test_result.name, BOLD[0], test_result.time)) print(BOLD[1] + 'stdout:' + BOLD[0]) print(test_result.stdout) print(BOLD[1] + 'stderr:' + BOLD[0]) @@ -472,7 +473,7 @@ def print_results(test_results, max_len_name, runtime): - results = "\n" + BOLD[1] + "%s | %s | %s\n\n" % ( + results = "\n" + BOLD[1] + "{} | {} | {}\n\n".format( "TEST".ljust(max_len_name), "STATUS ", "DURATION") + BOLD[0] test_results.sort(key=lambda result: result.name.lower()) @@ -486,9 +487,9 @@ results += str(test_result) status = TICK + "Passed" if all_passed else CROSS + "Failed" - results += BOLD[1] + "\n%s | %s | %s s (accumulated) \n" % ( + results += BOLD[1] + "\n{} | {} | {} s (accumulated) \n".format( "ALL".ljust(max_len_name), status.ljust(9), time_sum) + BOLD[0] - results += "Runtime: %s s\n" % (runtime) + results += "Runtime: {} s\n".format(runtime) print(results) @@ -516,7 +517,8 @@ color = GREY glyph = CIRCLE - return color[1] + "%s | %s%s | %s s\n" % (self.name.ljust(self.padding), glyph, self.status.ljust(7), self.time) + color[0] + return color[1] + "{} | {}{} | {} s\n".format( + self.name.ljust(self.padding), glyph, self.status.ljust(7), self.time) + color[0] @property def was_successful(self): diff --git a/test/functional/wallet_listsinceblock.py b/test/functional/wallet_listsinceblock.py --- a/test/functional/wallet_listsinceblock.py +++ b/test/functional/wallet_listsinceblock.py @@ -59,7 +59,7 @@ # generate on both sides lastblockhash = self.nodes[1].generate(6)[5] self.nodes[2].generate(7) - self.log.info('lastblockhash=%s' % (lastblockhash)) + self.log.info('lastblockhash={}'.format(lastblockhash)) self.sync_all([self.nodes[:2], self.nodes[2:]]) diff --git a/test/util/bitcoin-util-test.py b/test/util/bitcoin-util-test.py --- a/test/util/bitcoin-util-test.py +++ b/test/util/bitcoin-util-test.py @@ -118,14 +118,14 @@ try: a_parsed = parse_output(outs[0], outputType) except Exception as e: - logging.error('Error parsing command output as %s: %s' % - (outputType, e)) + logging.error( + 'Error parsing command output as {}: {}'.format(outputType, e)) raise try: b_parsed = parse_output(outputData, outputType) except Exception as e: - logging.error('Error parsing expected output %s as %s: %s' % - (outputFn, outputType, e)) + logging.error('Error parsing expected output {} as {}: {}'.format( + outputFn, outputType, e)) raise # Compare data if a_parsed != b_parsed: @@ -176,7 +176,7 @@ elif fmt == 'hex': # hex: parse and compare binary data return binascii.a2b_hex(a.strip()) else: - raise NotImplementedError("Don't know how to compare %s" % fmt) + raise NotImplementedError("Don't know how to compare {}".format(fmt)) if __name__ == '__main__':