Skip to content

Commit e720521

Browse files
committed
Refactor the code
1 parent 0f74cb5 commit e720521

File tree

10 files changed

+13
-87
lines changed

10 files changed

+13
-87
lines changed

seleniumbase/behave/behave_sb.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,15 +1280,9 @@ def _perform_behave_unconfigure_():
12801280
)
12811281
find_it_3 = '<td class="col-result">Untested</td>'
12821282
swap_with_3 = '<td class="col-result">Unreported</td>'
1283-
if sys.version_info[0] >= 3:
1284-
# These use caching to prevent extra method calls
1285-
DASH_PIE_PNG_1 = constants.Dashboard.get_dash_pie_1()
1286-
DASH_PIE_PNG_2 = constants.Dashboard.get_dash_pie_2()
1287-
else:
1288-
from seleniumbase.core import encoded_images
1289-
1290-
DASH_PIE_PNG_1 = encoded_images.get_dash_pie_png1()
1291-
DASH_PIE_PNG_2 = encoded_images.get_dash_pie_png2()
1283+
# These use caching to prevent extra method calls
1284+
DASH_PIE_PNG_1 = constants.Dashboard.get_dash_pie_1()
1285+
DASH_PIE_PNG_2 = constants.Dashboard.get_dash_pie_2()
12921286
find_it_4 = 'href="%s"' % DASH_PIE_PNG_1
12931287
swap_with_4 = 'href="%s"' % DASH_PIE_PNG_2
12941288
try:

seleniumbase/console_scripts/run.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,6 @@ def main():
10011001
retry_msg_2 = "** Unable to download driver! Retrying in 5s..."
10021002
if " --proxy=" in " ".join(sys.argv):
10031003
from seleniumbase.core import proxy_helper
1004-
10051004
for arg in sys.argv:
10061005
if arg.startswith("--proxy="):
10071006
proxy_string = arg.split("--proxy=")[1]
@@ -1036,26 +1035,22 @@ def main():
10361035
show_install_usage()
10371036
elif command == "commander" or command == "gui":
10381037
from seleniumbase.console_scripts import sb_commander
1039-
10401038
sb_commander.main()
10411039
elif command == "behave-gui" or command == "gui-behave":
10421040
from seleniumbase.console_scripts import sb_behave_gui
1043-
10441041
sb_behave_gui.main()
10451042
elif (
10461043
command == "caseplans"
10471044
or command == "case-plans"
10481045
or command == "case_plans"
10491046
):
10501047
from seleniumbase.console_scripts import sb_caseplans
1051-
10521048
sb_caseplans.main()
10531049
elif (
10541050
command == "recorder"
10551051
or (command == "record" and len(command_args) == 0)
10561052
):
10571053
from seleniumbase.console_scripts import sb_recorder
1058-
10591054
sb_recorder.main()
10601055
elif (
10611056
command == "mkrec"
@@ -1064,7 +1059,6 @@ def main():
10641059
):
10651060
if len(command_args) >= 1:
10661061
from seleniumbase.console_scripts import sb_mkrec
1067-
10681062
sb_mkrec.main()
10691063
else:
10701064
show_basic_usage()
@@ -1075,70 +1069,55 @@ def main():
10751069
elif command == "mkdir":
10761070
if len(command_args) >= 1:
10771071
from seleniumbase.console_scripts import sb_mkdir
1078-
10791072
sb_mkdir.main()
10801073
else:
10811074
show_basic_usage()
10821075
show_mkdir_usage()
10831076
elif command == "mkfile":
10841077
if len(command_args) >= 1:
10851078
from seleniumbase.console_scripts import sb_mkfile
1086-
10871079
sb_mkfile.main()
10881080
else:
10891081
show_basic_usage()
10901082
show_mkfile_usage()
10911083
elif command == "mkpres":
10921084
if len(command_args) >= 1:
10931085
from seleniumbase.console_scripts import sb_mkpres
1094-
10951086
sb_mkpres.main()
10961087
else:
10971088
show_basic_usage()
10981089
show_mkpres_usage()
10991090
elif command == "mkchart":
11001091
if len(command_args) >= 1:
11011092
from seleniumbase.console_scripts import sb_mkchart
1102-
11031093
sb_mkchart.main()
11041094
else:
11051095
show_basic_usage()
11061096
show_mkchart_usage()
11071097
elif command == "convert":
11081098
if len(command_args) == 1:
11091099
from seleniumbase.utilities.selenium_ide import convert_ide
1110-
11111100
convert_ide.main()
11121101
else:
11131102
show_basic_usage()
11141103
show_convert_usage()
11151104
elif command == "print":
11161105
if len(command_args) >= 1:
11171106
from seleniumbase.console_scripts import sb_print
1118-
11191107
sb_print.main()
11201108
else:
11211109
show_basic_usage()
11221110
show_print_usage()
11231111
elif command == "translate":
11241112
if len(command_args) >= 1:
1125-
if sys.version_info[0] == 2:
1126-
c5 = colorama.Fore.RED + colorama.Back.LIGHTYELLOW_EX
1127-
cr = colorama.Style.RESET_ALL
1128-
msg = "The SeleniumBase Translator does NOT support Python 2!"
1129-
message = "\n" + c5 + msg + cr + "\n"
1130-
print("")
1131-
raise Exception(message)
11321113
from seleniumbase.translate import translator
1133-
11341114
translator.main()
11351115
else:
11361116
show_basic_usage()
11371117
show_translate_usage()
11381118
elif command == "extract-objects" or command == "extract_objects":
11391119
if len(command_args) >= 1:
11401120
from seleniumbase.console_scripts import sb_objectify
1141-
11421121
sb_objectify.extract_objects()
11431122
else:
11441123
show_basic_usage()
@@ -1154,31 +1133,27 @@ def main():
11541133
elif command == "objectify":
11551134
if len(command_args) >= 1:
11561135
from seleniumbase.console_scripts import sb_objectify
1157-
11581136
sb_objectify.objectify()
11591137
else:
11601138
show_basic_usage()
11611139
show_objectify_usage()
11621140
elif command == "revert-objects" or command == "revert_objects":
11631141
if len(command_args) >= 1:
11641142
from seleniumbase.console_scripts import sb_objectify
1165-
11661143
sb_objectify.revert_objects()
11671144
else:
11681145
show_basic_usage()
11691146
show_revert_objects_usage()
11701147
elif command == "encrypt" or command == "obfuscate":
11711148
if len(command_args) >= 0:
11721149
from seleniumbase.common import obfuscate
1173-
11741150
obfuscate.main()
11751151
else:
11761152
show_basic_usage()
11771153
show_encrypt_usage()
11781154
elif command == "decrypt" or command == "unobfuscate":
11791155
if len(command_args) >= 0:
11801156
from seleniumbase.common import unobfuscate
1181-
11821157
unobfuscate.main()
11831158
else:
11841159
show_basic_usage()
@@ -1188,31 +1163,27 @@ def main():
11881163
from seleniumbase.utilities.selenium_grid import (
11891164
download_selenium_server,
11901165
)
1191-
11921166
download_selenium_server.main(force_download=True)
11931167
else:
11941168
show_basic_usage()
11951169
show_download_usage()
11961170
elif command == "grid-hub" or command == "grid_hub":
11971171
if len(command_args) >= 1:
11981172
from seleniumbase.utilities.selenium_grid import grid_hub
1199-
12001173
grid_hub.main()
12011174
else:
12021175
show_basic_usage()
12031176
show_grid_hub_usage()
12041177
elif command == "grid-node" or command == "grid_node":
12051178
if len(command_args) >= 1:
12061179
from seleniumbase.utilities.selenium_grid import grid_node
1207-
12081180
grid_node.main()
12091181
else:
12101182
show_basic_usage()
12111183
show_grid_node_usage()
12121184
elif command == "version" or command == "--version" or command == "-v":
12131185
if len(command_args) == 0:
12141186
from seleniumbase.console_scripts import logo_helper
1215-
12161187
seleniumbase_logo = logo_helper.get_seleniumbase_logo()
12171188
print(seleniumbase_logo)
12181189
print("")
@@ -1231,7 +1202,6 @@ def main():
12311202
import fasteners
12321203
import os
12331204
import warnings
1234-
12351205
with warnings.catch_warnings():
12361206
warnings.simplefilter("ignore", category=UserWarning)
12371207
pip_find_lock = fasteners.InterProcessLock(

seleniumbase/console_scripts/sb_behave_gui.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@
2020
from seleniumbase.fixtures import shared_utils
2121
from tkinter.scrolledtext import ScrolledText
2222

23-
if sys.version_info <= (3, 8):
24-
current_version = ".".join(str(ver) for ver in sys.version_info[:3])
25-
raise Exception(
26-
"\n* SBase Commander requires Python 3.8 or newer!"
27-
"\n** You are currently using Python %s" % current_version
28-
)
29-
3023

3124
def set_colors(use_colors):
3225
c0 = ""

seleniumbase/console_scripts/sb_caseplans.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@
2525
from tkinter import messagebox
2626
from tkinter.scrolledtext import ScrolledText
2727

28-
if sys.version_info <= (3, 8):
29-
current_version = ".".join(str(ver) for ver in sys.version_info[:3])
30-
raise Exception(
31-
"\n* SBase Case Plans Generator requires Python 3.8 or newer!"
32-
"\n** You are currently using Python %s" % current_version
33-
)
34-
3528

3629
def set_colors(use_colors):
3730
c0 = ""

seleniumbase/console_scripts/sb_commander.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@
2525
from seleniumbase.fixtures import shared_utils
2626
from tkinter.scrolledtext import ScrolledText
2727

28-
if sys.version_info <= (3, 8):
29-
current_version = ".".join(str(ver) for ver in sys.version_info[:3])
30-
raise Exception(
31-
"\n* SBase Commander requires Python 3.8 or newer!"
32-
"\n** You are currently using Python %s" % current_version
33-
)
34-
3528

3629
def set_colors(use_colors):
3730
c0 = ""

seleniumbase/console_scripts/sb_recorder.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@
3030
sys_executable = sys.executable
3131
if " " in sys_executable:
3232
sys_executable = "python"
33-
if sys.version_info <= (3, 8):
34-
current_version = ".".join(str(ver) for ver in sys.version_info[:3])
35-
raise Exception(
36-
"\n* Recorder Desktop requires Python 3.8 or newer!"
37-
"\n*** You are currently using Python %s" % current_version
38-
)
3933

4034

4135
def set_colors(use_colors):

seleniumbase/core/mysql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ def __init__(self, database_env="test", conf_creds=None):
1919
constants.PipInstall.FINDLOCK
2020
)
2121
with pip_find_lock:
22-
if sys.version_info >= (3, 7) and sys.version_info < (3, 9):
23-
# Fix bug in newer cryptography for Python 3.7 and 3.8:
22+
if sys.version_info < (3, 9):
23+
# Fix bug with newer cryptography on Python 3.8:
2424
# "pyo3_runtime.PanicException: Python API call failed"
2525
# (Match the version needed for pdfminer.six functions)
2626
try:

seleniumbase/core/style_sheet.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import textwrap
32
from seleniumbase.fixtures import constants
43

@@ -11,18 +10,12 @@ class Saved:
1110
def get_report_style():
1211
if hasattr(Saved, "report_style"):
1312
return Saved.report_style
14-
if sys.version_info[0] >= 3:
15-
# Uses caching to prevent extra method calls
16-
REPORT_FAVICON = constants.Report.get_favicon()
17-
else:
18-
from seleniumbase.core import encoded_images
19-
20-
REPORT_FAVICON = encoded_images.get_report_favicon()
13+
# Uses caching to prevent extra method calls
14+
REPORT_FAVICON = constants.Report.get_favicon()
2115
title = """<meta id="OGTitle" property="og:title" content="SeleniumBase">
2216
<title>Test Report</title>
2317
<link rel="SHORTCUT ICON"
2418
href="%s" />""" % REPORT_FAVICON
25-
2619
style = (
2720
title
2821
+ """<style type="text/css">

seleniumbase/core/visual_helper.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import sys
32
from seleniumbase.core import log_helper
43
from seleniumbase.fixtures import constants
54

@@ -22,13 +21,8 @@ def visual_baseline_folder_setup():
2221

2322

2423
def get_sbs_head():
25-
if sys.version_info[0] >= 3:
26-
# Uses caching to prevent extra method calls
27-
SIDE_BY_SIDE_PNG = constants.SideBySide.get_favicon()
28-
else:
29-
from seleniumbase.core import encoded_images
30-
31-
SIDE_BY_SIDE_PNG = encoded_images.get_side_by_side_png()
24+
# Uses caching to prevent extra method calls
25+
SIDE_BY_SIDE_PNG = constants.SideBySide.get_favicon()
3226
head = (
3327
'<head><meta charset="utf-8">'
3428
'<meta name="viewport" content="shrink-to-fit=no">'

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
confirm_text = ">>> Confirm release PUBLISH to PyPI? (yes/no): "
3131
reply = str(input_method(confirm_text)).lower().strip()
3232
if reply == "yes":
33-
if sys.version_info < (3, 9):
34-
print("\nERROR! Publishing to PyPI requires Python>=3.9")
33+
if sys.version_info < (3, 10):
34+
current_ver = ".".join(str(ver) for ver in sys.version_info[:3])
35+
print("\nERROR! Publishing to PyPI requires Python>=3.10")
36+
print("You are currently using Python %s\n" % current_ver)
3537
sys.exit()
3638
print("\n*** Checking code health with flake8:\n")
3739
os.system("python -m pip install 'flake8==7.2.0'")

0 commit comments

Comments
 (0)