Skip to content

Commit ab03b2b

Browse files
authored
Merge pull request #899 from seleniumbase/perform-code-optimization
Perform code optimization
2 parents 180902f + 3012ce0 commit ab03b2b

Some content is hidden

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

64 files changed

+4286
-2583
lines changed

docs/prepare.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def process_file(file_name):
5050
content = content.replace("(" + md_path + ")", normalize_path(path))
5151

5252
for url in urls:
53-
path = url[len(GITHUB_URL):]
53+
path = url[len(GITHUB_URL) :] # noqa: E203
5454
paths.add(path)
5555
content = content.replace(
5656
url, normalize_path(os.path.relpath(path, directory))
@@ -83,9 +83,9 @@ def main(*args, **kwargs):
8383
process_file(file_)
8484

8585
readme_file = "./docs/README.md"
86-
with open(readme_file, 'r', encoding='utf-8') as f:
86+
with open(readme_file, "r", encoding="utf-8") as f:
8787
all_code = f.read()
88-
code_lines = all_code.split('\n')
88+
code_lines = all_code.split("\n")
8989

9090
changed = False
9191
seleniumbase_lines = []
@@ -99,24 +99,27 @@ def main(*args, **kwargs):
9999
r'<p align="center"><div align="center">'
100100
r'<a href="https://github.com/seleniumbase/SeleniumBase">'
101101
r'<img src="https://img.shields.io/badge/'
102-
r'✅%20💛%20View%20Code-on%20GitHub%20🌎%20🚀'
102+
r"✅%20💛%20View%20Code-on%20GitHub%20🌎%20🚀"
103103
r'-02A79E.svg" alt="SeleniumBase on GitHub" />'
104-
r'</a></div></p>')
104+
r"</a></div></p>"
105+
)
105106
if "<!-- SeleniumBase Header1 -->" in line:
106107
changed = True
107108
line = (
108109
'<section align="center"><div align="center">'
109-
'<h2>✅ Reliable Browser Testing</h2>'
110-
'</div></section>')
110+
"<h2>✅ Reliable Browser Testing</h2>"
111+
"</div></section>"
112+
)
111113
if "<!-- SeleniumBase Docs -->" in line:
112114
changed = True
113115
line = (
114116
'<h2><img src="https://seleniumbase.io/img/sb_icon.png" '
115117
'title="SeleniumBase" width="20" /> SeleniumBase Docs '
116118
'<img src="https://seleniumbase.io/img/sb_icon.png" '
117-
'title="SeleniumBase" width="20" /></h2>')
119+
'title="SeleniumBase" width="20" /></h2>'
120+
)
118121
seleniumbase_lines.append(line)
119122
if changed:
120-
out_file = codecs.open(readme_file, "w+", encoding='utf-8')
123+
out_file = codecs.open(readme_file, "w+", encoding="utf-8")
121124
out_file.writelines("\r\n".join(seleniumbase_lines))
122125
out_file.close()

docs/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Markdown==3.3.4
66
docutils==0.17.1
77
Jinja2==2.11.3
88
readme-renderer==29.0
9-
pymdown-extensions==8.1.1
9+
pymdown-extensions==8.2
1010
importlib-metadata==4.0.1;python_version>="3.6"
1111
lunr==0.5.8
1212
nltk==3.6.2
1313
mkdocs==1.1.2
14-
mkdocs-material==7.1.3
14+
mkdocs-material==7.1.4
1515
mkdocs-exclude-search==0.5.2;python_version>="3.6"
1616
mkdocs-simple-hooks==0.1.3
1717
mkdocs-material-extensions==1.0.1

help_docs/method_summary.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ self.get_path_of_downloaded_file(file, browser=False)
323323
self.is_downloaded_file_present(file, browser=False)
324324

325325
self.delete_downloaded_file_if_present(file, browser=False)
326+
# Duplicates: self.delete_downloaded_file(file, browser=False)
326327

327328
self.assert_downloaded_file(file, timeout=None, browser=False)
328329

integrations/brython/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33

44
def setup_page():
5-
document['topHeader'].textContent = "Brython Examples:"
5+
document["topHeader"].textContent = "Brython Examples:"

integrations/node_js/my_first_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class MyTestClass(BaseCase):
5-
65
def test_basics(self):
76
url = "https://store.xkcd.com/collections/posters"
87
self.open(url)

