test: use f-strings in feature_asmap.py

pull/826/head
fanquake 3 years ago
parent b5c468cfe3
commit 6f3d5ad67a
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

@ -31,8 +31,8 @@ ASMAP = '../../src/test/data/asmap.raw' # path to unit test skeleton asmap
VERSION = 'fec61fa21a9f46f3b17bdcd660d7f4cd90b966aad3aec593c99b35f0aca15853' VERSION = 'fec61fa21a9f46f3b17bdcd660d7f4cd90b966aad3aec593c99b35f0aca15853'
def expected_messages(filename): def expected_messages(filename):
return ['Opened asmap file "{}" (59 bytes) from disk'.format(filename), return [f'Opened asmap file "{filename}" (59 bytes) from disk',
'Using asmap version {} for IP bucketing'.format(VERSION)] f'Using asmap version {VERSION} for IP bucketing']
class AsmapTest(BitcoinTestFramework): class AsmapTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
@ -50,7 +50,7 @@ class AsmapTest(BitcoinTestFramework):
filename = os.path.join(self.datadir, 'my-map-file.map') filename = os.path.join(self.datadir, 'my-map-file.map')
shutil.copyfile(self.asmap_raw, filename) shutil.copyfile(self.asmap_raw, filename)
with self.node.assert_debug_log(expected_messages(filename)): with self.node.assert_debug_log(expected_messages(filename)):
self.start_node(0, ['-asmap={}'.format(filename)]) self.start_node(0, [f'-asmap={filename}'])
os.remove(filename) os.remove(filename)
def test_asmap_with_relative_path(self): def test_asmap_with_relative_path(self):
@ -60,13 +60,13 @@ class AsmapTest(BitcoinTestFramework):
filename = os.path.join(self.datadir, name) filename = os.path.join(self.datadir, name)
shutil.copyfile(self.asmap_raw, filename) shutil.copyfile(self.asmap_raw, filename)
with self.node.assert_debug_log(expected_messages(filename)): with self.node.assert_debug_log(expected_messages(filename)):
self.start_node(0, ['-asmap={}'.format(name)]) self.start_node(0, [f'-asmap={name}'])
os.remove(filename) os.remove(filename)
def test_default_asmap(self): def test_default_asmap(self):
shutil.copyfile(self.asmap_raw, self.default_asmap) shutil.copyfile(self.asmap_raw, self.default_asmap)
for arg in ['-asmap', '-asmap=']: for arg in ['-asmap', '-asmap=']:
self.log.info('Test bitcoind {} (using default map file)'.format(arg)) self.log.info(f'Test bitcoind {arg} (using default map file)')
self.stop_node(0) self.stop_node(0)
with self.node.assert_debug_log(expected_messages(self.default_asmap)): with self.node.assert_debug_log(expected_messages(self.default_asmap)):
self.start_node(0, [arg]) self.start_node(0, [arg])
@ -75,7 +75,7 @@ class AsmapTest(BitcoinTestFramework):
def test_default_asmap_with_missing_file(self): def test_default_asmap_with_missing_file(self):
self.log.info('Test bitcoind -asmap with missing default map file') self.log.info('Test bitcoind -asmap with missing default map file')
self.stop_node(0) self.stop_node(0)
msg = "Error: Could not find asmap file \"{}\"".format(self.default_asmap) msg = f"Error: Could not find asmap file \"{self.default_asmap}\""
self.node.assert_start_raises_init_error(extra_args=['-asmap'], expected_msg=msg) self.node.assert_start_raises_init_error(extra_args=['-asmap'], expected_msg=msg)
def test_empty_asmap(self): def test_empty_asmap(self):
@ -83,7 +83,7 @@ class AsmapTest(BitcoinTestFramework):
self.stop_node(0) self.stop_node(0)
with open(self.default_asmap, "w", encoding="utf-8") as f: with open(self.default_asmap, "w", encoding="utf-8") as f:
f.write("") f.write("")
msg = "Error: Could not parse asmap file \"{}\"".format(self.default_asmap) msg = f"Error: Could not parse asmap file \"{self.default_asmap}\""
self.node.assert_start_raises_init_error(extra_args=['-asmap'], expected_msg=msg) self.node.assert_start_raises_init_error(extra_args=['-asmap'], expected_msg=msg)
os.remove(self.default_asmap) os.remove(self.default_asmap)

Loading…
Cancel
Save