Skip to content

Commit 1c2f1cb

Browse files
committed
[py]: Lint webdriver/safari/ in preparation for consolidating the driver API
1 parent f4a8915 commit 1c2f1cb

File tree

5 files changed

+67
-41
lines changed

5 files changed

+67
-41
lines changed

py/selenium/webdriver/safari/options.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ class Options(ArgOptions):
3434
KEY = "safari.options"
3535

3636
# @see https://developer.apple.com/documentation/webkit/about_webdriver_for_safari
37-
AUTOMATIC_INSPECTION = 'safari:automaticInspection'
38-
AUTOMATIC_PROFILING = 'safari:automaticProfiling'
37+
AUTOMATIC_INSPECTION = "safari:automaticInspection"
38+
AUTOMATIC_PROFILING = "safari:automaticProfiling"
3939

40-
SAFARI_TECH_PREVIEW = 'Safari Technology Preview'
40+
SAFARI_TECH_PREVIEW = "Safari Technology Preview"
4141

4242
def __init__(self) -> None:
4343
super().__init__()
@@ -63,8 +63,7 @@ def binary_location(self, value: str) -> None:
6363
self._binary_location = value
6464

6565
def to_capabilities(self) -> dict:
66-
"""Marshals the options to an desired capabilities object.
67-
"""
66+
"""Marshals the options to an desired capabilities object."""
6867
# This intentionally looks at the internal properties
6968
# so if a binary or profile has _not_ been set,
7069
# it will defer to geckodriver to find the system Firefox
@@ -89,7 +88,7 @@ def default_capabilities(self) -> typing.Dict[str, str]:
8988

9089
@property
9190
def automatic_inspection(self) -> bool:
92-
""":Returns: The option Automatic Inspection value """
91+
""":Returns: The option Automatic Inspection value"""
9392
return self._caps.get(self.AUTOMATIC_INSPECTION)
9493

9594
@automatic_inspection.setter
@@ -105,7 +104,7 @@ def automatic_inspection(self, value: bool) -> None:
105104

106105
@property
107106
def automatic_profiling(self) -> bool:
108-
""":Returns: The options Automatic Profiling value """
107+
""":Returns: The options Automatic Profiling value"""
109108
return self._caps.get(self.AUTOMATIC_PROFILING)
110109

111110
@automatic_profiling.setter
@@ -122,7 +121,7 @@ def automatic_profiling(self, value: bool) -> None:
122121
@property
123122
def use_technology_preview(self) -> bool:
124123
""":Returns: whether BROWSER_NAME is equal to Safari Technology Preview"""
125-
return self._caps.get('browserName') == self.SAFARI_TECH_PREVIEW
124+
return self._caps.get("browserName") == self.SAFARI_TECH_PREVIEW
126125

127126
@use_technology_preview.setter
128127
def use_technology_preview(self, value: bool) -> None:
@@ -133,4 +132,4 @@ def use_technology_preview(self, value: bool) -> None:
133132
- value: boolean value
134133
135134
"""
136-
self.set_capability('browserName', self.SAFARI_TECH_PREVIEW if value else 'safari')
135+
self.set_capability("browserName", self.SAFARI_TECH_PREVIEW if value else "safari")

py/selenium/webdriver/safari/remote_connection.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
class SafariRemoteConnection(RemoteConnection):
2323

24-
browser_name = DesiredCapabilities.SAFARI['browserName']
24+
browser_name = DesiredCapabilities.SAFARI["browserName"]
2525

2626
def __init__(self, remote_server_addr, keep_alive=True, ignore_proxy=False):
2727
super().__init__(remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)
28-
self._commands["GET_PERMISSIONS"] = ('GET', '/session/$sessionId/apple/permissions')
29-
self._commands["SET_PERMISSIONS"] = ('POST', '/session/$sessionId/apple/permissions')
30-
self._commands["ATTACH_DEBUGGER"] = ('POST', '/session/$sessionId/apple/attach_debugger')
28+
self._commands["GET_PERMISSIONS"] = ("GET", "/session/$sessionId/apple/permissions")
29+
self._commands["SET_PERMISSIONS"] = ("POST", "/session/$sessionId/apple/permissions")
30+
self._commands["ATTACH_DEBUGGER"] = ("POST", "/session/$sessionId/apple/attach_debugger")

py/selenium/webdriver/safari/service.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,21 @@ class Service(service.Service):
2929
Object that manages the starting and stopping of the SafariDriver
3030
"""
3131

32-
def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
33-
port=0, quiet=False, service_args=None):
32+
def __init__(
33+
self,
34+
executable_path: str = DEFAULT_EXECUTABLE_PATH,
35+
port=0,
36+
quiet=False,
37+
service_args=None,
38+
):
3439
"""
3540
Creates a new instance of the Service
3641
3742
:Args:
3843
- executable_path : Path to the SafariDriver
3944
- port : Port the service is running on
4045
- quiet : Suppress driver stdout and stderr
41-
- service_args : List of args to pass to the safaridriver service """
46+
- service_args : List of args to pass to the safaridriver service"""
4247

4348
if not os.path.exists(executable_path):
4449
if "Safari Technology Preview" in executable_path:
@@ -55,7 +60,7 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
5560
self.quiet = quiet
5661
log = PIPE
5762
if quiet:
58-
log = open(os.devnull, 'w', encoding='utf-8')
63+
log = open(os.devnull, "w", encoding="utf-8")
5964
super().__init__(executable_path, port, log)
6065

6166
def command_line_args(self):

py/selenium/webdriver/safari/webdriver.py

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,18 @@ class WebDriver(RemoteWebDriver):
3636
3737
"""
3838

