Skip to content

Commit 8ae272c

Browse files
committed
Update message output from the SeleniumBase translator
1 parent 8421cbf commit 8ae272c

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

seleniumbase/translate/translator.py

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def get_width(line):
103103
def process_test_file(code_lines, new_lang):
104104
detected_lang = None
105105
changed = False
106+
found_bc = False # Found BaseCase or a translation
106107
seleniumbase_lines = []
107108
lang_codes = MD_L_Codes.lang
108109
nl_code = lang_codes[new_lang] # new_lang language code
@@ -127,6 +128,7 @@ def process_test_file(code_lines, new_lang):
127128
changed = True
128129
new_line = MD_F.get_import_line(new_lang) + comments
129130
else:
131+
found_bc = True
130132
new_line = line
131133
if new_line.endswith(" # noqa"): # Remove flake8 skip
132134
new_line = new_line[0:-len(" # noqa")]
@@ -144,6 +146,7 @@ def process_test_file(code_lines, new_lang):
144146
changed = True
145147
new_line = MD_F.get_mqa_im_line(new_lang) + comments
146148
else:
149+
found_bc = True
147150
new_line = line
148151
if new_line.endswith(" # noqa"): # Remove flake8 skip
149152
new_line = new_line[0:-len(" # noqa")]
@@ -176,6 +179,7 @@ def process_test_file(code_lines, new_lang):
176179
'%sclass %s(%s):%s'
177180
'' % (whitespace, name, new_parent, comments))
178181
else:
182+
found_bc = True
179183
new_line = line
180184
if new_line.endswith(" # noqa"): # Remove flake8 skip
181185
new_line = new_line[0:-len(" # noqa")]
@@ -192,6 +196,7 @@ def process_test_file(code_lines, new_lang):
192196
'%sclass %s(%s):%s'
193197
'' % (whitespace, name, new_parent, comments))
194198
else:
199+
found_bc = True
195200
new_line = line
196201
if new_line.endswith(" # noqa"): # Remove flake8 skip
197202
new_line = new_line[0:-len(" # noqa")]
@@ -231,7 +236,7 @@ def process_test_file(code_lines, new_lang):
231236

232237
seleniumbase_lines.append(line)
233238

234-
return seleniumbase_lines, changed, detected_lang
239+
return seleniumbase_lines, changed, detected_lang, found_bc
235240

236241

237242
def main():
@@ -447,17 +452,47 @@ def main():
447452
all_code = all_code.replace("\t", " ")
448453
code_lines = all_code.split('\n')
449454

450-
seleniumbase_lines, changed, d_l = process_test_file(code_lines, new_lang)
455+
sb_lines, changed, d_l, found_bc = process_test_file(code_lines, new_lang)
456+
seleniumbase_lines = sb_lines
451457
detected_lang = d_l
458+
found_basecase = found_bc
452459

453-
if not changed:
454-
msg = ('\n*> [%s] was already in %s! * No changes were made! <*\n'
455-
'' % (seleniumbase_file, new_lang))
456-
msg = msg.replace("*> ", "*> " + c2).replace(" <*", cr + " <*")
457-
print(msg)
460+
if not changed and found_basecase:
461+
print("")
462+
msg1 = (" [[[[%s]]]] was already in [[[%s]]]!\n\n"
463+
"" % (seleniumbase_file, new_lang))
464+
msg1 = msg1.replace("[[[[", "" + c3).replace("]]]]", cr + "")
465+
msg1 = msg1.replace("[[[", "" + c5).replace("]]]", cr + "")
466+
msg2 = None
467+
if print_only:
468+
msg2 = '*> *** No changes to display! *** <*'
469+
elif overwrite:
470+
msg2 = '*> *** No changes were made! *** <*'
471+
else: # "copy" action
472+
msg2 = '*> *** No action was taken! *** <*'
473+
msg2 = msg2.replace("*>", " " + c6).replace("<*", cr + '\n')
474+
print(msg1 + msg2)
475+
return
476+
477+
if not changed and not found_basecase:
478+
print("")
479+
filename = c3 + seleniumbase_file + cr
480+
from_sb = c5 + "from seleniumbase" + cr
481+
msg0 = (' * In order to translate the script,\n')
482+
msg1 = (' %s requires "%s..."\n' % (filename, from_sb))
483+
msg2 = (" and a BaseCase import in a supported language!\n\n")
484+
msg3 = None
485+
if print_only:
486+
msg3 = '*> *** No changes to display! *** <*'
487+
elif overwrite:
488+
msg3 = '*> *** No changes were made! *** <*'
489+
else: # "copy" action
490+
msg3 = '*> *** No action was taken! *** <*'
491+
msg3 = msg3.replace("*>", " " + c6).replace("<*", cr + '\n')
492+
print(msg0 + msg1 + msg2 + msg3)
458493
return
459494

460-
save_line = ("[[[[%s]]]] was translated to [[[%s]]]! "
495+
save_line = (" [[[[%s]]]] was translated to [[[%s]]]! "
461496
"(Previous: %s)\n"
462497
"" % (seleniumbase_file, new_lang, detected_lang))
463498
save_line = save_line.replace("[[[[", "" + c4)
@@ -684,7 +719,7 @@ def main():
684719
magic_console = Console()
685720
print("")
686721
print(save_line)
687-
print(c1 + "* Here are the results: >>>" + cr)
722+
print(" " + c1 + " *** Here are the results: >>> " + cr)
688723
# ----------------------------------------
689724
dash_length = 62 # May change
690725
if used_width and used_width + w < console_width:

0 commit comments

Comments
 (0)