unit testing and others

This commit is contained in:
2026-08-21 00:12:29 -07:00
parent 2f76622e52
commit 7a438b1798
7 changed files with 936 additions and 171 deletions
+49 -3
View File
@@ -8,11 +8,13 @@ License: GPL-3.0
"""
# Built-in imports
import sys
from pathlib import Path
from typing import Any, Callable
# External library imports
from PySide6.QtWidgets import QWidget, QVBoxLayout, QTextEdit, QLineEdit
from PySide6.QtCore import Qt, QThread, Signal
from PySide6.QtCore import QProcess, Qt, QThread, Signal
from file_ext_registration import register_file_association, is_windows_admin
from src.shared.shareddata import API_URL, API_URL_SECONDARY, APP_NAME, CURRENT_VERSION, PLATFORM_NAME
@@ -55,6 +57,8 @@ class TerminalWindow(QWidget):
layout.addWidget(self.input_line)
self.setLayout(layout)
self._process: QProcess | None = None
self.commands: dict[str, Callable[..., Any]] = {
"hello": self.cmd_hello,
"help": self.cmd_help,
@@ -62,6 +66,7 @@ class TerminalWindow(QWidget):
"about": self.cmd_about,
"assoc": self.cmd_assoc,
"update": self.cmd_update,
"utest": self.cmd_utest,
}
self._pending_assoc_confirmation: bool = False
@@ -107,7 +112,8 @@ class TerminalWindow(QWidget):
return "Hello from the terminal!"
def cmd_help(self, *args: Any) -> str:
return f"Available commands: {', '.join(self.commands.keys())}"
available_cmds = [cmd for cmd in self.commands.keys() if cmd != "utest"]
return f"Available commands: {', '.join(available_cmds)}"
def cmd_version(self, *args: Any) -> str:
return f"{APP_NAME.upper()} is running version {CURRENT_VERSION}."
@@ -163,4 +169,44 @@ class TerminalWindow(QWidget):
def _on_assoc_result(self, ok: bool, msg: str) -> None:
self.output_area.append(msg)
self._assoc_worker = None
self._assoc_worker = None
def cmd_utest(self, *args: Any) -> str | None:
"""Executes a specific pre-defined python script non-blockingly."""
if self._process and self._process.state() != QProcess.ProcessState.NotRunning:
return "[Error] A process is already running."
target_script = Path("main_unit_tests.py")
if not target_script.exists():
return f"[Error] Target script not found at: {target_script}"
self._process = QProcess(self)
# Stream stdout and stderr live to output_area
self._process.readyReadStandardOutput.connect(self._handle_stdout)
self._process.readyReadStandardError.connect(self._handle_stderr)
self._process.finished.connect(self._handle_process_finished)
# Use current Python interpreter executable. Works when packaged?
python_executable = sys.executable
self.output_area.append(f"Starting {target_script.name}...")
self._process.start(python_executable, [str(target_script)])
return None
def _handle_stdout(self) -> None:
if self._process:
data = self._process.readAllStandardOutput().data().decode("utf-8")
if data.strip():
self.output_area.append(data.strip())
def _handle_stderr(self) -> None:
if self._process:
data = self._process.readAllStandardError().data().decode("utf-8")
if data.strip():
self.output_area.append(f"[Error] {data.strip()}")
def _handle_process_finished(self, exit_code: int, exit_status: QProcess.ExitStatus) -> None:
self.output_area.append(f"Process finished with code {exit_code}.")
self._process = None