39-
def __init__(self, port=0, executable_path=DEFAULT_EXECUTABLE_PATH, reuse_service=False,
40-
desired_capabilities=DEFAULT_SAFARI_CAPS, quiet=False,
41-
keep_alive=True, service_args=None, options: Options = None, service: Service = None):
39+
def __init__(
40+
self,
41+
port=0,
42+
executable_path=DEFAULT_EXECUTABLE_PATH,
43+
reuse_service=False,
44+
desired_capabilities=DEFAULT_SAFARI_CAPS,
45+
quiet=False,
46+
keep_alive=True,
47+
service_args=None,
48+
options: Options = None,
49+
service: Service = None,
50+
):
4251
"""
4352
4453
Creates a new Safari driver instance and launches or finds a running safaridriver service.
@@ -55,28 +64,45 @@ def __init__(self, port=0, executable_path=DEFAULT_EXECUTABLE_PATH, reuse_servic
5564
- service - Service object for handling the browser driver if you need to pass extra details
5665
"""
5766
if port:
58-
warnings.warn("port has been deprecated, please set it via the service class",
59-
DeprecationWarning, stacklevel=2)
67+
warnings.warn(
68+
"port has been deprecated, please set it via the service class", DeprecationWarning, stacklevel=2
69+
)
6070

6171
if executable_path != DEFAULT_EXECUTABLE_PATH:
62-
warnings.warn("executable_path has been deprecated, please use the Options class to set it",
63-
DeprecationWarning, stacklevel=2)
72+
warnings.warn(
73+
"executable_path has been deprecated, please use the Options class to set it",
74+
DeprecationWarning,
75+
stacklevel=2,
76+
)
6477
if reuse_service:
65-
warnings.warn("reuse_service has been deprecated, please use the Service class to set it",
66-
DeprecationWarning, stacklevel=2)
78+
warnings.warn(
79+
"reuse_service has been deprecated, please use the Service class to set it",
80+
DeprecationWarning,
81+
stacklevel=2,
82+
)
6783
if desired_capabilities != DEFAULT_SAFARI_CAPS:
68-
warnings.warn("desired_capabilities has been deprecated, please use the Options class to set it",
69-
DeprecationWarning, stacklevel=2)
84+
warnings.warn(
85+
"desired_capabilities has been deprecated, please use the Options class to set it",
86+
DeprecationWarning,
87+
stacklevel=2,
88+
)
7089
if quiet:
71-
warnings.warn("quiet has been deprecated, please use the Service class to set it",
72-
DeprecationWarning, stacklevel=2)
90+
warnings.warn(
91+
"quiet has been deprecated, please use the Service class to set it", DeprecationWarning, stacklevel=2
92+
)
7393
if not keep_alive:
74-
warnings.warn("keep_alive has been deprecated, please use the Service class to set it",
75-
DeprecationWarning, stacklevel=2)
94+
warnings.warn(
95+
"keep_alive has been deprecated, please use the Service class to set it",
96+
DeprecationWarning,
97+
stacklevel=2,
98+
)
7699

77100
if service_args:
78-
warnings.warn("service_args has been deprecated, please use the Service class to set it",
79-
DeprecationWarning, stacklevel=2)
101+
warnings.warn(
102+
"service_args has been deprecated, please use the Service class to set it",
103+
DeprecationWarning,
104+
stacklevel=2,
105+
)
80106

81107
self._reuse_service = reuse_service
82108
if service:
@@ -86,13 +112,9 @@ def __init__(self, port=0, executable_path=DEFAULT_EXECUTABLE_PATH, reuse_servic
86112
if not reuse_service:
87113
self.service.start()
88114

89-
executor = SafariRemoteConnection(remote_server_addr=self.service.service_url,
90-
keep_alive=keep_alive)
115+
executor = SafariRemoteConnection(remote_server_addr=self.service.service_url, keep_alive=keep_alive)
91116

92-
super().__init__(
93-
command_executor=executor,
94-
options=options,
95-
desired_capabilities=desired_capabilities)
117+
super().__init__(command_executor=executor, options=options, desired_capabilities=desired_capabilities)
96118

97119
self._is_remote = False
98120

py/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ deps =
4242
flake8-typing-imports==1.13.0
4343
commands =
4444
isort selenium/ test/
45-
black test/ selenium/common/ -l 120
45+
black test/ selenium/common/ selenium/webdriver/safari -l 120
4646
flake8 selenium/ test/ --min-python-version=3.7

0 commit comments

Comments
 (0)