aboutsummaryrefslogtreecommitdiff
path: root/qa/rpc-tests/p2p-versionbits-warning.py
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2016-09-29 15:34:44 +0000
committerMarcoFalke <falke.marco@gmail.com>2016-10-03 11:54:29 +0200
commitcbc3fe59c4d92784411f5d40207ddde61fa5a892 (patch)
tree800641ca3653f66192283e5f4f3f5800a6c27051 /qa/rpc-tests/p2p-versionbits-warning.py
parent0bee740845b9c7599e041b0be7111c8debaff63b (diff)
downloadbitcoin-cbc3fe59c4d92784411f5d40207ddde61fa5a892.tar.xz
test: Explicitly set encoding to utf8 when opening text files
These are text files but their encoding does not depend on the locale. Not all of them require utf8 but it is better to fix it at something to remove potential unpredictability. This is necessary on FreeBSD where no locale is set by default, and apparently Python defaults not only the terminal encoding to the locale but that of every text file. So without LOCALE environment it defaults text file encoding to ASCII. This causes problems with e.g. `bitcoin.conf`. Luckily the locale doesn't affect the default encoding for str.encode() and bytes.decode() on Python 3, so this is the only change necessary. Github-Pull: #8840 Rebased-From: 30930e847e2483c7c8163cc581b392bc288250e9
Diffstat (limited to 'qa/rpc-tests/p2p-versionbits-warning.py')
-rwxr-xr-xqa/rpc-tests/p2p-versionbits-warning.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/qa/rpc-tests/p2p-versionbits-warning.py b/qa/rpc-tests/p2p-versionbits-warning.py
index 1fb4870e1a..fc3eddddee 100755
--- a/qa/rpc-tests/p2p-versionbits-warning.py
+++ b/qa/rpc-tests/p2p-versionbits-warning.py
@@ -72,7 +72,7 @@ class VersionBitsWarningTest(BitcoinTestFramework):
def setup_network(self):
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
# Open and close to create zero-length file
- with open(self.alert_filename, 'w') as _:
+ with open(self.alert_filename, 'w', encoding='utf8') as _:
pass
self.extra_args = [["-debug", "-logtimemicros=1", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]]
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)
@@ -95,7 +95,7 @@ class VersionBitsWarningTest(BitcoinTestFramework):
peer.sync_with_ping()
def test_versionbits_in_alert_file(self):
- with open(self.alert_filename, 'r') as f:
+ with open(self.alert_filename, 'r', encoding='utf8') as f:
alert_text = f.read()
assert(VB_PATTERN.match(alert_text))
@@ -146,7 +146,7 @@ class VersionBitsWarningTest(BitcoinTestFramework):
self.nodes[0].generate(VB_PERIOD)
stop_nodes(self.nodes)
# Empty out the alert file
- with open(self.alert_filename, 'w') as _:
+ with open(self.alert_filename, 'w', encoding='utf8') as _:
pass
self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)