[py]: replace `platform.system()` with `sys.platform` (#16259)
Co-authored-by: Corey Goldberg <1113081+cgoldberg@users.noreply.github.com>
NOKEYCHECK=True
GitOrigin-RevId: c585e6a6e97801c0f16c6c84e2295c794b7f1e5f
diff --git a/conftest.py b/conftest.py
index c790b27..37f76fb 100644
--- a/conftest.py
+++ b/conftest.py
@@ -16,7 +16,7 @@
# under the License.
import os
-import platform
+import sys
from dataclasses import dataclass
from pathlib import Path
@@ -182,7 +182,14 @@
@property
def exe_platform(self):
- return platform.system()
+ if sys.platform == "win32":
+ return "Windows"
+ elif sys.platform == "darwin":
+ return "Darwin"
+ elif sys.platform == "linux":
+ return "Linux"
+ else:
+ return sys.platform.title()
@property
def browser_path(self):
@@ -397,7 +404,7 @@
)
remote_env = os.environ.copy()
- if platform.system() == "Linux":
+ if sys.platform == "linux":
# There are issues with window size/position when running Firefox
# under Wayland, so we use XWayland instead.
remote_env["MOZ_ENABLE_WAYLAND"] = "0"
diff --git a/selenium/webdriver/common/service.py b/selenium/webdriver/common/service.py
index 7b3bdf8..d8e7ac0 100644
--- a/selenium/webdriver/common/service.py
+++ b/selenium/webdriver/common/service.py
@@ -19,10 +19,10 @@
import logging
import os
import subprocess
+import sys
from abc import ABC, abstractmethod
from collections.abc import Mapping
from io import IOBase
-from platform import system
from subprocess import PIPE
from time import sleep
from typing import IO, Any, Optional, Union, cast
@@ -205,13 +205,13 @@
"""
cmd = [path]
cmd.extend(self.command_line_args())
- close_file_descriptors = self.popen_kw.pop("close_fds", system() != "Windows")
+ close_file_descriptors = self.popen_kw.pop("close_fds", sys.platform != "win32")
try:
start_info = None
- if system() == "Windows":
- start_info = subprocess.STARTUPINFO() # type: ignore[attr-defined]
- start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW # type: ignore[attr-defined]
- start_info.wShowWindow = subprocess.SW_HIDE # type: ignore[attr-defined]
+ if sys.platform == "win32":
+ start_info = subprocess.STARTUPINFO()
+ start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
+ start_info.wShowWindow = subprocess.SW_HIDE
self.process = subprocess.Popen(
cmd,
diff --git a/selenium/webdriver/firefox/firefox_binary.py b/selenium/webdriver/firefox/firefox_binary.py
index 6490c1f..0932fa1 100644
--- a/selenium/webdriver/firefox/firefox_binary.py
+++ b/selenium/webdriver/firefox/firefox_binary.py
@@ -17,8 +17,8 @@
import os
+import sys
import time
-from platform import system
from subprocess import DEVNULL, STDOUT, Popen
from typing_extensions import deprecated
@@ -45,7 +45,7 @@
# a while the pipe would fill up and Firefox would freeze.
self._log_file = log_file or DEVNULL
self.command_line = None
- self.platform = system().lower()
+ self.platform = sys.platform
if not self._start_cmd:
self._start_cmd = self._get_firefox_start_cmd()
if not self._start_cmd.strip():
diff --git a/selenium/webdriver/remote/remote_connection.py b/selenium/webdriver/remote/remote_connection.py
index 031481c..2b496e4 100644
--- a/selenium/webdriver/remote/remote_connection.py
+++ b/selenium/webdriver/remote/remote_connection.py
@@ -16,8 +16,8 @@
# under the License.
import logging
-import platform
import string
+import sys
import warnings
from base64 import b64encode
from typing import Optional
@@ -156,7 +156,7 @@
_ca_certs = os.getenv("REQUESTS_CA_BUNDLE") if "REQUESTS_CA_BUNDLE" in os.environ else certifi.where()
_client_config: Optional[ClientConfig] = None
- system = platform.system().lower()
+ system = sys.platform
if system == "darwin":
system = "mac"
diff --git a/test/selenium/webdriver/firefox/firefox_sizing_tests.py b/test/selenium/webdriver/firefox/firefox_sizing_tests.py
index ce157bd..eade45f 100644
--- a/test/selenium/webdriver/firefox/firefox_sizing_tests.py
+++ b/test/selenium/webdriver/firefox/firefox_sizing_tests.py
@@ -16,7 +16,7 @@
# under the License.
import os
-import platform
+import sys
from unittest.mock import patch
import pytest
@@ -25,7 +25,7 @@
def is_running_wayland():
- return platform.system() == "Linux" and os.getenv("WAYLAND_DISPLAY")
+ return sys.platform == "linux" and os.getenv("WAYLAND_DISPLAY")
@pytest.mark.skipif(not is_running_wayland(), reason="This test only runs on Linux under Wayland")
diff --git a/test/unit/selenium/webdriver/chrome/chrome_options_tests.py b/test/unit/selenium/webdriver/chrome/chrome_options_tests.py
index 107a31e..2102f51 100644
--- a/test/unit/selenium/webdriver/chrome/chrome_options_tests.py
+++ b/test/unit/selenium/webdriver/chrome/chrome_options_tests.py
@@ -14,7 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-import platform
+import sys
from os import path
import pytest
@@ -91,7 +91,7 @@
def test_get_extensions_from_extension_files(options, mocker):
- null = "NUL" if platform.system().lower() == "windows" else "/dev/null"
+ null = "NUL" if sys.platform == "win32" else "/dev/null"
mocker.patch("selenium.webdriver.chromium.options.open").return_value = open(null)
mocker.patch("base64.b64encode").return_value = b"foo"
options._extension_files = ["foo"]