release: ship validated Mentor PDF exporter v1.0.0
This commit is contained in:
1 parent
d4928af5b6
commit
0334f2b85b
50 files changed
+3998
-219
No files matched your search
+445
-4
@@ -1,20 +1,24 @@
|
||||
import threading
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
from pypdf import PdfWriter
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6.QtGui import QPalette
|
||||
from PySide6.QtWidgets import QFileDialog, QLabel
|
||||
from mentor_pdf_export.ui import MainWindow
|
||||
from mentor_pdf_export.exporter import Exporter
|
||||
from mentor_pdf_export.models import ExportResult
|
||||
|
||||
|
||||
def runner(args, cwd, log_dir, cancel, timeout, on_event=None):
|
||||
def runner(args, cwd, log_dir, cancel, timeout, on_event=None, *, env=None):
|
||||
writer = PdfWriter(); writer.add_blank_page(width=500,height=400)
|
||||
with Path(args[args.index("-a")+1]).open("wb") as f:
|
||||
writer.write(f)
|
||||
return 0
|
||||
|
||||
|
||||
def make_window(qtbot, tmp_path, factory=None):
|
||||
window = MainWindow(root=str(tmp_path), output=str(tmp_path / "pdfs"), runs_root=tmp_path.parent / (tmp_path.name + "-runs"), exporter_factory=factory)
|
||||
def make_window(qtbot, tmp_path, factory=None, library=None):
|
||||
window = MainWindow(root=str(tmp_path), output=str(tmp_path / "pdfs"), runs_root=tmp_path.parent / (tmp_path.name + "-runs"), exporter_factory=factory, library=library, font_mapping="preserve", print_theme="original", legacy_gbk=False)
|
||||
qtbot.addWidget(window); window.show()
|
||||
return window
|
||||
|
||||
@@ -47,6 +51,9 @@ def test_export_worker_result_and_buttons(qtbot, project_factory, tmp_path):
|
||||
assert window.busy
|
||||
assert not window.start_button.isEnabled()
|
||||
assert not window.options_group.isEnabled()
|
||||
assert not window.font_mapping_combo.isEnabled()
|
||||
assert not window.print_theme_combo.isEnabled()
|
||||
assert not window.legacy_gbk_check.isEnabled()
|
||||
qtbot.waitUntil(lambda: not window.busy,timeout=10000)
|
||||
assert window.table.item(0,3).text()=="成功"
|
||||
assert window.start_button.isEnabled()
|
||||
@@ -58,7 +65,7 @@ def test_export_worker_result_and_buttons(qtbot, project_factory, tmp_path):
|
||||
def test_cancel_signal_is_requested(qtbot, project_factory, tmp_path):
|
||||
project_factory()
|
||||
started=threading.Event()
|
||||
def waiting(args,cwd,log_dir,cancel,timeout,on_event=None):
|
||||
def waiting(args,cwd,log_dir,cancel,timeout,on_event=None, *, env=None):
|
||||
started.set()
|
||||
assert cancel.wait(5)
|
||||
raise InterruptedError("任务已停止")
|
||||
@@ -101,3 +108,437 @@ def test_ui_preflights_all_source_paths_before_queue(qtbot,project_factory,tmp_p
|
||||
qtbot.waitUntil(lambda:not window.busy,timeout=10000)
|
||||
assert not unexpectedly_started
|
||||
assert window.worker is None
|
||||
|
||||
|
||||
def test_direct_mode_has_no_library_replacement_controls(qtbot,tmp_path):
|
||||
window=make_window(qtbot,tmp_path)
|
||||
assert not hasattr(window,'library_edit')
|
||||
assert not hasattr(window,'library_toggle')
|
||||
assert '原工程' in window.root_edit.toolTip()
|
||||
assert window.options().library_override==''
|
||||
|
||||
|
||||
|
||||
def test_constructor_rejects_library_replacement_in_direct_mode(qtbot,tmp_path):
|
||||
with pytest.raises(ValueError,match='依赖库'):
|
||||
MainWindow(root=tmp_path,library=tmp_path/'matching.lmc')
|
||||
|
||||
|
||||
|
||||
def test_library_information_is_read_only(qtbot,tmp_path):
|
||||
window=make_window(qtbot,tmp_path)
|
||||
assert not hasattr(window, 'library_help')
|
||||
assert '不替换库' in window.root_edit.toolTip()
|
||||
assert not any('依赖库' in label.text() for label in window.findChildren(QLabel) if label.isVisible())
|
||||
assert not hasattr(window,'choose_library')
|
||||
|
||||
|
||||
|
||||
def test_profile_defaults_preserve_existing_export_modes(qtbot, tmp_path):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
assert window.font_mapping_combo.currentData() == "preserve"
|
||||
assert window.print_theme_combo.currentData() == "original"
|
||||
options = window.options()
|
||||
assert options.font_mapping == "preserve"
|
||||
assert options.print_theme == "original"
|
||||
assert options.color == 4
|
||||
assert [window.color_combo.itemData(i) for i in range(window.color_combo.count())] == [4, 3, 1, 2]
|
||||
assert not hasattr(window, "profile_warning_label")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("label, mapping", [
|
||||
("原映射", "preserve"),
|
||||
("Arial+中文回退(推荐)", "arial"),
|
||||
("宋体(中文对照)", "simsun"),
|
||||
("微软雅黑(中文对照)", "msyh"),
|
||||
])
|
||||
def test_font_mapping_flows_to_options(qtbot, tmp_path, label, mapping):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
index = window.font_mapping_combo.findText(label)
|
||||
assert index >= 0
|
||||
window.font_mapping_combo.setCurrentIndex(index)
|
||||
assert window.options().font_mapping == mapping
|
||||
|
||||
|
||||
@pytest.mark.parametrize("theme", ["original", "high_contrast", "mono"])
|
||||
def test_print_theme_enforces_color_and_restores_original_choice(qtbot, tmp_path, theme):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
index = window.print_theme_combo.findData(theme)
|
||||
assert index >= 0
|
||||
window.print_theme_combo.setCurrentIndex(index)
|
||||
for color_index, existing_color in enumerate([4, 3, 1, 2]):
|
||||
window.color_combo.setCurrentIndex(color_index)
|
||||
options = window.options()
|
||||
assert options.print_theme == theme
|
||||
expected_color = {"high_contrast": 4, "mono": 3}.get(theme, existing_color)
|
||||
assert options.color == expected_color
|
||||
window.print_theme_combo.setCurrentIndex(window.print_theme_combo.findData("original"))
|
||||
assert window.options().color == 2
|
||||
|
||||
|
||||
def test_profile_tooltips_explain_processing_and_sample_limits(qtbot, tmp_path):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
assert window.print_theme_combo.findText("白底高对比(可选)") >= 0
|
||||
for mapping in ("arial", "simsun", "msyh"):
|
||||
window.font_mapping_combo.setCurrentIndex(window.font_mapping_combo.findData(mapping))
|
||||
assert not hasattr(window, "profile_warning_label")
|
||||
explanation = window.font_mapping_combo.toolTip()
|
||||
assert "发布前" in explanation and "文字编码" in explanation
|
||||
assert "样本" in explanation and "其他工程" in explanation
|
||||
for detail in ("矢量", "坐标", "书签", "注释", "不添加白色遮罩", "不栅格化"):
|
||||
assert detail in explanation
|
||||
assert "未验证" not in explanation and "未生效" not in explanation
|
||||
assert "不保证修复中文" not in explanation
|
||||
if mapping == "arial":
|
||||
assert "Arial" in explanation and "宋体" in explanation and "17" in explanation
|
||||
window.font_mapping_combo.setCurrentIndex(window.font_mapping_combo.findData("preserve"))
|
||||
assert not hasattr(window, "profile_warning_label")
|
||||
window.print_theme_combo.setCurrentIndex(window.print_theme_combo.findData("high_contrast"))
|
||||
assert not hasattr(window, "profile_warning_label")
|
||||
assert "深色前景" in window.font_mapping_combo.toolTip()
|
||||
assert "浅色填充" in window.font_mapping_combo.toolTip()
|
||||
assert "0.35pt" in window.font_mapping_combo.toolTip()
|
||||
window.print_theme_combo.setCurrentIndex(window.print_theme_combo.findData("mono"))
|
||||
assert not hasattr(window, "profile_warning_label")
|
||||
assert "黑白" in window.font_mapping_combo.toolTip()
|
||||
window.print_theme_combo.setCurrentIndex(window.print_theme_combo.findData("original"))
|
||||
assert not hasattr(window, "profile_warning_label")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", ["scan", "batch"])
|
||||
def test_new_controls_lock_and_restore_with_busy_state(qtbot, tmp_path, kind):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
controls = (
|
||||
window.root_edit, window.engine_edit,
|
||||
window.font_mapping_combo, window.print_theme_combo, window.legacy_gbk_check,
|
||||
)
|
||||
window._set_busy(True, kind)
|
||||
assert all(not control.isEnabled() for control in controls)
|
||||
assert window.stop_button.isEnabled() == (kind == "batch")
|
||||
window._set_busy(False, kind)
|
||||
assert all(control.isEnabled() for control in controls)
|
||||
|
||||
|
||||
def test_blue_gray_palette_has_blue_primary_and_white_cards(qtbot, project_factory, tmp_path):
|
||||
project_factory()
|
||||
window = make_window(qtbot, tmp_path)
|
||||
window.scan_projects()
|
||||
qtbot.waitUntil(lambda: window.table.rowCount() == 1 and not window.busy, timeout=10000)
|
||||
qtbot.wait(20)
|
||||
assert window.start_button.palette().color(QPalette.Button).name() == "#2563eb"
|
||||
assert window.palette().color(QPalette.Window).name() == "#f1f5f9"
|
||||
assert window.paths_group.palette().color(QPalette.Window).name() == "#ffffff"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("status, color", [
|
||||
("success", "#16a34a"), ("skipped", "#d97706"),
|
||||
("uncertain", "#d97706"), ("failed", "#dc2626"),
|
||||
("timeout", "#dc2626"),
|
||||
])
|
||||
def test_result_status_keeps_semantic_colors(qtbot, project_factory, tmp_path, status, color):
|
||||
project_factory()
|
||||
window = make_window(qtbot, tmp_path)
|
||||
window.scan_projects()
|
||||
qtbot.waitUntil(lambda: window.table.rowCount() == 1 and not window.busy, timeout=10000)
|
||||
window._item_result(0, ExportResult(project="board", status=status, message="对照结果"))
|
||||
assert window.table.item(0, 3).foreground().color().name() == color
|
||||
|
||||
|
||||
def test_selection_and_advanced_controls_do_not_reset_scroll(qtbot, project_factory, tmp_path):
|
||||
for number in range(45):
|
||||
project_factory(f"board-{number:02d}")
|
||||
window = make_window(qtbot, tmp_path)
|
||||
window.scan_projects()
|
||||
qtbot.waitUntil(lambda: window.table.rowCount() == 45 and not window.busy, timeout=10000)
|
||||
scrollbar = window.table.verticalScrollBar()
|
||||
qtbot.waitUntil(lambda: scrollbar.maximum() > 0)
|
||||
scrollbar.setValue(scrollbar.maximum() // 2)
|
||||
position = scrollbar.value()
|
||||
item = window.table.item(25, 0)
|
||||
item.setCheckState(Qt.Unchecked)
|
||||
qtbot.mouseClick(window.select_all_button, Qt.LeftButton)
|
||||
assert scrollbar.value() == position
|
||||
assert window.table.item(25, 0) is item
|
||||
window.font_mapping_combo.setCurrentIndex(window.font_mapping_combo.findData("arial"))
|
||||
qtbot.wait(20)
|
||||
assert scrollbar.value() == position
|
||||
window.font_mapping_combo.setCurrentIndex(window.font_mapping_combo.findData("arial"))
|
||||
window.font_mapping_combo.setCurrentIndex(window.font_mapping_combo.findData("arial"))
|
||||
qtbot.wait(20)
|
||||
assert scrollbar.value() == position
|
||||
assert window.selected_count() == 45
|
||||
|
||||
|
||||
@pytest.mark.parametrize("theme", ["original", "high_contrast", "mono"])
|
||||
def test_expanded_advanced_settings_leave_queue_rows_visible(qtbot, project_factory, tmp_path, theme):
|
||||
for number in range(6):
|
||||
project_factory(f"board-{number}")
|
||||
window = make_window(qtbot, tmp_path)
|
||||
qtbot.mouseClick(window.advanced_button, Qt.LeftButton)
|
||||
assert window.advanced_panel.isVisible()
|
||||
window.scan_projects()
|
||||
qtbot.waitUntil(lambda: window.table.rowCount() == 6 and not window.busy, timeout=10000)
|
||||
window.font_mapping_combo.setCurrentIndex(window.font_mapping_combo.findData("arial"))
|
||||
window.font_mapping_combo.setCurrentIndex(window.font_mapping_combo.findData("arial"))
|
||||
window.print_theme_combo.setCurrentIndex(window.print_theme_combo.findData(theme))
|
||||
qtbot.wait(50)
|
||||
assert window.table.viewport().visibleRegion().boundingRect().height() >= 2 * window.table.rowHeight(0)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("theme", ["original", "high_contrast", "mono"])
|
||||
def test_color_selector_only_enabled_for_original_and_restores_after_busy(qtbot, tmp_path, theme):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
window.color_combo.setCurrentIndex(window.color_combo.findData(2))
|
||||
window.print_theme_combo.setCurrentIndex(window.print_theme_combo.findData(theme))
|
||||
assert window.color_combo.isEnabled() == (theme == "original")
|
||||
assert window.color_combo.currentData() == 2
|
||||
for kind in ("scan", "batch"):
|
||||
window._set_busy(True, kind)
|
||||
assert not window.color_combo.isEnabled()
|
||||
window._set_busy(False, kind)
|
||||
assert window.color_combo.isEnabled() == (theme == "original")
|
||||
window.print_theme_combo.setCurrentIndex(window.print_theme_combo.findData("original"))
|
||||
assert window.color_combo.isEnabled()
|
||||
assert window.options().color == 2
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mapping, theme", [
|
||||
("arial", "high_contrast"), ("simsun", "mono"),
|
||||
("msyh", "original"), ("preserve", "original"),
|
||||
])
|
||||
def test_constructor_accepts_explicit_profile_defaults(qtbot, tmp_path, mapping, theme):
|
||||
window = MainWindow(root=tmp_path, output=tmp_path / "pdfs", font_mapping=mapping, print_theme=theme)
|
||||
qtbot.addWidget(window)
|
||||
window.show()
|
||||
assert window.font_mapping_combo.currentData() == mapping
|
||||
assert window.print_theme_combo.currentData() == theme
|
||||
options = window.options()
|
||||
assert options.font_mapping == mapping
|
||||
assert options.print_theme == theme
|
||||
assert options.color == (3 if theme == "mono" else 4)
|
||||
assert window.color_combo.isEnabled() == (theme == "original")
|
||||
assert not hasattr(window, "profile_warning_label")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("defaults, message", [
|
||||
({"font_mapping": "arail"}, "字体"),
|
||||
({"print_theme": "unknown"}, "配色"),
|
||||
])
|
||||
def test_constructor_rejects_unknown_profile_defaults(qtbot, defaults, message):
|
||||
with pytest.raises(ValueError, match=message):
|
||||
MainWindow(**defaults)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mapping, theme", [
|
||||
("arial", "original"), ("preserve", "high_contrast"), ("msyh", "mono"),
|
||||
])
|
||||
def test_profile_tooltips_expose_limited_compatibility_scope(qtbot, tmp_path, mapping, theme):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
window.font_mapping_combo.setCurrentIndex(window.font_mapping_combo.findData(mapping))
|
||||
window.print_theme_combo.setCurrentIndex(window.print_theme_combo.findData(theme))
|
||||
assert not hasattr(window, "profile_warning_label")
|
||||
assert "兼容范围有限" in window.font_mapping_combo.toolTip()
|
||||
assert "其他工程" in window.font_mapping_combo.toolTip()
|
||||
explanation = window.font_mapping_combo.toolTip()
|
||||
assert "不代表所有 PDF" in explanation
|
||||
assert "字体" in explanation and "文字结构" in explanation
|
||||
assert "样张" in explanation
|
||||
assert "未验证" not in explanation and "未生效" not in explanation
|
||||
|
||||
|
||||
|
||||
def test_legacy_gbk_is_explicit_and_respects_disabled_override(qtbot, tmp_path):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
assert window.legacy_gbk_check.text() == "CP936 / GBK 修复"
|
||||
assert not window.legacy_gbk_check.isChecked()
|
||||
assert window.options().legacy_gbk is False
|
||||
explanation = window.legacy_gbk_check.toolTip()
|
||||
assert "WinAnsi" in explanation and "±" in explanation and "×" in explanation
|
||||
assert "不适用于" in explanation
|
||||
assert "已确认" in explanation
|
||||
assert "Arial" in explanation and "不等于编码修复" in explanation
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mapping", ["arial", "simsun", "msyh"])
|
||||
def test_font_mapping_alone_does_not_enable_encoding_repair(qtbot, tmp_path, mapping):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
window.font_mapping_combo.setCurrentIndex(window.font_mapping_combo.findData(mapping))
|
||||
assert window.options().font_mapping == mapping
|
||||
assert window.options().legacy_gbk is False
|
||||
assert not window.legacy_gbk_check.isChecked()
|
||||
assert "不自动修复编码" in window.font_mapping_combo.toolTip()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("mapping", ["arial", "simsun", "msyh"])
|
||||
def test_explicit_legacy_gbk_flows_to_options(qtbot, tmp_path, mapping):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
window.font_mapping_combo.setCurrentIndex(window.font_mapping_combo.findData(mapping))
|
||||
# Matches the CLI follow-up: explicitly opt in after constructing the window.
|
||||
window.legacy_gbk_check.setChecked(True)
|
||||
assert window.options().legacy_gbk is True
|
||||
assert window.options().font_mapping == mapping
|
||||
assert "CP936 / GBK" in window.font_mapping_combo.toolTip()
|
||||
assert "修复" in window.font_mapping_combo.toolTip()
|
||||
window.legacy_gbk_check.setChecked(False)
|
||||
assert window.options().legacy_gbk is False
|
||||
assert "不自动修复编码" in window.font_mapping_combo.toolTip()
|
||||
|
||||
|
||||
def test_legacy_gbk_rejects_preserve_without_silently_changing_font(qtbot, tmp_path):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
window.legacy_gbk_check.setChecked(True)
|
||||
assert window.font_mapping_combo.currentData() == "preserve"
|
||||
with pytest.raises(ValueError) as error:
|
||||
window.options()
|
||||
message = str(error.value)
|
||||
for choice in ("Arial", "SimSun", "YaHei"):
|
||||
assert choice in message
|
||||
assert "选择" in message
|
||||
window.legacy_gbk_check.setChecked(False)
|
||||
assert window.options().legacy_gbk is False
|
||||
|
||||
|
||||
def test_recommended_constructor_profiles_respect_disabled_legacy_gbk_override(qtbot, tmp_path):
|
||||
window = MainWindow(root=tmp_path, font_mapping="arial", print_theme="high_contrast", legacy_gbk=False)
|
||||
qtbot.addWidget(window)
|
||||
window.show()
|
||||
assert not window.legacy_gbk_check.isChecked()
|
||||
assert window.options().legacy_gbk is False
|
||||
assert window.options().color == 4
|
||||
assert "不自动修复编码" in window.font_mapping_combo.toolTip()
|
||||
|
||||
|
||||
def test_reference_palette_is_recommended_and_font_repair_is_independent(qtbot, tmp_path):
|
||||
window = MainWindow(root=tmp_path);qtbot.addWidget(window);window.show()
|
||||
assert window.print_theme_combo.currentText() == "工程参考配色(推荐)"
|
||||
explanation = window.print_theme_combo.toolTip()
|
||||
for detail in ("红色", "青绿色", "原生线宽", "界面", "字体", "子进程"):
|
||||
assert detail in explanation
|
||||
window.legacy_gbk_check.setChecked(False)
|
||||
assert window.options().print_theme == "reference"
|
||||
assert window.options().color == 4
|
||||
assert not window.options().legacy_gbk
|
||||
assert "子进程" in window.font_mapping_combo.toolTip()
|
||||
|
||||
|
||||
def test_direct_mode_discloses_native_database_write_risk(qtbot, tmp_path):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
assert not hasattr(window, "source_warning_label")
|
||||
text = window.strict_source_check.toolTip()
|
||||
for detail in ("原生引擎", "数据库", "待核验", "不发布"):
|
||||
assert detail in text
|
||||
|
||||
|
||||
def test_heading_has_no_engine_status_badge(qtbot, tmp_path):
|
||||
window = make_window(qtbot, tmp_path)
|
||||
assert not hasattr(window, "environment_label")
|
||||
assert not window.findChildren(QLabel, "badge")
|
||||
assert not any("已找到 Mentor" in label.text() for label in window.findChildren(QLabel))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("kind", ["scan", "batch"])
|
||||
def test_busy_queue_can_scroll_but_cannot_change_selection(qtbot, project_factory, tmp_path, kind):
|
||||
for number in range(45):
|
||||
project_factory(f"queue-{number:02d}")
|
||||
window = make_window(qtbot, tmp_path)
|
||||
window.scan_projects()
|
||||
qtbot.waitUntil(lambda: window.table.rowCount() == 45 and not window.busy, timeout=10000)
|
||||
scrollbar = window.table.verticalScrollBar()
|
||||
qtbot.waitUntil(lambda: scrollbar.maximum() > 0)
|
||||
before = [window.table.item(row, 0).checkState() for row in range(45)]
|
||||
window._set_busy(True, kind)
|
||||
try:
|
||||
assert window.table.isEnabled()
|
||||
assert scrollbar.isEnabled()
|
||||
assert not window.select_all_button.isEnabled()
|
||||
assert not window.clear_button.isEnabled()
|
||||
assert not window.select_failed_button.isEnabled()
|
||||
assert all(not (window.table.item(row, 0).flags() & Qt.ItemIsUserCheckable) for row in range(45))
|
||||
scrollbar.setFocus()
|
||||
qtbot.keyClick(scrollbar, Qt.Key_End)
|
||||
assert scrollbar.value() == scrollbar.maximum()
|
||||
qtbot.keyClick(scrollbar, Qt.Key_Home)
|
||||
assert scrollbar.value() == scrollbar.minimum()
|
||||
window.table.setCurrentCell(0, 0)
|
||||
rect = window.table.visualItemRect(window.table.item(0, 0))
|
||||
qtbot.mouseClick(window.table.viewport(), Qt.LeftButton, pos=rect.center())
|
||||
qtbot.keyClick(window.table, Qt.Key_Space)
|
||||
assert [window.table.item(row, 0).checkState() for row in range(45)] == before
|
||||
finally:
|
||||
window._set_busy(False, kind)
|
||||
assert all(window.table.item(row, 0).flags() & Qt.ItemIsUserCheckable for row in range(45))
|
||||
window.table.setCurrentCell(0, 0)
|
||||
qtbot.keyClick(window.table, Qt.Key_Space)
|
||||
assert window.table.item(0, 0).checkState() == Qt.Unchecked
|
||||
|
||||
|
||||
def test_running_worker_keeps_queue_browsable_and_shows_direct_mode(qtbot, project_factory, tmp_path):
|
||||
for number in range(30):
|
||||
project_factory(f"active-{number:02d}")
|
||||
started = threading.Event()
|
||||
def waiting(args, cwd, log_dir, cancel, timeout, on_event=None, *, env=None):
|
||||
started.set()
|
||||
if cancel.wait(30):
|
||||
raise InterruptedError("任务已停止")
|
||||
raise TimeoutError("test worker did not receive stop")
|
||||
window = make_window(qtbot, tmp_path, lambda engine, runs: Exporter(engine, runs, runner=waiting))
|
||||
engine = tmp_path / "sch2pdf.exe"
|
||||
engine.write_bytes(b"fake")
|
||||
window.engine_edit.setText(str(engine))
|
||||
window.scan_projects()
|
||||
qtbot.waitUntil(lambda: window.table.rowCount() == 30 and not window.busy, timeout=10000)
|
||||
window.start_export()
|
||||
try:
|
||||
qtbot.waitUntil(started.is_set, timeout=10000)
|
||||
assert window.busy and window.table.isEnabled()
|
||||
scrollbar = window.table.verticalScrollBar()
|
||||
scrollbar.setFocus()
|
||||
qtbot.keyClick(scrollbar, Qt.Key_End)
|
||||
assert scrollbar.maximum() > 0 and scrollbar.value() == scrollbar.maximum()
|
||||
assert "直接" in window.status_label.text()
|
||||
assert "副本" not in window.status_label.text()
|
||||
assert "副本" not in window.table.item(0, 4).text()
|
||||
assert "副本" not in window.log.placeholderText()
|
||||
finally:
|
||||
window.stop_export()
|
||||
qtbot.waitUntil(lambda: not window.busy, timeout=10000)
|
||||
assert window.table.item(0, 0).flags() & Qt.ItemIsUserCheckable
|
||||
|
||||
|
||||
def test_native_update_warning_is_success_not_uncertain_in_ui(qtbot,project_factory,tmp_path):
|
||||
project_factory();window=make_window(qtbot,tmp_path);window.scan_projects()
|
||||
qtbot.waitUntil(lambda:window.table.rowCount()==1 and not window.busy,timeout=10000)
|
||||
result=ExportResult(project='board',status='success',message='PDF valid; native database updated, not read-only',pages=1,warnings=('native update',))
|
||||
window._item_result(0,result)
|
||||
assert window.table.item(0,3).text()=='成功(有提示)'
|
||||
assert window.table.columnWidth(3) >= 110
|
||||
assert window.table.item(0,3).foreground().color().name()=='#d97706'
|
||||
assert '1 页' in window.table.item(0,4).text()
|
||||
assert 'native database' in window.table.item(0,4).toolTip()
|
||||
|
||||
|
||||
def test_strict_source_check_is_optional_and_locks_during_export(qtbot,tmp_path):
|
||||
window=make_window(qtbot,tmp_path)
|
||||
assert not window.strict_source_check.isChecked() and not window.options().strict_source
|
||||
assert '不阻止' in window.strict_source_check.toolTip()
|
||||
window.strict_source_check.setChecked(True)
|
||||
assert window.options().strict_source and '严格' in window.strict_source_check.toolTip()
|
||||
window._set_busy(True)
|
||||
assert not window.strict_source_check.isEnabled()
|
||||
window._set_busy(False)
|
||||
assert window.strict_source_check.isEnabled()
|
||||
|
||||
|
||||
def test_batch_native_update_warnings_publish_and_count_as_success(qtbot,project_factory,tmp_path):
|
||||
project_factory('one');project_factory('two')
|
||||
def updating(args,cwd,logs,cancel,timeout,on_event=None, *, env=None):
|
||||
rc=runner(args,cwd,logs,cancel,timeout,on_event)
|
||||
(Path(cwd)/'database/icdb.dat').write_bytes(b'native update')
|
||||
return rc
|
||||
window=make_window(qtbot,tmp_path,lambda engine,runs:Exporter(engine,runs,runner=updating))
|
||||
engine=tmp_path/'sch2pdf.exe';engine.write_bytes(b'fake');window.engine_edit.setText(str(engine))
|
||||
window.scan_projects();qtbot.waitUntil(lambda:window.table.rowCount()==2 and not window.busy,timeout=10000)
|
||||
window.start_export();qtbot.waitUntil(lambda:not window.busy,timeout=10000)
|
||||
assert [window.table.item(row,3).text() for row in range(2)]==['成功(有提示)']*2
|
||||
assert '成功 2' in window.status_label.text() and '有提示 2' in window.status_label.text()
|
||||
assert all(Path(r.output).is_file() and r.warnings for r in window.worker.results)
|
||||
Reference in new issue
Block a user