integrations/node_js/test_demo_site.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class MyTestClass(BaseCase):
5-
65
def test_demo_site(self):
76
self.open("https://seleniumbase.io/demo_page")
87

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ setuptools>=56.1.0;python_version>="3.6"
88
setuptools-scm==5.0.2;python_version<"3.6"
99
setuptools-scm>=6.0.1;python_version>="3.6"
1010
wheel>=0.36.2
11-
attrs>=20.3.0
11+
attrs>=21.2.0
1212
PyYAML>=5.4.1;python_version>="3.6"
1313
certifi>=2020.12.5
1414
six==1.16.0

seleniumbase/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from seleniumbase.common import decorators # noqa
55
from seleniumbase.common import encryption # noqa
66
import sys
7+
78
if sys.version_info[0] >= 3:
89
from seleniumbase import translate # noqa
910
del sys # Undo "import sys" / Simplify "dir(seleniumbase)"

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "1.63.2"
2+
__version__ = "1.63.3"

seleniumbase/common/decorators.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99

1010

1111
def retry_on_exception(tries=6, delay=1, backoff=2, max_delay=32):
12-
'''
12+
"""
1313
Decorator for implementing exponential backoff for retrying on failures.
1414
1515
tries: Max number of tries to execute the wrapped function before failing.
1616
delay: Delay time in seconds before the FIRST retry.
1717
backoff: Multiplier to extend the initial delay by for each retry.
1818
max_delay: Max time in seconds to wait between retries.
19-
'''
19+
"""
2020
tries = math.floor(tries)
2121
if tries < 1:
2222
raise ValueError('"tries" must be greater than or equal to 1.')
@@ -37,21 +37,24 @@ def function_to_retry(*args, **kwargs):
3737
except Exception as e:
3838
if local_delay > max_delay:
3939
local_delay = max_delay
40-
logging.exception('%s: Retrying in %d seconds...'
41-
% (str(e), local_delay))
40+
logging.exception(
41+
"%s: Retrying in %d seconds..." % (str(e), local_delay)
42+
)
4243
time.sleep(local_delay)
4344
local_tries -= 1
4445
local_delay *= backoff
4546
return func(*args, **kwargs)
47+
4648
return function_to_retry
49+
4750
return decorated_function_with_retry
4851

4952

5053
def rate_limited(max_per_second):
51-
""" This decorator limits how often a method can get called in a second.
52-
If the limit is exceeded, the call will be held in a queue until
53-
enough time has passed.
54-
Useful when trying to avoid overloading a system with rapid calls. """
54+
"""This decorator limits how often a method can get called in a second.
55+
If the limit is exceeded, the call will be held in a queue until
56+
enough time has passed.
57+
Useful when trying to avoid overloading a system with rapid calls."""
5558
min_interval = 1.0 / float(max_per_second)
5659

5760
def decorate(func):
@@ -76,33 +79,37 @@ def rate_limited_function(*args, **kargs):
7679
finally:
7780
rate_lock.release()
7881
return func(*args, **kargs)
82+
7983
return rate_limited_function
84+
8085
return decorate
8186

8287

8388
def deprecated(message=None):
84-
""" This decorator marks methods as deprecated.
85-
A warning is displayed if the method is called. """
89+
"""This decorator marks methods as deprecated.
90+
A warning is displayed if the method is called."""
8691

8792
def decorated_method_to_deprecate(func):
8893
if inspect.isclass(func):
8994
# Handle a deprecated class differently from a deprecated method
9095
msg = "Class {}() is DEPRECATED! *** ".format(func.__name__)
9196
if message:
9297
msg += "<> %s <>" % message
93-
warnings.simplefilter('always', DeprecationWarning) # See Warnings
98+
warnings.simplefilter("always", DeprecationWarning) # See Warnings
9499
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
95-
warnings.simplefilter('default', DeprecationWarning) # Set Default
100+
warnings.simplefilter("default", DeprecationWarning) # Set Default
96101
return func
97102

98103
@wraps(func)
99104
def new_func(*args, **kwargs):
100105
msg = "Method {}() is DEPRECATED! *** ".format(func.__name__)
101106
if message:
102107
msg += "<> %s <>" % message
103-
warnings.simplefilter('always', DeprecationWarning) # See Warnings
108+
warnings.simplefilter("always", DeprecationWarning) # See Warnings
104109
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
105-
warnings.simplefilter('default', DeprecationWarning) # Set Default
110+
warnings.simplefilter("default", DeprecationWarning) # Set Default
106111
return func(*args, **kwargs)
112+
107113
return new_func
114+
108115
return decorated_method_to_deprecate

0 commit comments

Comments
 (0)