Skip to content

Commit 72ca3c9

Browse files
committed
Use keyword arguments with the open() method
1 parent 6da4191 commit 72ca3c9

File tree

24 files changed

+101
-89
lines changed

24 files changed

+101
-89
lines changed

mkdocs_build/prepare.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def main(*args, **kwargs):
117117

118118
for file_ in updated_files_to_process:
119119
readme_file = "./mkdocs_build/" + file_
120-
with open(readme_file, "r", encoding="utf-8") as f:
120+
with open(readme_file, mode="r", encoding="utf-8") as f:
121121
all_code = f.read()
122122
code_lines = all_code.split("\n")
123123

@@ -195,6 +195,6 @@ def main(*args, **kwargs):
195195
)
196196
seleniumbase_lines.append(line)
197197
if changed:
198-
out_file = open(readme_file, "w+", encoding="utf-8")
198+
out_file = open(readme_file, mode="w+", encoding="utf-8")
199199
out_file.writelines("\r\n".join(seleniumbase_lines))
200200
out_file.close()

seleniumbase/behave/behave_sb.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,24 +1216,24 @@ def _create_dashboard_assets_():
12161216
add_pytest_style_css = True
12171217
if os.path.exists(pytest_style_css):
12181218
existing_pytest_style = None
1219-
with open(pytest_style_css, "r") as f:
1219+
with open(pytest_style_css, mode="r") as f:
12201220
existing_pytest_style = f.read()
12211221
if existing_pytest_style == get_pytest_style():
12221222
add_pytest_style_css = False
12231223
if add_pytest_style_css:
1224-
out_file = open(pytest_style_css, "w+", encoding="utf-8")
1224+
out_file = open(pytest_style_css, mode="w+", encoding="utf-8")
12251225
out_file.writelines(get_pytest_style())
12261226
out_file.close()
12271227
live_js_file = os.path.join(assets_folder, "live.js")
12281228
add_live_js_file = True
12291229
if os.path.exists(live_js_file):
12301230
existing_live_js = None
1231-
with open(live_js_file, "r") as f:
1231+
with open(live_js_file, mode="r") as f:
12321232
existing_live_js = f.read()
12331233
if existing_live_js == live_js:
12341234
add_live_js_file = False
12351235
if add_live_js_file:
1236-
out_file = open(live_js_file, "w+", encoding="utf-8")
1236+
out_file = open(live_js_file, mode="w+", encoding="utf-8")
12371237
out_file.writelines(live_js)
12381238
out_file.close()
12391239

@@ -1306,7 +1306,7 @@ def _perform_behave_unconfigure_():
13061306
# Part 1: Finalizing the dashboard / integrating html report
13071307
if os.path.exists(dashboard_path):
13081308
the_html_d = None
1309-
with open(dashboard_path, "r", encoding="utf-8") as f:
1309+
with open(dashboard_path, mode="r", encoding="utf-8") as f:
13101310
the_html_d = f.read()
13111311
if sb_config._multithreaded and "-c" in sys.argv:
13121312
# Threads have "-c" in sys.argv, except for the last
@@ -1317,7 +1317,7 @@ def _perform_behave_unconfigure_():
13171317
if os.path.exists(pie_path):
13181318
import json
13191319

1320-
with open(pie_path, "r") as f:
1320+
with open(pie_path, mode="r") as f:
13211321
dash_pie = f.read().strip()
13221322
sb_config._saved_dashboard_pie = json.loads(dash_pie)
13231323
# If the test run doesn't complete by itself, stop refresh
@@ -1326,7 +1326,7 @@ def _perform_behave_unconfigure_():
13261326
the_html_d = the_html_d.replace(find_it_3, swap_with_3)
13271327
the_html_d = the_html_d.replace(find_it_4, swap_with_4)
13281328
the_html_d += stamp
1329-
with open(dashboard_path, "w", encoding="utf-8") as f:
1329+
with open(dashboard_path, mode="w", encoding="utf-8") as f:
13301330
f.write(the_html_d) # Finalize the dashboard
13311331
except KeyboardInterrupt:
13321332
pass

seleniumbase/console_scripts/sb_caseplans.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def generate_case_plan_boilerplates(
134134
file_name = case_id
135135
file_path = os.path.join(full_folder_path, file_name)
136136
if not os.path.exists(file_path):
137-
out_file = open(file_path, "w+", "utf-8")
137+
out_file = open(file_path, mode="w+", encoding="utf-8")
138138
out_file.writelines("\r\n".join(data))
139139
out_file.close()
140140
new_plans += 1
@@ -182,7 +182,7 @@ def view_summary_of_existing_case_plans(root, tests):
182182
else:
183183
case_path = os.path.join(folder_path, "case_plans", case_id)
184184
if os.path.exists(case_path):
185-
f = open(case_path, "r")
185+
f = open(case_path, mode="r")
186186
case_data = f.read()
187187
f.close()
188188
case_data_storage.append(case_data)
@@ -315,7 +315,7 @@ def view_summary_of_existing_case_plans(root, tests):
315315
full_plan = plan_head
316316

317317
file_path = "case_summary.md"
318-
file = open(file_path, "w+", "utf-8")
318+
file = open(file_path, mode="w+", encoding="utf-8")
319319
file.writelines("\r\n".join(full_plan))
320320
file.close()
321321

seleniumbase/console_scripts/sb_mkchart.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def main():
253253
continue
254254
new_data.append(line)
255255
data = new_data
256-
file = open(file_path, "w+", "utf-8")
256+
file = open(file_path, mode="w+", encoding="utf-8")
257257
file.writelines("\r\n".join(data))
258258
file.close()
259259
if " " not in file_name:

seleniumbase/console_scripts/sb_mkdir.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def main():
113113
data.append(seleniumbase_req)
114114
data.append("")
115115
file_path = "%s/%s" % (dir_name, "requirements.txt")
116-
file = open(file_path, "w+", "utf-8")
116+
file = open(file_path, mode="w+", encoding="utf-8")
117117
file.writelines("\r\n".join(data))
118118
file.close()
119119

@@ -151,7 +151,7 @@ def main():
151151
data.append(" production: custom marker")
152152
data.append("")
153153
file_path = "%s/%s" % (dir_name, "pytest.ini")
154-
file = open(file_path, "w+", "utf-8")
154+
file = open(file_path, mode="w+", encoding="utf-8")
155155
file.writelines("\r\n".join(data))
156156
file.close()
157157

@@ -168,14 +168,14 @@ def main():
168168
data.append("show_skipped=false")
169169
data.append("show_timings=false")
170170
file_path = "%s/%s" % (dir_name, "setup.cfg")
171-
file = open(file_path, "w+", "utf-8")
171+
file = open(file_path, mode="w+", encoding="utf-8")
172172
file.writelines("\r\n".join(data))
173173
file.close()
174174

175175
data = []
176176
data.append("")
177177
file_path = "%s/%s" % (dir_name, "__init__.py")
178-
file = open(file_path, "w+", "utf-8")
178+
file = open(file_path, mode="w+", encoding="utf-8")
179179
file.writelines("\r\n".join(data))
180180
file.close()
181181

@@ -311,7 +311,7 @@ def main():
311311
data.append("temp_*/")
312312
data.append("node_modules")
313313
file_path = "%s/%s" % (dir_name, ".gitignore")
314-
file = open(file_path, "w+", "utf-8")
314+
file = open(file_path, mode="w+", encoding="utf-8")
315315
file.writelines("\r\n".join(data))
316316
file.close()
317317

@@ -323,7 +323,7 @@ def main():
323323
data.append(" ├── requirements.txt")
324324
data.append(" └── setup.cfg")
325325
file_path = "%s/%s" % (dir_name, "outline.rst")
326-
file = open(file_path, "w+", "utf-8")
326+
file = open(file_path, mode="w+", encoding="utf-8")
327327
file.writelines("\r\n".join(data))
328328
file.close()
329329
os.system("sbase print %s -n" % file_path)
@@ -367,7 +367,7 @@ def main():
367367
data.append(' self.assert_element("div#login_button_container")')
368368
data.append("")
369369
file_path = "%s/%s" % (dir_name, "my_first_test.py")
370-
file = open(file_path, "w+", "utf-8")
370+
file = open(file_path, mode="w+", encoding="utf-8")
371371
file.writelines("\r\n".join(data))
372372
file.close()
373373

@@ -460,7 +460,7 @@ def main():
460460
data.append(' self.assert_text("SeleniumBase", "h2")')
461461
data.append("")
462462
file_path = "%s/%s" % (dir_name, "test_demo_site.py")
463-
file = open(file_path, "w+", "utf-8")
463+
file = open(file_path, mode="w+", encoding="utf-8")
464464
file.writelines("\r\n".join(data))
465465
file.close()
466466

@@ -499,7 +499,7 @@ def main():
499499
data.append(' self.assert_title_contains(title_text)')
500500
data.append("")
501501
file_path = "%s/%s" % (dir_name, "parameterized_test.py")
502-
file = open(file_path, "w+", "utf-8")
502+
file = open(file_path, mode="w+", encoding="utf-8")
503503
file.writelines("\r\n".join(data))
504504
file.close()
505505

@@ -509,7 +509,7 @@ def main():
509509
data = []
510510
data.append("")
511511
file_path = "%s/%s" % (dir_name_2, "__init__.py")
512-
file = open(file_path, "w+", "utf-8")
512+
file = open(file_path, mode="w+", encoding="utf-8")
513513
file.writelines("\r\n".join(data))
514514
file.close()
515515

@@ -544,7 +544,7 @@ def main():
544544
data.append(" pass")
545545
data.append("")
546546
file_path = "%s/%s" % (dir_name_2, "base_test_case.py")
547-
file = open(file_path, "w+", "utf-8")
547+
file = open(file_path, mode="w+", encoding="utf-8")
548548
file.writelines("\r\n".join(data))
549549
file.close()
550550

@@ -553,7 +553,7 @@ def main():
553553
data.append(' html = "html"')
554554
data.append("")
555555
file_path = "%s/%s" % (dir_name_2, "page_objects.py")
556-
file = open(file_path, "w+", "utf-8")
556+
file = open(file_path, mode="w+", encoding="utf-8")
557557
file.writelines("\r\n".join(data))
558558
file.close()
559559

@@ -569,7 +569,7 @@ def main():
569569
data.append(" self.assert_element(Page.html)")
570570
data.append("")
571571
file_path = "%s/%s" % (dir_name_2, "boilerplate_test.py")
572-
file = open(file_path, "w+", "utf-8")
572+
file = open(file_path, mode="w+", encoding="utf-8")
573573
file.writelines("\r\n".join(data))
574574
file.close()
575575

@@ -593,7 +593,7 @@ def main():
593593
data.append(' DataPage().add_input_text(self, "Goodbye!")')
594594
data.append("")
595595
file_path = "%s/%s" % (dir_name_2, "classic_obj_test.py")
596-
file = open(file_path, "w+", "utf-8")
596+
file = open(file_path, mode="w+", encoding="utf-8")
597597
file.writelines("\r\n".join(data))
598598
file.close()
599599

@@ -613,7 +613,7 @@ def main():
613613
data.append(' DataPage().add_input_text(sb, "Goodbye!")')
614614
data.append("")
615615
file_path = "%s/%s" % (dir_name_2, "sb_fixture_test.py")
616-
file = open(file_path, "w+", "utf-8")
616+
file = open(file_path, mode="w+", encoding="utf-8")
617617
file.writelines("\r\n".join(data))
618618
file.close()
619619

@@ -623,7 +623,7 @@ def main():
623623
data = []
624624
data.append("")
625625
file_path = "%s/%s" % (dir_name_3, "__init__.py")
626-
file = open(file_path, "w+", "utf-8")
626+
file = open(file_path, mode="w+", encoding="utf-8")
627627
file.writelines("\r\n".join(data))
628628
file.close()
629629

@@ -651,7 +651,7 @@ def main():
651651
)
652652
data.append("")
653653
file_path = "%s/%s" % (dir_name_3, "google_test.py")
654-
file = open(file_path, "w+", "utf-8")
654+
file = open(file_path, mode="w+", encoding="utf-8")
655655
file.writelines("\r\n".join(data))
656656
file.close()
657657

