mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
test: use f-strings in feature_config_args.py
This commit is contained in:
parent
36d33d32b1
commit
e2f1fd8ee9
1 changed files with 13 additions and 13 deletions
|
@ -24,7 +24,7 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||||
|
|
||||||
inc_conf_file_path = os.path.join(self.nodes[0].datadir, 'include.conf')
|
inc_conf_file_path = os.path.join(self.nodes[0].datadir, 'include.conf')
|
||||||
with open(os.path.join(self.nodes[0].datadir, 'bitcoin.conf'), 'a', encoding='utf-8') as conf:
|
with open(os.path.join(self.nodes[0].datadir, 'bitcoin.conf'), 'a', encoding='utf-8') as conf:
|
||||||
conf.write('includeconf={}\n'.format(inc_conf_file_path))
|
conf.write(f'includeconf={inc_conf_file_path}\n')
|
||||||
|
|
||||||
self.nodes[0].assert_start_raises_init_error(
|
self.nodes[0].assert_start_raises_init_error(
|
||||||
expected_msg='Error: Error parsing command line arguments: Invalid parameter -dash_cli=1',
|
expected_msg='Error: Error parsing command line arguments: Invalid parameter -dash_cli=1',
|
||||||
|
@ -43,13 +43,13 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||||
if self.is_wallet_compiled():
|
if self.is_wallet_compiled():
|
||||||
with open(inc_conf_file_path, 'w', encoding='utf8') as conf:
|
with open(inc_conf_file_path, 'w', encoding='utf8') as conf:
|
||||||
conf.write("wallet=foo\n")
|
conf.write("wallet=foo\n")
|
||||||
self.nodes[0].assert_start_raises_init_error(expected_msg='Error: Config setting for -wallet only applied on %s network when in [%s] section.' % (self.chain, self.chain))
|
self.nodes[0].assert_start_raises_init_error(expected_msg=f'Error: Config setting for -wallet only applied on {self.chain} network when in [{self.chain}] section.')
|
||||||
|
|
||||||
main_conf_file_path = os.path.join(self.options.tmpdir, 'node0', 'bitcoin_main.conf')
|
main_conf_file_path = os.path.join(self.options.tmpdir, 'node0', 'bitcoin_main.conf')
|
||||||
util.write_config(main_conf_file_path, n=0, chain='', extra_config='includeconf={}\n'.format(inc_conf_file_path))
|
util.write_config(main_conf_file_path, n=0, chain='', extra_config=f'includeconf={inc_conf_file_path}\n')
|
||||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||||
conf.write('acceptnonstdtxn=1\n')
|
conf.write('acceptnonstdtxn=1\n')
|
||||||
self.nodes[0].assert_start_raises_init_error(extra_args=["-conf={}".format(main_conf_file_path)], expected_msg='Error: acceptnonstdtxn is not currently supported for main chain')
|
self.nodes[0].assert_start_raises_init_error(extra_args=[f"-conf={main_conf_file_path}"], expected_msg='Error: acceptnonstdtxn is not currently supported for main chain')
|
||||||
|
|
||||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||||
conf.write('nono\n')
|
conf.write('nono\n')
|
||||||
|
@ -69,14 +69,14 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||||
|
|
||||||
inc_conf_file2_path = os.path.join(self.nodes[0].datadir, 'include2.conf')
|
inc_conf_file2_path = os.path.join(self.nodes[0].datadir, 'include2.conf')
|
||||||
with open(os.path.join(self.nodes[0].datadir, 'bitcoin.conf'), 'a', encoding='utf-8') as conf:
|
with open(os.path.join(self.nodes[0].datadir, 'bitcoin.conf'), 'a', encoding='utf-8') as conf:
|
||||||
conf.write('includeconf={}\n'.format(inc_conf_file2_path))
|
conf.write(f'includeconf={inc_conf_file2_path}\n')
|
||||||
|
|
||||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||||
conf.write('testnot.datadir=1\n')
|
conf.write('testnot.datadir=1\n')
|
||||||
with open(inc_conf_file2_path, 'w', encoding='utf-8') as conf:
|
with open(inc_conf_file2_path, 'w', encoding='utf-8') as conf:
|
||||||
conf.write('[testnet]\n')
|
conf.write('[testnet]\n')
|
||||||
self.restart_node(0)
|
self.restart_node(0)
|
||||||
self.nodes[0].stop_node(expected_stderr='Warning: ' + inc_conf_file_path + ':1 Section [testnot] is not recognized.' + os.linesep + inc_conf_file2_path + ':1 Section [testnet] is not recognized.')
|
self.nodes[0].stop_node(expected_stderr=f'Warning: {inc_conf_file_path}:1 Section [testnot] is not recognized.{os.linesep}{inc_conf_file2_path}:1 Section [testnet] is not recognized.')
|
||||||
|
|
||||||
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
|
||||||
conf.write('') # clear
|
conf.write('') # clear
|
||||||
|
@ -105,8 +105,8 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||||
'Command-line arg: rpcpassword=****',
|
'Command-line arg: rpcpassword=****',
|
||||||
'Command-line arg: rpcuser=****',
|
'Command-line arg: rpcuser=****',
|
||||||
'Command-line arg: torpassword=****',
|
'Command-line arg: torpassword=****',
|
||||||
'Config file arg: %s="1"' % self.chain,
|
f'Config file arg: {self.chain}="1"',
|
||||||
'Config file arg: [%s] server="1"' % self.chain,
|
f'Config file arg: [{self.chain}] server="1"',
|
||||||
],
|
],
|
||||||
unexpected_msgs=[
|
unexpected_msgs=[
|
||||||
'alice:f7efda5c189b999524f151318c0c86$d5b51b3beffbc0',
|
'alice:f7efda5c189b999524f151318c0c86$d5b51b3beffbc0',
|
||||||
|
@ -235,7 +235,7 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# Check that using -datadir argument on non-existent directory fails
|
# Check that using -datadir argument on non-existent directory fails
|
||||||
self.nodes[0].datadir = new_data_dir
|
self.nodes[0].datadir = new_data_dir
|
||||||
self.nodes[0].assert_start_raises_init_error(['-datadir=' + new_data_dir], 'Error: Specified data directory "' + new_data_dir + '" does not exist.')
|
self.nodes[0].assert_start_raises_init_error([f'-datadir={new_data_dir}'], f'Error: Specified data directory "{new_data_dir}" does not exist.')
|
||||||
|
|
||||||
# Check that using non-existent datadir in conf file fails
|
# Check that using non-existent datadir in conf file fails
|
||||||
conf_file = os.path.join(default_data_dir, "bitcoin.conf")
|
conf_file = os.path.join(default_data_dir, "bitcoin.conf")
|
||||||
|
@ -243,21 +243,21 @@ class ConfArgsTest(BitcoinTestFramework):
|
||||||
# datadir needs to be set before [chain] section
|
# datadir needs to be set before [chain] section
|
||||||
conf_file_contents = open(conf_file, encoding='utf8').read()
|
conf_file_contents = open(conf_file, encoding='utf8').read()
|
||||||
with open(conf_file, 'w', encoding='utf8') as f:
|
with open(conf_file, 'w', encoding='utf8') as f:
|
||||||
f.write("datadir=" + new_data_dir + "\n")
|
f.write(f"datadir={new_data_dir}\n")
|
||||||
f.write(conf_file_contents)
|
f.write(conf_file_contents)
|
||||||
|
|
||||||
self.nodes[0].assert_start_raises_init_error(['-conf=' + conf_file], 'Error: Error reading configuration file: specified data directory "' + new_data_dir + '" does not exist.')
|
self.nodes[0].assert_start_raises_init_error([f'-conf={conf_file}'], f'Error: Error reading configuration file: specified data directory "{new_data_dir}" does not exist.')
|
||||||
|
|
||||||
# Create the directory and ensure the config file now works
|
# Create the directory and ensure the config file now works
|
||||||
os.mkdir(new_data_dir)
|
os.mkdir(new_data_dir)
|
||||||
self.start_node(0, ['-conf='+conf_file])
|
self.start_node(0, [f'-conf={conf_file}'])
|
||||||
self.stop_node(0)
|
self.stop_node(0)
|
||||||
assert os.path.exists(os.path.join(new_data_dir, self.chain, 'blocks'))
|
assert os.path.exists(os.path.join(new_data_dir, self.chain, 'blocks'))
|
||||||
|
|
||||||
# Ensure command line argument overrides datadir in conf
|
# Ensure command line argument overrides datadir in conf
|
||||||
os.mkdir(new_data_dir_2)
|
os.mkdir(new_data_dir_2)
|
||||||
self.nodes[0].datadir = new_data_dir_2
|
self.nodes[0].datadir = new_data_dir_2
|
||||||
self.start_node(0, ['-datadir='+new_data_dir_2, '-conf='+conf_file])
|
self.start_node(0, [f'-datadir={new_data_dir_2}', f'-conf={conf_file}'])
|
||||||
assert os.path.exists(os.path.join(new_data_dir_2, self.chain, 'blocks'))
|
assert os.path.exists(os.path.join(new_data_dir_2, self.chain, 'blocks'))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue