69753e35f9
- Implement synchronous offscreen wafer map PNG rendering and CSV summary. - Add "Batch Export" button to file browser sidebar. - Adjust trend pane bottom spacer to align with About button when visible. - Fix type check errors and add pytest coverage for batch export.
125 lines
3.9 KiB
Python
125 lines
3.9 KiB
Python
"""Tests for src/pygui/backend/visualization/wafer_map_item.py."""
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
|
|
# Use the session-scoped qapp fixture from conftest.py so Qt Property/Signal
|
|
# descriptors work properly.
|
|
pytestmark = pytest.mark.usefixtures("qapp")
|
|
|
|
|
|
def test_export_image_empty_path():
|
|
"""export_image returns False for empty/None path."""
|
|
from pygui.backend.visualization.wafer_map_item import WaferMapItem
|
|
|
|
item = WaferMapItem()
|
|
assert item.export_image("") is False
|
|
assert item.export_image(None) is False
|
|
|
|
|
|
def test_export_image_zero_size_item_fails():
|
|
"""export_image returns False when the item has no geometry to render."""
|
|
from pygui.backend.visualization.wafer_map_item import WaferMapItem
|
|
|
|
item = WaferMapItem()
|
|
assert item.export_image("/tmp/test_wafer.png") is False
|
|
|
|
|
|
def test_export_image_unwritable_path_fails(tmp_path):
|
|
"""export_image returns False when the target directory doesn't exist."""
|
|
from pygui.backend.visualization.wafer_map_item import WaferMapItem
|
|
|
|
item = WaferMapItem()
|
|
item.setWidth(100)
|
|
item.setHeight(100)
|
|
item.values = [10.0, 20.0, 30.0]
|
|
assert item.export_image(str(tmp_path / "no_such_dir" / "wafer.png")) is False
|
|
|
|
|
|
def test_thickness_properties():
|
|
"""Thickness data properties exist with correct defaults."""
|
|
from pygui.backend.visualization.wafer_map_item import WaferMapItem
|
|
|
|
item = WaferMapItem()
|
|
|
|
assert item._thickness_data == []
|
|
assert item._show_thickness is False
|
|
|
|
|
|
def test_thickness_setter_updates_data():
|
|
"""Setting thicknessData updates _thickness_data."""
|
|
from pygui.backend.visualization.wafer_map_item import WaferMapItem
|
|
|
|
item = WaferMapItem()
|
|
item._rebuild_thickness = MagicMock()
|
|
|
|
item.thicknessData = [1.0, 2.0, 3.0]
|
|
|
|
assert item._thickness_data == [1.0, 2.0, 3.0]
|
|
assert item._rebuild_thickness.called
|
|
|
|
|
|
def test_show_thickness_setter():
|
|
"""Setting showThickness updates _show_thickness."""
|
|
from pygui.backend.visualization.wafer_map_item import WaferMapItem
|
|
|
|
item = WaferMapItem()
|
|
assert item._show_thickness is False
|
|
|
|
item.showThickness = True
|
|
assert item._show_thickness is True
|
|
|
|
|
|
def test_export_image_writes_real_png_headless(tmp_path):
|
|
"""export_image must produce an actual decodable image file without a
|
|
QQuickWindow — the button was silently failing because grabToImage()
|
|
resolves asynchronously and never completes headless/immediately."""
|
|
from PySide6.QtGui import QImage
|
|
|
|
from pygui.backend.visualization.wafer_map_item import WaferMapItem
|
|
|
|
item = WaferMapItem()
|
|
item.setWidth(200)
|
|
item.setHeight(200)
|
|
item.values = [10.0, 20.0, 30.0]
|
|
out = tmp_path / "wafer.png"
|
|
|
|
assert item.export_image(str(out)) is True
|
|
assert out.exists()
|
|
loaded = QImage(str(out))
|
|
assert not loaded.isNull()
|
|
assert loaded.width() == 200
|
|
|
|
|
|
def test_export_image_includes_metrics_footer(tmp_path):
|
|
"""With sensor values loaded, the export gains a footer strip below the
|
|
map carrying the metric readouts (sensors / min / max / avg)."""
|
|
from PySide6.QtGui import QImage
|
|
|
|
from pygui.backend.visualization.wafer_map_item import WaferMapItem
|
|
|
|
item = WaferMapItem()
|
|
item.setWidth(200)
|
|
item.setHeight(200)
|
|
item.values = [10.0, 20.0, 30.0]
|
|
out = tmp_path / "wafer.png"
|
|
|
|
assert item.export_image(str(out)) is True
|
|
loaded = QImage(str(out))
|
|
assert loaded.height() > 200 # footer strip appended
|
|
# footer is painted opaque (dark bg), not transparent
|
|
assert loaded.pixelColor(5, loaded.height() - 5).alpha() == 255
|
|
|
|
|
|
def test_export_image_no_data_fails(tmp_path):
|
|
"""No file loaded / no stream played -> nothing meaningful to export."""
|
|
from pygui.backend.visualization.wafer_map_item import WaferMapItem
|
|
|
|
item = WaferMapItem()
|
|
item.setWidth(200)
|
|
item.setHeight(200)
|
|
out = tmp_path / "wafer.png"
|
|
|
|
assert item.export_image(str(out)) is False
|
|
assert not out.exists()
|