@@ -669,7 +669,7 @@ def main():
669669
data.append(' search_results = "div#center_col"')
670670
data.append("")
671671
file_path = "%s/%s" % (dir_name_3, "google_objects.py")
672-
file = open(file_path, "w+", "utf-8")
672+
file = open(file_path, mode="w+", encoding="utf-8")
673673
file.writelines("\r\n".join(data))
674674
file.close()
675675

@@ -701,7 +701,7 @@ def main():
701701
data.append(' self.assert_element("div#login_button_container")')
702702
data.append("")
703703
file_path = "%s/%s" % (dir_name_3, "swag_labs_test.py")
704-
file = open(file_path, "w+", "utf-8")
704+
file = open(file_path, mode="w+", encoding="utf-8")
705705
file.writelines("\r\n".join(data))
706706
file.close()
707707

@@ -728,7 +728,7 @@ def main():
728728
data.append(' sb.assert_element("div#login_button_container")')
729729
data.append("")
730730
file_path = "%s/%s" % (dir_name_3, "sb_swag_test.py")
731-
file = open(file_path, "w+", "utf-8")
731+
file = open(file_path, mode="w+", encoding="utf-8")
732732
file.writelines("\r\n".join(data))
733733
file.close()
734734

@@ -755,7 +755,7 @@ def main():
755755
data.append(" ├── sb_swag_test.py")
756756
data.append(" └── swag_labs_test.py")
757757
file_path = "%s/%s" % (dir_name, "outline.rst")
758-
file = open(file_path, "w+", "utf-8")
758+
file = open(file_path, mode="w+", encoding="utf-8")
759759
file.writelines("\r\n".join(data))
760760
file.close()
761761
if " " not in file_path:

seleniumbase/console_scripts/sb_mkfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def main():
412412
continue
413413
new_data.append(line)
414414
data = new_data
415-
file = open(file_path, "w+", "utf-8")
415+
file = open(file_path, mode="w+", encoding="utf-8")
416416
file.writelines("\r\n".join(data))
417417
file.close()
418418
if " " not in file_name:

seleniumbase/console_scripts/sb_mkpres.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def main():
272272
continue
273273
new_data.append(line)
274274
data = new_data
275-
file = open(file_path, "w+", "utf-8")
275+
file = open(file_path, mode="w+", encoding="utf-8")
276276
file.writelines("\r\n".join(data))
277277
file.close()
278278
if " " not in file_name:

seleniumbase/console_scripts/sb_mkrec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def main():
239239
d2.append("")
240240
data = d2
241241

242-
file = open(file_path, "w+", "utf-8")
242+
file = open(file_path, mode="w+", encoding="utf-8")
243243
file.writelines("\r\n".join(data))
244244
file.close()
245245
success = (

seleniumbase/console_scripts/sb_objectify.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def create_objects_file(selector_list_dict=None):
135135
data.append(' html = "html"')
136136
data.append("")
137137
file_path = PAGE_OBJECTS_FILE
138-
file = open(file_path, "w+", "utf-8")
138+
file = open(file_path, mode="w+", encoding="utf-8")
139139
file.writelines("\r\n".join(data))
140140
file.close()
141141
if not selector_list_dict:
@@ -149,7 +149,7 @@ def scan_objects_file():
149149
create_objects_file()
150150

151151
page_selectors = {}
152-
with open(PAGE_OBJECTS_FILE, "r", encoding="utf-8") as f:
152+
with open(PAGE_OBJECTS_FILE, mode="r", encoding="utf-8") as f:
153153
all_code = f.read()
154154

155155
var_names = []
@@ -3089,7 +3089,7 @@ def main(shell_command):
30893089
"Expecting: %s\n" % (seleniumbase_file, expected_arg)
30903090
)
30913091

3092-
with open(seleniumbase_file, "r", encoding="utf-8") as f:
3092+
with open(seleniumbase_file, mode="r", encoding="utf-8") as f:
30933093
all_code = f.read()
30943094
if "def test_" not in all_code:
30953095
raise Exception(
@@ -3188,7 +3188,7 @@ def main(shell_command):
31883188
# Create SeleniumBase test file
31893189
base_file_name = seleniumbase_file.split(".py")[0]
31903190
converted_file_name = base_file_name + ".py" # Change end to make a copy
3191-
out_file = open(converted_file_name, "w+", encoding="utf-8")
3191+
out_file = open(converted_file_name, mode="w+", encoding="utf-8")
31923192
out_file.writelines(seleniumbase_code)
31933193
out_file.close()
31943194
print('\n>>> ["%s"] was updated!\n' % converted_file_name)

seleniumbase/console_scripts/sb_print.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def main():
123123

124124
all_code = None
125125
with open(
126-
file_to_print, "r+", encoding="utf-8", errors="ignore"
126+
file_to_print, mode="r+", encoding="utf-8", errors="ignore"
127127
) as f:
128128
all_code = f.read()
129129
all_code = all_code.replace("\t", " ")

0 commit comments

Comments
 (0)