Skip to content

Commit bd3d308

Browse files
committed
Fix flake8 issues in Python client
1 parent 319f431 commit bd3d308

File tree

107 files changed

+980
-886
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+980
-886
lines changed

py/selenium/common/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from . import exceptions
18+
from . import exceptions # noqa

py/selenium/common/exceptions.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Exceptions that may happen in all the webdriver code.
2020
"""
2121

22+
2223
class WebDriverException(Exception):
2324
"""
2425
Base webdriver exception.
@@ -38,6 +39,7 @@ def __str__(self):
3839
exception_msg += "Stacktrace:\n%s" % stacktrace
3940
return exception_msg
4041

42+
4143
class ErrorInResponseException(WebDriverException):
4244
"""
4345
Thrown when an error has occurred on the server side.
@@ -49,52 +51,58 @@ def __init__(self, response, msg):
4951
WebDriverException.__init__(self, msg)
5052
self.response = response
5153

54+
5255
class InvalidSwitchToTargetException(WebDriverException):
5356
"""
5457
Thrown when frame or window target to be switched doesn't exist.
5558
"""
5659
pass
5760

61+
5862
class NoSuchFrameException(InvalidSwitchToTargetException):
5963
"""
6064
Thrown when frame target to be switched doesn't exist.
6165
"""
6266
pass
6367

68+
6469
class NoSuchWindowException(InvalidSwitchToTargetException):
6570
"""
6671
Thrown when window target to be switched doesn't exist.
6772
68-
To find the current set of active window handles, you can get a list
73+
To find the current set of active window handles, you can get a list
6974
of the active window handles in the following way::
7075
7176
print driver.window_handles
7277
7378
"""
7479
pass
7580

81+
7682
class NoSuchElementException(WebDriverException):
7783
"""
7884
Thrown when element could not be found.
7985
8086
If you encounter this exception, you may want to check the following:
8187
* Check your selector used in your find_by...
8288
* Element may not yet be on the screen at the time of the find operation,
83-
(webpage is still loading) see selenium.webdriver.support.wait.WebDriverWait()
89+
(webpage is still loading) see selenium.webdriver.support.wait.WebDriverWait()
8490
for how to write a wait wrapper to wait for an element to appear.
8591
"""
8692
pass
8793

94+
8895
class NoSuchAttributeException(WebDriverException):
8996
"""
9097
Thrown when the attribute of element could not be found.
9198
92-
You may want to check if the attribute exists in the particular browser you are
93-
testing against. Some browsers may have different property names for the same
99+
You may want to check if the attribute exists in the particular browser you are
100+
testing against. Some browsers may have different property names for the same
94101
property. (IE8's .innerText vs. Firefox .textContent)
95102
"""
96103
pass
97104

105+
98106
class StaleElementReferenceException(WebDriverException):
99107
"""
100108
Thrown when a reference to an element is now "stale".
@@ -103,26 +111,28 @@ class StaleElementReferenceException(WebDriverException):
103111
104112
105113
Possible causes of StaleElementReferenceException include, but not limited to:
106-
* You are no longer on the same page, or the page may have refreshed since the element
114+
* You are no longer on the same page, or the page may have refreshed since the element
107115
was located.
108116
* The element may have been removed and re-added to the screen, since it was located.
109-
Such as an element being relocated.
110-
This can happen typically with a javascript framework when values are updated and the
117+
Such as an element being relocated.
118+
This can happen typically with a javascript framework when values are updated and the
111119
node is rebuilt.
112120
* Element may have been inside an iframe or another context which was refreshed.
113121
"""
114122
pass
115123

116-
class InvalidElementStateException(WebDriverException):
124+
125+
class InvalidElementStateException(WebDriverException):
117126
"""
118127
"""
119128
pass
120129

130+
121131
class UnexpectedAlertPresentException(WebDriverException):
122132
"""
123133
Thrown when an unexpected alert is appeared.
124-
125-
Usually raised when when an expected modal is blocking webdriver form executing any
134+
135+
Usually raised when when an expected modal is blocking webdriver form executing any
126136
more commands.
127137
"""
128138
def __init__(self, msg=None, screen=None, stacktrace=None, alert_text=None):
@@ -132,70 +142,80 @@ def __init__(self, msg=None, screen=None, stacktrace=None, alert_text=None):
132142
def __str__(self):
133143
return "Alert Text: %s\n%s" % (self.alert_text, super(UnexpectedAlertPresentException, self).__str__())
134144

145+
135146
class NoAlertPresentException(WebDriverException):
136147
"""
137148
Thrown when switching to no presented alert.
138149
139-
This can be caused by calling an operation on the Alert() class when an alert is
150+
This can be caused by calling an operation on the Alert() class when an alert is
140151
not yet on the screen.
141152
"""
142153
pass
143154

155+
144156
class ElementNotVisibleException(InvalidElementStateException):
145157
"""
146-
Thrown when an element is present on the DOM, but
158+
Thrown when an element is present on the DOM, but
147159
it is not visible, and so is not able to be interacted with.
148160
149-
Most commonly encountered when trying to click or read text
161+
Most commonly encountered when trying to click or read text
150162
of an element that is hidden from view.
151163
"""
152164
pass
153165

166+
154167
class ElementNotSelectableException(InvalidElementStateException):
155168
"""
156169
Thrown when trying to select an unselectable element.
157-
170+
158171
For example, selecting a 'script' element.
159172
"""
160173
pass
161174

175+
162176
class InvalidCookieDomainException(WebDriverException):
163177
"""
164178
Thrown when attempting to add a cookie under a different domain
165179
than the current URL.
166180
"""
167181
pass
168182

183+
169184
class UnableToSetCookieException(WebDriverException):
170185
"""
171186
Thrown when a driver fails to set a cookie.
172187
"""
173188
pass
174189

190+
175191
class RemoteDriverServerException(WebDriverException):
176192
"""
177193
"""
178194
pass
179195

196+
180197
class TimeoutException(WebDriverException):
181198
"""
182199
Thrown when a command does not complete in enough time.
183200
"""
184201
pass
185202

203+
186204
class MoveTargetOutOfBoundsException(WebDriverException):
187205
"""
188-
Thrown when the target provided to the `ActionsChains` move()
206+
Thrown when the target provided to the `ActionsChains` move()
189207
method is invalid, i.e. out of document.
190208
"""
191209
pass
192210

211+
193212
class UnexpectedTagNameException(WebDriverException):
194213
"""
195214
Thrown when a support class did not get an expected web element.
196215
"""
197216
pass
198217

218+
199219
class InvalidSelectorException(NoSuchElementException):
200220
"""
201221
Thrown when the selector which is used to find an element does not return
@@ -206,13 +226,15 @@ class InvalidSelectorException(NoSuchElementException):
206226
"""
207227
pass
208228

229+
209230
class ImeNotAvailableException(WebDriverException):
210231
"""
211232
Thrown when IME support is not available. This exception is thrown for every IME-related
212233
method call if IME support is not available on the machine.
213234
"""
214235
pass
215236

237+
216238
class ImeActivationFailedException(WebDriverException):
217239
"""
218240
Thrown when activating an IME engine has failed.

py/selenium/webdriver/__init__.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from .firefox.webdriver import WebDriver as Firefox
19-
from .firefox.firefox_profile import FirefoxProfile
20-
from .chrome.webdriver import WebDriver as Chrome
21-
from .chrome.options import Options as ChromeOptions
22-
from .ie.webdriver import WebDriver as Ie
23-
from .edge.webdriver import WebDriver as Edge
24-
from .opera.webdriver import WebDriver as Opera
25-
from .safari.webdriver import WebDriver as Safari
26-
from .blackberry.webdriver import WebDriver as BlackBerry
27-
from .phantomjs.webdriver import WebDriver as PhantomJS
28-
from .android.webdriver import WebDriver as Android
29-
from .remote.webdriver import WebDriver as Remote
30-
from .common.desired_capabilities import DesiredCapabilities
31-
from .common.action_chains import ActionChains
32-
from .common.touch_actions import TouchActions
33-
from .common.proxy import Proxy
18+
from .firefox.webdriver import WebDriver as Firefox # noqa
19+
from .firefox.firefox_profile import FirefoxProfile # noqa
20+
from .chrome.webdriver import WebDriver as Chrome # noqa
21+
from .chrome.options import Options as ChromeOptions # noqa
22+
from .ie.webdriver import WebDriver as Ie # noqa
23+
from .edge.webdriver import WebDriver as Edge # noqa
24+
from .opera.webdriver import WebDriver as Opera # noqa
25+
from .safari.webdriver import WebDriver as Safari # noqa
26+
from .blackberry.webdriver import WebDriver as BlackBerry # noqa
27+
from .phantomjs.webdriver import WebDriver as PhantomJS # noqa
28+
from .android.webdriver import WebDriver as Android # noqa
29+
from .remote.webdriver import WebDriver as Remote # noqa
30+
from .common.desired_capabilities import DesiredCapabilities # noqa
31+
from .common.action_chains import ActionChains # noqa
32+
from .common.touch_actions import TouchActions # noqa
33+
from .common.proxy import Proxy # noqa
3434

3535
__version__ = '2.53.5'

py/selenium/webdriver/android/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-

py/selenium/webdriver/android/webdriver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import base64
1918
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
2019
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
2120

21+
2222
class WebDriver(RemoteWebDriver):
2323
"""
2424
Simple RemoteWebDriver wrapper to start connect to Selendroid's WebView app
@@ -36,7 +36,7 @@ def __init__(self, host="localhost", port=4444, desired_capabilities=DesiredCapa
3636
- port - port that selendroid is running on
3737
- desired_capabilities: Dictionary object with capabilities
3838
"""
39-
RemoteWebDriver.__init__(self,
39+
RemoteWebDriver.__init__(
40+
self,
4041
command_executor="http://%s:%d/wd/hub" % (host, port),
4142
desired_capabilities=desired_capabilities)
42-

py/selenium/webdriver/blackberry/webdriver.py

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

1818
import os
1919
import platform
20-
import time
2120
import subprocess
2221

23-
from selenium.webdriver.remote.command import Command
22+
try:
23+
import http.client as http_client
24+
except ImportError:
25+
import httplib as http_client
26+
2427
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
2528
from selenium.common.exceptions import WebDriverException
2629
from selenium.webdriver.support.ui import WebDriverWait

py/selenium/webdriver/chrome/remote_connection.py

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

1818
from selenium.webdriver.remote.remote_connection import RemoteConnection
1919

20+
2021
class ChromeRemoteConnection(RemoteConnection):
2122

2223
def __init__(self, remote_server_addr, keep_alive=True):
2324
RemoteConnection.__init__(self, remote_server_addr, keep_alive)
24-
self._commands["launchApp"] = ('POST',
25-
'/session/$sessionId/chromium/launch_app')
25+
self._commands["launchApp"] = ('POST', '/session/$sessionId/chromium/launch_app')

py/selenium/webdriver/chrome/service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
1718
from selenium.webdriver.common import service
1819

20+
1921
class Service(service.Service):
2022
"""
2123
Object that manages the starting and stopping of the ChromeDriver
@@ -34,7 +36,7 @@ def __init__(self, executable_path, port=0, service_args=None,
3436

3537
self.service_args = service_args or []
3638
if log_path:
37-
self.service_args.append('--log-path=%s' % log_path)
39+
self.service_args.append('--log-path=%s' % log_path)
3840

3941
service.Service.__init__(self, executable_path, port=port, env=env,
4042
start_error_message="Please see https://sites.google.com/a/chromium.org/chromedriver/home")

py/selenium/webdriver/chrome/webdriver.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
import base64
19-
from selenium.webdriver.remote.command import Command
2018
from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver
21-
from selenium.common.exceptions import WebDriverException
2219
from .remote_connection import ChromeRemoteConnection
2320
from .service import Service
2421
from .options import Options
2522

23+
2624
class WebDriver(RemoteWebDriver):
2725
"""
2826
Controls the ChromeDriver and allows you to drive the browser.
@@ -56,12 +54,16 @@ def __init__(self, executable_path="chromedriver", port=0,
5654
else:
5755
desired_capabilities.update(chrome_options.to_capabilities())
5856

59-
self.service = Service(executable_path, port=port,
60-
service_args=service_args, log_path=service_log_path)
57+
self.service = Service(
58+
executable_path,
59+
port=port,
60+
service_args=service_args,
61+
log_path=service_log_path)
6162
self.service.start()
6263

6364
try:
64-
RemoteWebDriver.__init__(self,
65+
RemoteWebDriver.__init__(
66+
self,
6567
command_executor=ChromeRemoteConnection(
6668
remote_server_addr=self.service.service_url),
6769
desired_capabilities=desired_capabilities)

0 commit comments

Comments
 (0)