91 lines
2.7 KiB
Python
91 lines
2.7 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_valid_path():
|
|
"""export_image saves a PNG when grabToImage succeeds."""
|
|
from pygui.backend.visualization.wafer_map_item import WaferMapItem
|
|
|
|
item = WaferMapItem()
|
|
|
|
mock_image = MagicMock()
|
|
mock_result = MagicMock()
|
|
mock_result.image.return_value = mock_image
|
|
item.grabToImage = MagicMock(return_value=mock_result)
|
|
|
|
assert item.export_image("/tmp/test_wafer.png") is True
|
|
|
|
|
|
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_grab_fails():
|
|
"""export_image returns False when grabToImage raises."""
|
|
from pygui.backend.visualization.wafer_map_item import WaferMapItem
|
|
|
|
item = WaferMapItem()
|
|
item.grabToImage = MagicMock(side_effect=RuntimeError("grab failed"))
|
|
|
|
assert item.export_image("/tmp/test_wafer.png") is False
|
|
|
|
|
|
def test_export_image_save_fails():
|
|
"""export_image returns False when image.save raises."""
|
|
from pygui.backend.visualization.wafer_map_item import WaferMapItem
|
|
|
|
mock_image = MagicMock()
|
|
mock_image.save.side_effect = IOError("disk full")
|
|
mock_result = MagicMock()
|
|
mock_result.image.return_value = mock_image
|
|
|
|
item = WaferMapItem()
|
|
item.grabToImage = MagicMock(return_value=mock_result)
|
|
|
|
assert item.export_image("/tmp/test_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
|