Switch UI to HTML based tools
Some checks failed
Mirror to Gitea / mirror (push) Has been cancelled

This commit is contained in:
2026-08-12 04:56:02 +03:30
parent 7c50480324
commit f1d9693966
19 changed files with 1523 additions and 489 deletions

127
tests/test_gui_app.py Normal file
View File

@@ -0,0 +1,127 @@
from pathlib import Path
from types import SimpleNamespace
from unittest.mock import patch
from xlsx_clean.gui_app import Api
def test_initial_data_stores_state_and_uses_first_set_inks():
rows = [{"set_name": "Set A"}]
config = {"backend": "ooxml"}
with patch(
"xlsx_clean.gui_app.load_config",
return_value=(["Set", "Ink", "Serial", "addin-a", "addin-b"], rows, config),
), patch("xlsx_clean.gui_app.list_sets", return_value=["Set A"]), patch(
"xlsx_clean.gui_app.list_ink_colors", return_value=["Blue"]
) as inks:
api = Api()
data = api.get_initial_data()
assert data["sets"] == ["Set A"]
assert data["inks"] == ["Blue"]
assert data["labels"] == {"set": "Set", "ink": "Ink", "serial": "Serial"}
assert api.rows == rows
assert api.addin_paths == ["addin-a", "addin-b"]
assert api.config == config
inks.assert_called_once_with(rows, "Set A")
def test_initial_data_uses_safe_label_fallbacks_and_empty_inks():
with (
patch("xlsx_clean.gui_app.load_config", return_value=([], [], {})),
patch("xlsx_clean.gui_app.list_sets", return_value=[]),
patch("xlsx_clean.gui_app.list_ink_colors") as inks,
):
data = Api().get_initial_data()
assert data["labels"] == {
"set": "Select Set",
"ink": "Select Ink Color",
"serial": "Serial:",
}
assert data["inks"] == []
inks.assert_not_called()
def test_get_inks_uses_initialized_rows():
api = Api()
api.rows = [{"set_name": "Set A"}]
with patch("xlsx_clean.gui_app.list_ink_colors", return_value=["Blue"]) as inks:
assert api.get_inks("Set A") == ["Blue"]
inks.assert_called_once_with(api.rows, "Set A")
def test_create_passes_core_arguments_and_serializes_paths():
api = Api()
api.rows = [{"set_name": "Set A"}]
api.addin_paths = ["addin-a"]
api.config = {"backend": "ooxml"}
result = SimpleNamespace(
ok=True,
skipped=False,
message="Wrote workbook",
template=Path("template.xlsx"),
destination=Path("output.xlsx"),
backend="ooxml",
)
with patch("xlsx_clean.gui_app.create_datasheet", return_value=result) as create:
response = api.create("Set A", "Blue", "1234/A")
create.assert_called_once_with(
selected_set="Set A",
selected_dir="Blue",
batch_serial="1234/A",
backend=None,
rows=api.rows,
addin_paths=api.addin_paths,
config=api.config,
)
assert response == {
"ok": True,
"skipped": False,
"message": "Wrote workbook",
"template": "template.xlsx",
"destination": "output.xlsx",
"backend": "ooxml",
}
def test_create_serializes_missing_paths_for_error_or_skipped_result():
api = Api()
result = SimpleNamespace(
ok=False,
skipped=False,
message="Select a set.",
template=None,
destination=None,
backend=None,
)
with patch("xlsx_clean.gui_app.create_datasheet", return_value=result):
response = api.create("", "", "")
assert response["template"] is None
assert response["destination"] is None
assert response["ok"] is False
def test_create_serializes_unexpected_exceptions_into_result_contract():
api = Api()
api.rows = [{"set_name": "Set A"}]
api.addin_paths = []
api.config = {"backend": "ooxml"}
def boom(**kwargs):
raise RuntimeError("backend exploded")
with patch("xlsx_clean.gui_app.create_datasheet", side_effect=boom):
response = api.create("Set A", "Blue", "1234/A")
assert response == {
"ok": False,
"skipped": False,
"message": "Unexpected error: backend exploded",
"template": None,
"destination": None,
"backend": None,
}

View File

@@ -0,0 +1,44 @@
from pathlib import Path
from unittest.mock import MagicMock, patch
from xlsx_clean import gui_app
def test_parse_args_uses_default_dimensions():
args = gui_app.parse_args([])
assert (args.width, args.height) == (800, 600)
def test_main_initializes_api_before_opening_window():
index_html = Path("/tmp/index.html")
events = []
api = MagicMock()
def create_window(**kwargs):
events.append(("create_window", kwargs))
with (
patch("xlsx_clean.gui_app.Api", return_value=api),
patch("xlsx_clean.gui_app.package_file", return_value=index_html) as package_file,
patch("xlsx_clean.gui_app.webview.create_window", side_effect=create_window),
patch("xlsx_clean.gui_app.webview.start", side_effect=lambda: events.append(("start",))),
):
gui_app.main(["--width", "900", "--height", "700"])
package_file.assert_called_once_with("ui/index.html")
api.initialize.assert_called_once_with()
assert events == [
(
"create_window",
{
"title": f"New QC Sheet · v{gui_app._VERSION}",
"url": index_html.as_uri(),
"js_api": api,
"width": 900,
"height": 700,
"min_size": (450, 400),
"background_color": "#f8fafc",
},
),
("start",),
]

14
tests/test_packaging.py Normal file
View File

@@ -0,0 +1,14 @@
from pathlib import Path
def test_pyinstaller_spec_collects_webview_and_local_assets():
spec = Path("packaging/xlsx_clean.spec").read_text(encoding="utf-8")
assert 'collect_all("webview")' in spec
assert 'collect_all("dearpygui")' not in spec
assert '"ui"), "xlsx_clean/ui")' in spec
assert '"fonts"), "xlsx_clean/fonts")' in spec
assert 'if sys.platform == "win32":' in spec
assert 'collect_all("clr_loader")' in spec
for hidden_import in ('"clr"', '"clr_loader"', '"pythonnet"'):
assert hidden_import in spec

50
tests/test_ui_assets.py Normal file
View File

@@ -0,0 +1,50 @@
import re
from html.parser import HTMLParser
from xlsx_clean.paths import package_file
class StrictHtmlParser(HTMLParser):
def error(self, message):
raise AssertionError(message)
def test_ui_asset_exists_and_has_required_bridge_content():
html_path = package_file("ui/index.html")
assert html_path.is_file()
content = html_path.read_text(encoding="utf-8")
for expected in (
"New QC Sheet",
"Create a new QC datasheet from the latest matching workbook.",
'id="set-label"',
'id="ink-label"',
'id="serial-label"',
"Create datasheet",
"status-ready",
"status-success",
"status-skipped",
"status-error",
'id="version"',
"pywebviewready",
"get_initial_data()",
"get_inks(setDropdown.value)",
"api.create(",
"finally",
):
assert expected in content
assert "tailwind" not in content.lower()
assert "quasar" not in content.lower()
assert "cdn" not in content.lower()
assert not re.search(r"https?://", content)
StrictHtmlParser().feed(content)
def test_ui_font_sources_are_bundled_locally():
content = package_file("ui/index.html").read_text(encoding="utf-8")
font_urls = re.findall(r'url\("([^\"]+\.ttf)"\)', content)
assert font_urls == ["../fonts/Inter-Regular.ttf", "../fonts/Inter-Bold.ttf"]
for font_url in font_urls:
assert (package_file("ui") / font_url).resolve().is_file()