0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-09 10:43:19 -05:00

test: detect OS consistently using platform.system()

This commit is contained in:
Sebastian Falbesoner 2023-12-08 17:30:19 +01:00
parent 37324ae3df
commit 4c65ac96f8
9 changed files with 24 additions and 20 deletions

View file

@ -6,8 +6,8 @@
import os import os
from pathlib import Path from pathlib import Path
import platform
import re import re
import sys
import tempfile import tempfile
import time import time
@ -116,7 +116,7 @@ class ConfArgsTest(BitcoinTestFramework):
def test_config_file_log(self): def test_config_file_log(self):
# Disable this test for windows currently because trying to override # Disable this test for windows currently because trying to override
# the default datadir through the environment does not seem to work. # the default datadir through the environment does not seem to work.
if sys.platform == "win32": if platform.system() == "Windows":
return return
self.log.info('Test that correct configuration path is changed when configuration file changes the datadir') self.log.info('Test that correct configuration path is changed when configuration file changes the datadir')
@ -339,7 +339,7 @@ class ConfArgsTest(BitcoinTestFramework):
def test_ignored_default_conf(self): def test_ignored_default_conf(self):
# Disable this test for windows currently because trying to override # Disable this test for windows currently because trying to override
# the default datadir through the environment does not seem to work. # the default datadir through the environment does not seem to work.
if sys.platform == "win32": if platform.system() == "Windows":
return return
self.log.info('Test error is triggered when bitcoin.conf in the default data directory sets another datadir ' self.log.info('Test error is triggered when bitcoin.conf in the default data directory sets another datadir '

View file

@ -3,8 +3,8 @@
# Distributed under the MIT software license, see the accompanying # Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Stress tests related to node initialization.""" """Stress tests related to node initialization."""
import os
from pathlib import Path from pathlib import Path
import platform
import shutil import shutil
from test_framework.test_framework import BitcoinTestFramework, SkipTest from test_framework.test_framework import BitcoinTestFramework, SkipTest
@ -36,7 +36,7 @@ class InitStressTest(BitcoinTestFramework):
# and other approaches (like below) don't work: # and other approaches (like below) don't work:
# #
# os.kill(node.process.pid, signal.CTRL_C_EVENT) # os.kill(node.process.pid, signal.CTRL_C_EVENT)
if os.name == 'nt': if platform.system() == 'Windows':
raise SkipTest("can't SIGTERM on Windows") raise SkipTest("can't SIGTERM on Windows")
self.stop_node(0) self.stop_node(0)

View file

@ -4,6 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test the -alertnotify, -blocknotify and -walletnotify options.""" """Test the -alertnotify, -blocknotify and -walletnotify options."""
import os import os
import platform
from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE from test_framework.address import ADDRESS_BCRT1_UNSPENDABLE
from test_framework.descriptors import descsum_create from test_framework.descriptors import descsum_create
@ -14,13 +15,13 @@ from test_framework.util import (
# Linux allow all characters other than \x00 # Linux allow all characters other than \x00
# Windows disallow control characters (0-31) and /\?%:|"<> # Windows disallow control characters (0-31) and /\?%:|"<>
FILE_CHAR_START = 32 if os.name == 'nt' else 1 FILE_CHAR_START = 32 if platform.system() == 'Windows' else 1
FILE_CHAR_END = 128 FILE_CHAR_END = 128
FILE_CHARS_DISALLOWED = '/\\?%*:|"<>' if os.name == 'nt' else '/' FILE_CHARS_DISALLOWED = '/\\?%*:|"<>' if platform.system() == 'Windows' else '/'
UNCONFIRMED_HASH_STRING = 'unconfirmed' UNCONFIRMED_HASH_STRING = 'unconfirmed'
def notify_outputname(walletname, txid): def notify_outputname(walletname, txid):
return txid if os.name == 'nt' else f'{walletname}_{txid}' return txid if platform.system() == 'Windows' else f'{walletname}_{txid}'
class NotificationsTest(BitcoinTestFramework): class NotificationsTest(BitcoinTestFramework):
@ -181,7 +182,7 @@ class NotificationsTest(BitcoinTestFramework):
# Universal newline ensures '\n' on 'nt' # Universal newline ensures '\n' on 'nt'
assert_equal(text[-1], '\n') assert_equal(text[-1], '\n')
text = text[:-1] text = text[:-1]
if os.name == 'nt': if platform.system() == 'Windows':
# On Windows, echo as above will append a whitespace # On Windows, echo as above will append a whitespace
assert_equal(text[-1], ' ') assert_equal(text[-1], ' ')
text = text[:-1] text = text[:-1]

View file

@ -4,6 +4,7 @@
# file COPYING or http://www.opensource.org/licenses/mit-license.php. # file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test removing undeleted pruned blk files on startup.""" """Test removing undeleted pruned blk files on startup."""
import platform
import os import os
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
@ -32,7 +33,7 @@ class FeatureRemovePrunedFilesOnStartupTest(BitcoinTestFramework):
self.nodes[0].pruneblockchain(600) self.nodes[0].pruneblockchain(600)
# Windows systems will not remove files with an open fd # Windows systems will not remove files with an open fd
if os.name != 'nt': if platform.system() != 'Windows':
assert not os.path.exists(blk0) assert not os.path.exists(blk0)
assert not os.path.exists(rev0) assert not os.path.exists(rev0)
assert not os.path.exists(blk1) assert not os.path.exists(blk1)

View file

@ -24,6 +24,7 @@ import asyncio
from collections import defaultdict from collections import defaultdict
from io import BytesIO from io import BytesIO
import logging import logging
import platform
import struct import struct
import sys import sys
import threading import threading
@ -592,7 +593,7 @@ class NetworkThread(threading.Thread):
NetworkThread.listeners = {} NetworkThread.listeners = {}
NetworkThread.protos = {} NetworkThread.protos = {}
if sys.platform == 'win32': if platform.system() == 'Windows':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
NetworkThread.network_event_loop = asyncio.new_event_loop() NetworkThread.network_event_loop = asyncio.new_event_loop()

View file

@ -12,6 +12,7 @@ import http.client
import json import json
import logging import logging
import os import os
import platform
import re import re
import subprocess import subprocess
import tempfile import tempfile
@ -19,7 +20,6 @@ import time
import urllib.parse import urllib.parse
import collections import collections
import shlex import shlex
import sys
from pathlib import Path from pathlib import Path
from .authproxy import ( from .authproxy import (
@ -567,7 +567,7 @@ class TestNode():
cmd, shell=True, cmd, shell=True,
stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL) == 0 stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL) == 0
if not sys.platform.startswith('linux'): if platform.system() != 'Linux':
self.log.warning("Can't profile with perf; only available on Linux platforms") self.log.warning("Can't profile with perf; only available on Linux platforms")
return None return None

View file

@ -13,8 +13,8 @@ import json
import logging import logging
import os import os
import pathlib import pathlib
import platform
import re import re
import sys
import time import time
from . import coverage from . import coverage
@ -414,12 +414,12 @@ def get_temp_default_datadir(temp_dir: pathlib.Path) -> tuple[dict, pathlib.Path
"""Return os-specific environment variables that can be set to make the """Return os-specific environment variables that can be set to make the
GetDefaultDataDir() function return a datadir path under the provided GetDefaultDataDir() function return a datadir path under the provided
temp_dir, as well as the complete path it would return.""" temp_dir, as well as the complete path it would return."""
if sys.platform == "win32": if platform.system() == "Windows":
env = dict(APPDATA=str(temp_dir)) env = dict(APPDATA=str(temp_dir))
datadir = temp_dir / "Bitcoin" datadir = temp_dir / "Bitcoin"
else: else:
env = dict(HOME=str(temp_dir)) env = dict(HOME=str(temp_dir))
if sys.platform == "darwin": if platform.system() == "Darwin":
datadir = temp_dir / "Library/Application Support/Bitcoin" datadir = temp_dir / "Library/Application Support/Bitcoin"
else: else:
datadir = temp_dir / ".bitcoin" datadir = temp_dir / ".bitcoin"

View file

@ -17,6 +17,7 @@ from collections import deque
import configparser import configparser
import datetime import datetime
import os import os
import platform
import time import time
import shutil import shutil
import signal import signal
@ -42,8 +43,8 @@ except UnicodeDecodeError:
CROSS = "x " CROSS = "x "
CIRCLE = "o " CIRCLE = "o "
if os.name != 'nt' or sys.getwindowsversion() >= (10, 0, 14393): #type:ignore if platform.system() != 'Windows' or sys.getwindowsversion() >= (10, 0, 14393): #type:ignore
if os.name == 'nt': if platform.system() == 'Windows':
import ctypes import ctypes
kernel32 = ctypes.windll.kernel32 # type: ignore kernel32 = ctypes.windll.kernel32 # type: ignore
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4 ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4

View file

@ -9,9 +9,9 @@ Verify that a bitcoind node can load multiple wallet files
from decimal import Decimal from decimal import Decimal
from threading import Thread from threading import Thread
import os import os
import platform
import shutil import shutil
import stat import stat
import sys
import time import time
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
@ -143,7 +143,7 @@ class MultiWalletTest(BitcoinTestFramework):
# should raise rpc error if wallet path can't be created # should raise rpc error if wallet path can't be created
err_code = -4 if self.options.descriptors else -1 err_code = -4 if self.options.descriptors else -1
assert_raises_rpc_error(err_code, "filesystem error:" if sys.platform != 'win32' else "create_directories:", self.nodes[0].createwallet, "w8/bad") assert_raises_rpc_error(err_code, "filesystem error:" if platform.system() != 'Windows' else "create_directories:", self.nodes[0].createwallet, "w8/bad")
# check that all requested wallets were created # check that all requested wallets were created
self.stop_node(0) self.stop_node(0)