Skip to content

Commit c0ad654

Browse files
committed
* Update dev version
* Refactor
1 parent e1d98c9 commit c0ad654

17 files changed

Lines changed: 172 additions & 98 deletions

File tree

pybreeze/extend/mail_thunder_extend/mail_thunder_setting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def send_after_test(html_report_path: str = None) -> None:
1111
mail_thunder_smtp: SMTPWrapper = SMTPWrapper()
1212
if html_report_path is None and mail_thunder_smtp.login_state is True:
1313
user: str = mail_thunder_smtp.user
14-
with open("default_name.html", "r+") as file:
14+
with open("default_name.html", "r") as file:
1515
html_string: str = file.read()
1616
message = mail_thunder_smtp.create_message_with_attach(
1717
html_string,
@@ -21,7 +21,7 @@ def send_after_test(html_report_path: str = None) -> None:
2121
mail_thunder_smtp.quit()
2222
elif mail_thunder_smtp.login_state is True:
2323
user: str = mail_thunder_smtp.user
24-
with open(html_report_path, "r+") as file:
24+
with open(html_report_path, "r") as file:
2525
html_string: str = file.read()
2626
message: MIMEMultipart = mail_thunder_smtp.create_message_with_attach(
2727
html_string,

pybreeze/extend/process_executor/api_testka/api_testka_process.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def call_api_testka_multi_file(
3636
if need_to_execute_list is not None \
3737
and isinstance(need_to_execute_list, list) and len(need_to_execute_list) > 0:
3838
for execute_file in need_to_execute_list:
39-
with open(execute_file, "r+") as test_script_json:
39+
with open(execute_file, "r") as test_script_json:
4040
call_api_testka(
4141
main_window,
4242
test_script_json.read(),
@@ -56,7 +56,7 @@ def call_api_testka_multi_file_and_send(
5656
if need_to_execute_list is not None \
5757
and isinstance(need_to_execute_list, list) and len(need_to_execute_list) > 0:
5858
for execute_file in need_to_execute_list:
59-
with open(execute_file, "r+") as test_script_json:
59+
with open(execute_file, "r") as test_script_json:
6060
call_api_testka_with_send(
6161
main_window,
6262
test_script_json.read(),

pybreeze/extend/process_executor/auto_control/auto_control_process.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def call_auto_control_multi_file(
3535
if need_to_execute_list is not None \
3636
and isinstance(need_to_execute_list, list) and len(need_to_execute_list) > 0:
3737
for execute_file in need_to_execute_list:
38-
with open(execute_file, "r+") as test_script_json:
38+
with open(execute_file, "r") as test_script_json:
3939
call_auto_control(
4040
main_window,
4141
test_script_json.read(),
@@ -52,7 +52,7 @@ def call_auto_control_multi_file_and_send(
5252
if need_to_execute_list is not None \
5353
and isinstance(need_to_execute_list, list) and len(need_to_execute_list) > 0:
5454
for execute_file in need_to_execute_list:
55-
with open(execute_file, "r+") as test_script_json:
55+
with open(execute_file, "r") as test_script_json:
5656
call_auto_control_with_send(
5757
main_window,
5858
test_script_json.read(),

pybreeze/extend/process_executor/file_automation/file_automation_process.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def call_file_automation_test_multi_file(
3636
if need_to_execute_list is not None \
3737
and isinstance(need_to_execute_list, list) and len(need_to_execute_list) > 0:
3838
for execute_file in need_to_execute_list:
39-
with open(execute_file, "r+") as test_script_json:
39+
with open(execute_file, "r") as test_script_json:
4040
call_file_automation_test(
4141
main_window,
4242
test_script_json.read(),
@@ -56,7 +56,7 @@ def call_file_automation_test_multi_file_and_send(
5656
if need_to_execute_list is not None \
5757
and isinstance(need_to_execute_list, list) and len(need_to_execute_list) > 0:
5858
for execute_file in need_to_execute_list:
59-
with open(execute_file, "r+") as test_script_json:
59+
with open(execute_file, "r") as test_script_json:
6060
call_file_automation_test_with_send(
6161
main_window,
6262
test_script_json.read(),

pybreeze/extend/process_executor/load_density/load_density_process.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def call_load_density_multi_file(
3636
if need_to_execute_list is not None and isinstance(need_to_execute_list, list) and len(
3737
need_to_execute_list) > 0:
3838
for execute_file in need_to_execute_list:
39-
with open(execute_file, "r+") as test_script_json:
39+
with open(execute_file, "r") as test_script_json:
4040
call_load_density(
4141
main_window,
4242
test_script_json.read(),
@@ -56,7 +56,7 @@ def call_load_density_multi_file_and_send(
5656
if need_to_execute_list is not None and isinstance(need_to_execute_list, list) and len(
5757
need_to_execute_list) > 0:
5858
for execute_file in need_to_execute_list:
59-
with open(execute_file, "r+") as test_script_json:
59+
with open(execute_file, "r") as test_script_json:
6060
call_load_density_with_send(
6161
main_window,
6262
test_script_json.read(),

pybreeze/extend/process_executor/process_executor_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ def start_process(
5656
if send_mail:
5757
process = TaskProcessManager(
5858
main_window=code_window,
59+
task_done_trigger_function=send_after_test,
5960
program_buffer_size=program_buffer,
6061
program_encoding=main_window.encoding
6162
)
6263
else:
6364
process = TaskProcessManager(
6465
code_window,
65-
task_done_trigger_function=send_after_test,
6666
program_buffer_size=program_buffer,
6767
program_encoding=main_window.encoding
6868
)

pybreeze/extend/process_executor/python_task_process_manager.py

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
import queue
32
import subprocess
43
import sys
@@ -57,23 +56,19 @@ def renew_path(self) -> None:
5756
def start_test_process(self, package: str, exec_str: str):
5857
self.renew_path()
5958
if sys.platform in ["win32", "cygwin", "msys"]:
60-
exec_str = json.dumps(exec_str)
61-
args = [
62-
self.compiler_path,
63-
"-m",
64-
package,
65-
"--execute_str",
66-
exec_str
67-
]
68-
else:
69-
args = " ".join([f"{self.compiler_path}", f"-m {package}", "--execute_str", f"{exec_str}"])
70-
self.process: subprocess.Popen = subprocess.Popen(
59+
exec_str = __import__("json").dumps(exec_str)
60+
args = [
61+
str(self.compiler_path),
62+
"-m",
63+
package,
64+
"--execute_str",
65+
exec_str
66+
]
67+
self.process = subprocess.Popen(
7168
args,
7269
stdin=subprocess.PIPE,
7370
stdout=subprocess.PIPE,
7471
stderr=subprocess.PIPE,
75-
shell=True,
76-
encoding=self.program_encoding
7772
)
7873
self.still_run_program = True
7974
# program output message queue thread
@@ -143,7 +138,7 @@ def exit_program(self):
143138
self.read_program_output_from_thread = None
144139
if self.read_program_error_output_from_thread is not None:
145140
self.read_program_error_output_from_thread = None
146-
self.print_and_clear_queue()
141+
self.drain_and_display_queue()
147142
if self.process is not None:
148143
self.process.terminate()
149144
text_cursor = self.main_window.code_result.textCursor()
@@ -152,26 +147,56 @@ def exit_program(self):
152147
text_cursor.insertText(f"Task exit with code {self.process.returncode}", text_format)
153148
text_cursor.insertBlock()
154149
self.process = None
150+
if self.task_done_trigger_function is not None:
151+
try:
152+
self.task_done_trigger_function()
153+
except Exception as e:
154+
print(repr(e), file=sys.stderr)
155155

156-
def print_and_clear_queue(self):
157-
self.run_output_queue = queue.Queue()
158-
self.run_error_queue = queue.Queue()
156+
def drain_and_display_queue(self):
157+
while not self.run_output_queue.empty():
158+
try:
159+
output_message = self.run_output_queue.get_nowait()
160+
output_message = str(output_message).strip()
161+
if output_message:
162+
text_cursor = self.main_window.code_result.textCursor()
163+
text_format = QTextCharFormat()
164+
text_format.setForeground(actually_color_dict.get("normal_output_color"))
165+
text_cursor.insertText(output_message, text_format)
166+
text_cursor.insertBlock()
167+
except queue.Empty:
168+
break
169+
while not self.run_error_queue.empty():
170+
try:
171+
error_message = self.run_error_queue.get_nowait()
172+
error_message = str(error_message).strip()
173+
if error_message:
174+
text_cursor = self.main_window.code_result.textCursor()
175+
text_format = QTextCharFormat()
176+
text_format.setForeground(actually_color_dict.get("error_output_color"))
177+
text_cursor.insertText(error_message, text_format)
178+
text_cursor.insertBlock()
179+
except queue.Empty:
180+
break
159181

160182
def read_program_output_from_process(self):
161183
while self.still_run_program:
162-
self.process: subprocess.Popen
163-
program_output_data = self.process.stdout.readline(self.program_buffer_size) \
164-
.decode("utf-8", "replace")
165-
if self.process:
166-
self.process.stdout.flush()
167-
if program_output_data.strip() != "":
184+
proc = self.process
185+
if proc is None:
186+
break
187+
program_output_data = proc.stdout.readline(self.program_buffer_size)
188+
if isinstance(program_output_data, bytes):
189+
program_output_data = program_output_data.decode(self.program_encoding, "replace")
190+
if program_output_data.strip():
168191
self.run_output_queue.put(program_output_data)
169192

170193
def read_program_error_output_from_process(self):
171194
while self.still_run_program:
172-
program_error_output_data = self.process.stderr.readline(self.program_buffer_size) \
173-
.decode("utf-8", "replace")
174-
if self.process:
175-
self.process.stderr.flush()
176-
if program_error_output_data.strip() != "":
195+
proc = self.process
196+
if proc is None:
197+
break
198+
program_error_output_data = proc.stderr.readline(self.program_buffer_size)
199+
if isinstance(program_error_output_data, bytes):
200+
program_error_output_data = program_error_output_data.decode(self.program_encoding, "replace")
201+
if program_error_output_data.strip():
177202
self.run_error_queue.put(program_error_output_data)

pybreeze/extend/process_executor/test_pioneer/test_pioneer_process_manager.py

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(
3737
self._main_window.clear_code_result()
3838
self._still_run_program: bool = False
3939
self._program_buffer_size = program_buffer
40+
self._program_encoding = encoding
4041
self._run_output_queue: Queue = Queue()
4142
self._run_error_queue: Queue = Queue()
4243
self._read_program_error_output_from_thread: Union[threading.Thread, None] = None
@@ -51,25 +52,18 @@ def __init__(
5152
self._compiler_path = check_and_choose_venv(venv_path)
5253
else:
5354
self._compiler_path = main_window.python_compiler
54-
if sys.platform in ["win32", "cygwin", "msys"]:
55-
args = [
56-
self._compiler_path,
57-
"-m",
58-
"test_pioneer",
59-
"-e",
60-
executable_path
61-
]
62-
else:
63-
args = " ".join([
64-
f"{self._compiler_path}", "-m test_pioneer", "-e", f"{executable_path}"
65-
])
66-
self._process: subprocess.Popen = subprocess.Popen(
55+
args = [
56+
str(self._compiler_path),
57+
"-m",
58+
"test_pioneer",
59+
"-e",
60+
executable_path
61+
]
62+
self._process: Union[subprocess.Popen, None] = subprocess.Popen(
6763
args,
6864
stdin=subprocess.PIPE,
6965
stdout=subprocess.PIPE,
7066
stderr=subprocess.PIPE,
71-
shell=True,
72-
encoding=encoding
7367
)
7468

7569
# Pyside UI update method
@@ -118,7 +112,7 @@ def exit_program(self):
118112
self._read_program_output_from_thread = None
119113
if self._read_program_error_output_from_thread is not None:
120114
self._read_program_error_output_from_thread = None
121-
self.print_and_clear_queue()
115+
self.drain_and_clear_queue()
122116
if self._process is not None:
123117
self._process.terminate()
124118
text_cursor = self._code_window.code_result.textCursor()
@@ -128,27 +122,52 @@ def exit_program(self):
128122
text_cursor.insertBlock()
129123
self._process = None
130124

131-
def print_and_clear_queue(self):
132-
self._run_output_queue = queue.Queue()
133-
self._run_error_queue = queue.Queue()
125+
def drain_and_clear_queue(self):
126+
while not self._run_output_queue.empty():
127+
try:
128+
output_message = self._run_output_queue.get_nowait()
129+
output_message = str(output_message).strip()
130+
if output_message:
131+
text_cursor = self._code_window.code_result.textCursor()
132+
text_format = QTextCharFormat()
133+
text_format.setForeground(actually_color_dict.get("normal_output_color"))
134+
text_cursor.insertText(output_message, text_format)
135+
text_cursor.insertBlock()
136+
except queue.Empty:
137+
break
138+
while not self._run_error_queue.empty():
139+
try:
140+
error_message = self._run_error_queue.get_nowait()
141+
error_message = str(error_message).strip()
142+
if error_message:
143+
text_cursor = self._code_window.code_result.textCursor()
144+
text_format = QTextCharFormat()
145+
text_format.setForeground(actually_color_dict.get("error_output_color"))
146+
text_cursor.insertText(error_message, text_format)
147+
text_cursor.insertBlock()
148+
except queue.Empty:
149+
break
134150

135151
def read_program_output_from_process(self):
136152
while self._still_run_program:
137-
self.process: subprocess.Popen
138-
program_output_data = self._process.stdout.readline(self._program_buffer_size) \
139-
.decode("utf-8", "replace")
140-
if self._process:
141-
self._process.stdout.flush()
142-
if program_output_data.strip() != "":
153+
proc = self._process
154+
if proc is None:
155+
break
156+
program_output_data = proc.stdout.readline(self._program_buffer_size)
157+
if isinstance(program_output_data, bytes):
158+
program_output_data = program_output_data.decode(self._program_encoding, "replace")
159+
if program_output_data.strip():
143160
self._run_output_queue.put(program_output_data)
144161

145162
def read_program_error_output_from_process(self):
146163
while self._still_run_program:
147-
program_error_output_data = self._process.stderr.readline(self._program_buffer_size) \
148-
.decode("utf-8", "replace")
149-
if self._process:
150-
self._process.stderr.flush()
151-
if program_error_output_data.strip() != "":
164+
proc = self._process
165+
if proc is None:
166+
break
167+
program_error_output_data = proc.stderr.readline(self._program_buffer_size)
168+
if isinstance(program_error_output_data, bytes):
169+
program_error_output_data = program_error_output_data.decode(self._program_encoding, "replace")
170+
if program_error_output_data.strip():
152171
self._run_error_queue.put(program_error_output_data)
153172

154173
def start_test_pioneer_process(self):

pybreeze/extend/process_executor/web_runner/web_runner_process.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def call_web_runner_test_multi_file(
3636
if need_to_execute_list is not None and isinstance(need_to_execute_list, list) and len(
3737
need_to_execute_list) > 0:
3838
for execute_file in need_to_execute_list:
39-
with open(execute_file, "r+") as test_script_json:
39+
with open(execute_file, "r") as test_script_json:
4040
call_web_runner_test(
4141
main_window,
4242
test_script_json.read(),
@@ -56,7 +56,7 @@ def call_web_runner_test_multi_file_and_send(
5656
if need_to_execute_list is not None and isinstance(need_to_execute_list, list) and len(
5757
need_to_execute_list) > 0:
5858
for execute_file in need_to_execute_list:
59-
with open(execute_file, "r+") as test_script_json:
59+
with open(execute_file, "r") as test_script_json:
6060
call_web_runner_test_with_send(
6161
main_window,
6262
test_script_json.read(),

pybreeze/pybreeze_ui/connect_gui/ssh/ssh_command_widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def connect_ssh(self):
175175
self.reader_thread.closed.connect(self._on_closed)
176176
self.reader_thread.start()
177177
self.login_widget.status_label.setText(
178-
self.word_dict.get("ssh_command_widget_dialog_title_not_connected"))
178+
self.word_dict.get("ssh_command_widget_log_message_connected"))
179179
self.append_text(f"{self.word_dict.get('ssh_command_widget_log_message_connected')}"
180180
f" {host}:{port} as {user}\n")
181181
except Exception as e:

0 commit comments

Comments
 (0)