mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 17:54:19 +02:00
test/contrib: Fix invalid escapes in regex strings
Flagged by flake8 v3.6.0, as W605, plus a few others identified incidentally, e.g. 59ffecf66cf4d08c4b431e457b083878d66a3fd6. Note that r"\n" matches to "\n" under re.match/search.
This commit is contained in:
@@ -81,7 +81,7 @@ def read_logs(tmp_dir):
|
||||
chain = glob.glob("{}/node0/*/debug.log".format(tmp_dir))
|
||||
if chain:
|
||||
chain = chain[0] # pick the first one if more than one chain was found (should never happen)
|
||||
chain = re.search('node0/(.+?)/debug\.log$', chain).group(1) # extract the chain name
|
||||
chain = re.search(r'node0/(.+?)/debug\.log$', chain).group(1) # extract the chain name
|
||||
else:
|
||||
chain = 'regtest' # fallback to regtest (should only happen when none exists)
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class LoggingTest(BitcoinTestFramework):
|
||||
invdir = self.relative_log_path("foo")
|
||||
invalidname = os.path.join("foo", "foo.log")
|
||||
self.stop_node(0)
|
||||
exp_stderr = "Error: Could not open debug log file \S+$"
|
||||
exp_stderr = r"Error: Could not open debug log file \S+$"
|
||||
self.nodes[0].assert_start_raises_init_error(["-debuglogfile=%s" % (invalidname)], exp_stderr, match=ErrorMatch.FULL_REGEX)
|
||||
assert not os.path.isfile(os.path.join(invdir, "foo.log"))
|
||||
|
||||
|
||||
@@ -27,12 +27,12 @@ class UacommentTest(BitcoinTestFramework):
|
||||
|
||||
self.log.info("test -uacomment max length")
|
||||
self.stop_node(0)
|
||||
expected = "Error: Total length of network version string \([0-9]+\) exceeds maximum length \(256\). Reduce the number or size of uacomments."
|
||||
expected = r"Error: Total length of network version string \([0-9]+\) exceeds maximum length \(256\). Reduce the number or size of uacomments."
|
||||
self.nodes[0].assert_start_raises_init_error(["-uacomment=" + 'a' * 256], expected, match=ErrorMatch.FULL_REGEX)
|
||||
|
||||
self.log.info("test -uacomment unsafe characters")
|
||||
for unsafe_char in ['/', ':', '(', ')', '₿', '🏃']:
|
||||
expected = "Error: User Agent comment \(" + re.escape(unsafe_char) + "\) contains unsafe characters."
|
||||
expected = r"Error: User Agent comment \(" + re.escape(unsafe_char) + r"\) contains unsafe characters."
|
||||
self.nodes[0].assert_start_raises_init_error(["-uacomment=" + unsafe_char], expected, match=ErrorMatch.FULL_REGEX)
|
||||
|
||||
|
||||
|
||||
@@ -93,12 +93,12 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
|
||||
# should not initialize if one wallet is a copy of another
|
||||
shutil.copyfile(wallet_dir('w8'), wallet_dir('w8_copy'))
|
||||
exp_stderr = "BerkeleyBatch: Can't open database w8_copy \(duplicates fileid \w+ from w8\)"
|
||||
exp_stderr = r"BerkeleyBatch: Can't open database w8_copy \(duplicates fileid \w+ from w8\)"
|
||||
self.nodes[0].assert_start_raises_init_error(['-wallet=w8', '-wallet=w8_copy'], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
|
||||
|
||||
# should not initialize if wallet file is a symlink
|
||||
os.symlink('w8', wallet_dir('w8_symlink'))
|
||||
self.nodes[0].assert_start_raises_init_error(['-wallet=w8_symlink'], 'Error: Invalid -wallet path \'w8_symlink\'\. .*', match=ErrorMatch.FULL_REGEX)
|
||||
self.nodes[0].assert_start_raises_init_error(['-wallet=w8_symlink'], r'Error: Invalid -wallet path \'w8_symlink\'\. .*', match=ErrorMatch.FULL_REGEX)
|
||||
|
||||
# should not initialize if the specified walletdir does not exist
|
||||
self.nodes[0].assert_start_raises_init_error(['-walletdir=bad'], 'Error: Specified -walletdir "bad" does not exist')
|
||||
@@ -139,7 +139,7 @@ class MultiWalletTest(BitcoinTestFramework):
|
||||
competing_wallet_dir = os.path.join(self.options.tmpdir, 'competing_walletdir')
|
||||
os.mkdir(competing_wallet_dir)
|
||||
self.restart_node(0, ['-walletdir=' + competing_wallet_dir])
|
||||
exp_stderr = "Error: Error initializing wallet database environment \"\S+competing_walletdir\"!"
|
||||
exp_stderr = r"Error: Error initializing wallet database environment \"\S+competing_walletdir\"!"
|
||||
self.nodes[1].assert_start_raises_init_error(['-walletdir=' + competing_wallet_dir], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
|
||||
|
||||
self.restart_node(0, extra_args)
|
||||
|
||||
Reference in New Issue
Block a user