Skip to content

Commit 4c65ac9

Browse files
committed
test: detect OS consistently using platform.system()
1 parent 37324ae commit 4c65ac9

File tree

9 files changed

+24
-20
lines changed

9 files changed

+24
-20
lines changed

test/functional/feature_config_args.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import os
88
from pathlib import Path
9+
import platform
910
import re
10-
import sys
1111
import tempfile
1212
import time
1313

@@ -116,7 +116,7 @@ def test_config_file_parser(self):
116116
def test_config_file_log(self):
117117
# Disable this test for windows currently because trying to override
118118
# the default datadir through the environment does not seem to work.
119-
if sys.platform == "win32":
119+
if platform.system() == "Windows":
120120
return
121121

122122
self.log.info('Test that correct configuration path is changed when configuration file changes the datadir')
@@ -339,7 +339,7 @@ def test_ignored_conf(self):
339339
def test_ignored_default_conf(self):
340340
# Disable this test for windows currently because trying to override
341341
# the default datadir through the environment does not seem to work.
342-
if sys.platform == "win32":
342+
if platform.system() == "Windows":
343343
return
344344

345345
self.log.info('Test error is triggered when bitcoin.conf in the default data directory sets another datadir '

test/functional/feature_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Stress tests related to node initialization."""
6-
import os
76
from pathlib import Path
7+
import platform
88
import shutil
99

1010
from test_framework.test_framework import BitcoinTestFramework, SkipTest
@@ -36,7 +36,7 @@ def run_test(self):
3636
# and other approaches (like below) don't work:
3737
#
3838
# os.kill(node.process.pid, signal.CTRL_C_EVENT)
39-
if os.name == 'nt':
39+
if platform.system() == 'Windows':
4040
raise SkipTest("can't SIGTERM on Windows")
4141

4242
self.stop_node(0)

test/functional/feature_notifications.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the -alertnotify, -blocknotify and -walletnotify options."""
66
import os
7+
import platform
78

89
from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE
910
from test_framework.descriptors import descsum_create
@@ -14,13 +15,13 @@
1415

1516
# Linux allow all characters other than \x00
1617
# Windows disallow control characters (0-31) and /\?%:|"<>
17-
FILE_CHAR_START = 32 if os.name == 'nt' else 1
18+
FILE_CHAR_START = 32 if platform.system() == 'Windows' else 1
1819
FILE_CHAR_END = 128
19-
FILE_CHARS_DISALLOWED = '/\\?%*:|"<>' if os.name == 'nt' else '/'
20+
FILE_CHARS_DISALLOWED = '/\\?%*:|"<>' if platform.system() == 'Windows' else '/'
2021
UNCONFIRMED_HASH_STRING = 'unconfirmed'
2122

2223
def notify_outputname(walletname, txid):
23-
return txid if os.name == 'nt' else f'{walletname}_{txid}'
24+
return txid if platform.system() == 'Windows' else f'{walletname}_{txid}'
2425

2526

2627
class NotificationsTest(BitcoinTestFramework):
@@ -181,7 +182,7 @@ def expect_wallet_notify(self, tx_details):
181182
# Universal newline ensures '\n' on 'nt'
182183
assert_equal(text[-1], '\n')
183184
text = text[:-1]
184-
if os.name == 'nt':
185+
if platform.system() == 'Windows':
185186
# On Windows, echo as above will append a whitespace
186187
assert_equal(text[-1], ' ')
187188
text = text[:-1]

test/functional/feature_remove_pruned_files_on_startup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test removing undeleted pruned blk files on startup."""
66

7+
import platform
78
import os
89
from test_framework.test_framework import BitcoinTestFramework
910

@@ -32,7 +33,7 @@ def run_test(self):
3233
self.nodes[0].pruneblockchain(600)
3334

3435
# Windows systems will not remove files with an open fd
35-
if os.name != 'nt':
36+
if platform.system() != 'Windows':
3637
assert not os.path.exists(blk0)
3738
assert not os.path.exists(rev0)
3839
assert not os.path.exists(blk1)

test/functional/test_framework/p2p.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from collections import defaultdict
2525
from io import BytesIO
2626
import logging
27+
import platform
2728
import struct
2829
import sys
2930
import threading
@@ -592,7 +593,7 @@ def __init__(self):
592593

593594
NetworkThread.listeners = {}
594595
NetworkThread.protos = {}
595-
if sys.platform == 'win32':
596+
if platform.system() == 'Windows':
596597
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
597598
NetworkThread.network_event_loop = asyncio.new_event_loop()
598599

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
import json
1313
import logging
1414
import os
15+
import platform
1516
import re
1617
import subprocess
1718
import tempfile
1819
import time
1920
import urllib.parse
2021
import collections
2122
import shlex
22-
import sys
2323
from pathlib import Path
2424

2525
from .authproxy import (
@@ -567,7 +567,7 @@ def test_success(cmd):
567567
cmd, shell=True,
568568
stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL) == 0
569569

570-
if not sys.platform.startswith('linux'):
570+
if platform.system() != 'Linux':
571571
self.log.warning("Can't profile with perf; only available on Linux platforms")
572572
return None
573573

test/functional/test_framework/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import logging
1414
import os
1515
import pathlib
16+
import platform
1617
import re
17-
import sys
1818
import time
1919

2020
from . import coverage
@@ -414,12 +414,12 @@ def get_temp_default_datadir(temp_dir: pathlib.Path) -> tuple[dict, pathlib.Path
414414
"""Return os-specific environment variables that can be set to make the
415415
GetDefaultDataDir() function return a datadir path under the provided
416416
temp_dir, as well as the complete path it would return."""
417-
if sys.platform == "win32":
417+
if platform.system() == "Windows":
418418
env = dict(APPDATA=str(temp_dir))
419419
datadir = temp_dir / "Bitcoin"
420420
else:
421421
env = dict(HOME=str(temp_dir))
422-
if sys.platform == "darwin":
422+
if platform.system() == "Darwin":
423423
datadir = temp_dir / "Library/Application Support/Bitcoin"
424424
else:
425425
datadir = temp_dir / ".bitcoin"

test/functional/test_runner.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import configparser
1818
import datetime
1919
import os
20+
import platform
2021
import time
2122
import shutil
2223
import signal
@@ -42,8 +43,8 @@
4243
CROSS = "x "
4344
CIRCLE = "o "
4445

45-
if os.name != 'nt' or sys.getwindowsversion() >= (10, 0, 14393): #type:ignore
46-
if os.name == 'nt':
46+
if platform.system() != 'Windows' or sys.getwindowsversion() >= (10, 0, 14393): #type:ignore
47+
if platform.system() == 'Windows':
4748
import ctypes
4849
kernel32 = ctypes.windll.kernel32 # type: ignore
4950
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4

test/functional/wallet_multiwallet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
from decimal import Decimal
1010
from threading import Thread
1111
import os
12+
import platform
1213
import shutil
1314
import stat
14-
import sys
1515
import time
1616

1717
from test_framework.authproxy import JSONRPCException
@@ -143,7 +143,7 @@ def wallet_file(name):
143143

144144
# should raise rpc error if wallet path can't be created
145145
err_code = -4 if self.options.descriptors else -1
146-
assert_raises_rpc_error(err_code, "filesystem error:" if sys.platform != 'win32' else "create_directories:", self.nodes[0].createwallet, "w8/bad")
146+
assert_raises_rpc_error(err_code, "filesystem error:" if platform.system() != 'Windows' else "create_directories:", self.nodes[0].createwallet, "w8/bad")
147147

148148
# check that all requested wallets were created
149149
self.stop_node(0)

0 commit comments

Comments
 (0)