Skip to content

Commit c585e6a

Browse files
navin772cgoldberg
andauthored
[py]: replace platform.system() with sys.platform (#16259)
Co-authored-by: Corey Goldberg <[email protected]>
1 parent d3cef1a commit c585e6a

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

py/conftest.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717

1818
import os
19-
import platform
19+
import sys
2020
from dataclasses import dataclass
2121
from pathlib import Path
2222

@@ -182,7 +182,14 @@ def driver_class(self, cls_name):
182182

183183
@property
184184
def exe_platform(self):
185-
return platform.system()
185+
if sys.platform == "win32":
186+
return "Windows"
187+
elif sys.platform == "darwin":
188+
return "Darwin"
189+
elif sys.platform == "linux":
190+
return "Linux"
191+
else:
192+
return sys.platform.title()
186193

187194
@property
188195
def browser_path(self):
@@ -397,7 +404,7 @@ def server(request):
397404
)
398405

399406
remote_env = os.environ.copy()
400-
if platform.system() == "Linux":
407+
if sys.platform == "linux":
401408
# There are issues with window size/position when running Firefox
402409
# under Wayland, so we use XWayland instead.
403410
remote_env["MOZ_ENABLE_WAYLAND"] = "0"

py/selenium/webdriver/common/service.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
import logging
2020
import os
2121
import subprocess
22+
import sys
2223
from abc import ABC, abstractmethod
2324
from collections.abc import Mapping
2425
from io import IOBase
25-
from platform import system
2626
from subprocess import PIPE
2727
from time import sleep
2828
from typing import IO, Any, Optional, Union, cast
@@ -205,13 +205,13 @@ def _start_process(self, path: str) -> None:
205205
"""
206206
cmd = [path]
207207
cmd.extend(self.command_line_args())
208-
close_file_descriptors = self.popen_kw.pop("close_fds", system() != "Windows")
208+
close_file_descriptors = self.popen_kw.pop("close_fds", sys.platform != "win32")
209209
try:
210210
start_info = None
211-
if system() == "Windows":
212-
start_info = subprocess.STARTUPINFO() # type: ignore[attr-defined]
213-
start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW # type: ignore[attr-defined]
214-
start_info.wShowWindow = subprocess.SW_HIDE # type: ignore[attr-defined]
211+
if sys.platform == "win32":
212+
start_info = subprocess.STARTUPINFO()
213+
start_info.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
214+
start_info.wShowWindow = subprocess.SW_HIDE
215215

216216
self.process = subprocess.Popen(
217217
cmd,

py/selenium/webdriver/firefox/firefox_binary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818

1919
import os
20+
import sys
2021
import time
21-
from platform import system
2222
from subprocess import DEVNULL, STDOUT, Popen
2323

2424
from typing_extensions import deprecated
@@ -45,7 +45,7 @@ def __init__(self, firefox_path=None, log_file=None):
4545
# a while the pipe would fill up and Firefox would freeze.
4646
self._log_file = log_file or DEVNULL
4747
self.command_line = None
48-
self.platform = system().lower()
48+
self.platform = sys.platform
4949
if not self._start_cmd:
5050
self._start_cmd = self._get_firefox_start_cmd()
5151
if not self._start_cmd.strip():

py/selenium/webdriver/remote/remote_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
# under the License.
1717

1818
import logging
19-
import platform
2019
import string
20+
import sys
2121
import warnings
2222
from base64 import b64encode
2323
from typing import Optional
@@ -156,7 +156,7 @@ class RemoteConnection:
156156
_ca_certs = os.getenv("REQUESTS_CA_BUNDLE") if "REQUESTS_CA_BUNDLE" in os.environ else certifi.where()
157157
_client_config: Optional[ClientConfig] = None
158158

159-
system = platform.system().lower()
159+
system = sys.platform
160160
if system == "darwin":
161161
system = "mac"
162162

py/test/selenium/webdriver/firefox/firefox_sizing_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717

1818
import os
19-
import platform
19+
import sys
2020
from unittest.mock import patch
2121

2222
import pytest
@@ -25,7 +25,7 @@
2525

2626

2727
def is_running_wayland():
28-
return platform.system() == "Linux" and os.getenv("WAYLAND_DISPLAY")
28+
return sys.platform == "linux" and os.getenv("WAYLAND_DISPLAY")
2929

3030

3131
@pytest.mark.skipif(not is_running_wayland(), reason="This test only runs on Linux under Wayland")

py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
import platform
17+
import sys
1818
from os import path
1919

2020
import pytest
@@ -91,7 +91,7 @@ def test_add_encoded_extension(options):
9191

9292

9393
def test_get_extensions_from_extension_files(options, mocker):
94-
null = "NUL" if platform.system().lower() == "windows" else "/dev/null"
94+
null = "NUL" if sys.platform == "win32" else "/dev/null"
9595
mocker.patch("selenium.webdriver.chromium.options.open").return_value = open(null)
9696
mocker.patch("base64.b64encode").return_value = b"foo"
9797
options._extension_files = ["foo"]

0 commit comments

Comments
 (0)