Skip to content

Commit

Permalink
[py]: Apply black on the rest of the code base
Browse files Browse the repository at this point in the history
  • Loading branch information
symonk committed Oct 2, 2022
1 parent 6b4281b commit e2add16
Show file tree
Hide file tree
Showing 66 changed files with 1,597 additions and 1,460 deletions.
2 changes: 1 addition & 1 deletion py/selenium/webdriver/__init__.py
Expand Up @@ -36,7 +36,7 @@
from .wpewebkit.options import Options as WPEWebKitOptions # noqa
from .wpewebkit.webdriver import WebDriver as WPEWebKit # noqa

__version__ = '4.5.0'
__version__ = "4.5.0"

# We need an explicit __all__ because the above won't otherwise be exported.
__all__ = [
Expand Down
12 changes: 6 additions & 6 deletions py/selenium/webdriver/chrome/options.py
Expand Up @@ -22,14 +22,14 @@


class Options(ChromiumOptions):

@property
def default_capabilities(self) -> dict:
return DesiredCapabilities.CHROME.copy()

def enable_mobile(self,
android_package: str = "com.android.chrome",
android_activity: Optional[str] = None,
device_serial: Optional[str] = None
) -> None:
def enable_mobile(
self,
android_package: str = "com.android.chrome",
android_activity: Optional[str] = None,
device_serial: Optional[str] = None,
) -> None:
super().enable_mobile(android_package, android_activity, device_serial)
19 changes: 10 additions & 9 deletions py/selenium/webdriver/chrome/service.py
Expand Up @@ -27,9 +27,14 @@ class Service(service.ChromiumService):
Object that manages the starting and stopping of the ChromeDriver
"""

def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
port: int = 0, service_args: List[str] = None,
log_path: str = None, env: dict = None):
def __init__(
self,
executable_path: str = DEFAULT_EXECUTABLE_PATH,
port: int = 0,
service_args: List[str] = None,
log_path: str = None,
env: dict = None,
):
"""
Creates a new instance of the Service
Expand All @@ -40,9 +45,5 @@ def __init__(self, executable_path: str = DEFAULT_EXECUTABLE_PATH,
- log_path : Path for the chromedriver service to log to"""

super().__init__(
executable_path,
port,
service_args,
log_path,
env,
"Please see https://chromedriver.chromium.org/home")
executable_path, port, service_args, log_path, env, "Please see https://chromedriver.chromium.org/home"
)
46 changes: 31 additions & 15 deletions py/selenium/webdriver/chrome/webdriver.py
Expand Up @@ -35,10 +35,18 @@ class WebDriver(ChromiumDriver):
http://chromedriver.storage.googleapis.com/index.html
"""

def __init__(self, executable_path=DEFAULT_EXECUTABLE_PATH, port=DEFAULT_PORT,
options: Options = None, service_args=None,
desired_capabilities=None, service_log_path=DEFAULT_SERVICE_LOG_PATH,
chrome_options=None, service: Service = None, keep_alive=DEFAULT_KEEP_ALIVE):
def __init__(
self,
executable_path=DEFAULT_EXECUTABLE_PATH,
port=DEFAULT_PORT,
options: Options = None,
service_args=None,
desired_capabilities=None,
service_log_path=DEFAULT_SERVICE_LOG_PATH,
chrome_options=None,
service: Service = None,
keep_alive=DEFAULT_KEEP_ALIVE,
):
"""
Creates a new instance of the chrome driver.
Starts the service and then creates new instance of chrome driver.
Expand All @@ -54,22 +62,30 @@ def __init__(self, executable_path=DEFAULT_EXECUTABLE_PATH, port=DEFAULT_PORT,
- service_log_path - Deprecated: Where to log information from the driver.
- keep_alive - Deprecated: Whether to configure ChromeRemoteConnection to use HTTP keep-alive.
"""
if executable_path != 'chromedriver':
warnings.warn('executable_path has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
if executable_path != "chromedriver":
warnings.warn(
"executable_path has been deprecated, please pass in a Service object", DeprecationWarning, stacklevel=2
)
if chrome_options:
warnings.warn('use options instead of chrome_options',
DeprecationWarning, stacklevel=2)
warnings.warn("use options instead of chrome_options", DeprecationWarning, stacklevel=2)
options = chrome_options
if keep_alive != DEFAULT_KEEP_ALIVE:
warnings.warn('keep_alive has been deprecated, please pass in a Service object',
DeprecationWarning, stacklevel=2)
warnings.warn(
"keep_alive has been deprecated, please pass in a Service object", DeprecationWarning, stacklevel=2
)
else:
keep_alive = True
if not service:
service = Service(executable_path, port, service_args, service_log_path)

super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
port, options,
service_args, desired_capabilities,
service_log_path, service, keep_alive)
super().__init__(
DesiredCapabilities.CHROME["browserName"],
"goog",
port,
options,
service_args,
desired_capabilities,
service_log_path,
service,
keep_alive,
)
23 changes: 12 additions & 11 deletions py/selenium/webdriver/chromium/options.py
Expand Up @@ -31,7 +31,7 @@ class ChromiumOptions(ArgOptions):

def __init__(self) -> None:
super().__init__()
self._binary_location = ''
self._binary_location = ""
self._extension_files = []
self._extensions = []
self._experimental_options = {}
Expand Down Expand Up @@ -76,6 +76,7 @@ def extensions(self) -> List[str]:
"""
:Returns: A list of encoded extensions that will be loaded
"""

def _decode(file_data: BinaryIO) -> str:
# Should not use base64.encodestring() which inserts newlines every
# 76 characters (per RFC 1521). Chromedriver has to remove those
Expand Down Expand Up @@ -143,7 +144,7 @@ def headless(self) -> bool:
"""
:Returns: True if the headless argument is set, else False
"""
return '--headless' in self._arguments
return "--headless" in self._arguments

@headless.setter
def headless(self, value: bool) -> None:
Expand All @@ -152,7 +153,7 @@ def headless(self, value: bool) -> None:
:Args:
value: boolean value indicating to set the headless option
"""
args = {'--headless'}
args = {"--headless"}
if value is True:
self._arguments.extend(args)
else:
Expand All @@ -165,17 +166,17 @@ def to_capabilities(self) -> dict:
"""
caps = self._caps
chrome_options = self.experimental_options.copy()
if 'w3c' in chrome_options:
if chrome_options['w3c']:
if "w3c" in chrome_options:
if chrome_options["w3c"]:
warnings.warn(
"Setting 'w3c: True' is redundant and will no longer be allowed",
DeprecationWarning,
stacklevel=2
"Setting 'w3c: True' is redundant and will no longer be allowed", DeprecationWarning, stacklevel=2
)
else:
raise AttributeError('setting w3c to False is not allowed, '
'Please update to W3C Syntax: '
'https://www.selenium.dev/blog/2022/legacy-protocol-support/')
raise AttributeError(
"setting w3c to False is not allowed, "
"Please update to W3C Syntax: "
"https://www.selenium.dev/blog/2022/legacy-protocol-support/"
)
if self.mobile_options:
chrome_options.update(self.mobile_options)
chrome_options["extensions"] = self.extensions
Expand Down
41 changes: 23 additions & 18 deletions py/selenium/webdriver/chromium/remote_connection.py
Expand Up @@ -20,23 +20,28 @@


class ChromiumRemoteConnection(RemoteConnection):
def __init__(self,
remote_server_addr: str,
vendor_prefix: str,
browser_name: str,
keep_alive: bool = True,
ignore_proxy: typing.Optional[bool] = False):
def __init__(
self,
remote_server_addr: str,
vendor_prefix: str,
browser_name: str,
keep_alive: bool = True,
ignore_proxy: typing.Optional[bool] = False,
):
super().__init__(remote_server_addr, keep_alive, ignore_proxy=ignore_proxy)
self.browser_name = browser_name
self._commands["launchApp"] = ('POST', '/session/$sessionId/chromium/launch_app')
self._commands["setPermissions"] = ('POST', '/session/$sessionId/permissions')
self._commands["setNetworkConditions"] = ('POST', '/session/$sessionId/chromium/network_conditions')
self._commands["getNetworkConditions"] = ('GET', '/session/$sessionId/chromium/network_conditions')
self._commands["deleteNetworkConditions"] = ('DELETE', '/session/$sessionId/chromium/network_conditions')
self._commands['executeCdpCommand'] = ('POST', f'/session/$sessionId/{vendor_prefix}/cdp/execute')
self._commands['getSinks'] = ('GET', f'/session/$sessionId/{vendor_prefix}/cast/get_sinks')
self._commands['getIssueMessage'] = ('GET', f'/session/$sessionId/{vendor_prefix}/cast/get_issue_message')
self._commands['setSinkToUse'] = ('POST', f'/session/$sessionId/{vendor_prefix}/cast/set_sink_to_use')
self._commands['startDesktopMirroring'] = ('POST', f'/session/$sessionId/{vendor_prefix}/cast/start_desktop_mirroring')
self._commands['startTabMirroring'] = ('POST', f'/session/$sessionId/{vendor_prefix}/cast/start_tab_mirroring')
self._commands['stopCasting'] = ('POST', f'/session/$sessionId/{vendor_prefix}/cast/stop_casting')
self._commands["launchApp"] = ("POST", "/session/$sessionId/chromium/launch_app")
self._commands["setPermissions"] = ("POST", "/session/$sessionId/permissions")
self._commands["setNetworkConditions"] = ("POST", "/session/$sessionId/chromium/network_conditions")
self._commands["getNetworkConditions"] = ("GET", "/session/$sessionId/chromium/network_conditions")
self._commands["deleteNetworkConditions"] = ("DELETE", "/session/$sessionId/chromium/network_conditions")
self._commands["executeCdpCommand"] = ("POST", f"/session/$sessionId/{vendor_prefix}/cdp/execute")
self._commands["getSinks"] = ("GET", f"/session/$sessionId/{vendor_prefix}/cast/get_sinks")
self._commands["getIssueMessage"] = ("GET", f"/session/$sessionId/{vendor_prefix}/cast/get_issue_message")
self._commands["setSinkToUse"] = ("POST", f"/session/$sessionId/{vendor_prefix}/cast/set_sink_to_use")
self._commands["startDesktopMirroring"] = (
"POST",
f"/session/$sessionId/{vendor_prefix}/cast/start_desktop_mirroring",
)
self._commands["startTabMirroring"] = ("POST", f"/session/$sessionId/{vendor_prefix}/cast/start_tab_mirroring")
self._commands["stopCasting"] = ("POST", f"/session/$sessionId/{vendor_prefix}/cast/stop_casting")
13 changes: 10 additions & 3 deletions py/selenium/webdriver/chromium/service.py
Expand Up @@ -25,8 +25,15 @@ class ChromiumService(service.Service):
Object that manages the starting and stopping the WebDriver instance of the ChromiumDriver
"""

def __init__(self, executable_path: str, port: int = 0, service_args: List[str] = None,
log_path: str = None, env: dict = None, start_error_message: str = None):
def __init__(
self,
executable_path: str,
port: int = 0,
service_args: List[str] = None,
log_path: str = None,
env: dict = None,
start_error_message: str = None,
):
"""
Creates a new instance of the Service
Expand All @@ -38,7 +45,7 @@ def __init__(self, executable_path: str, port: int = 0, service_args: List[str]

self.service_args = service_args or []
if log_path:
self.service_args.append('--log-path=%s' % log_path)
self.service_args.append("--log-path=%s" % log_path)

if not start_error_message:
raise AttributeError("start_error_message should not be empty")
Expand Down

0 comments on commit e2add16

Please sign in to comment.