fix: lazy-import tkinter to fix CI on headless Linux
Some checks failed
Lint & Test / test (push) Failing after 2m16s
Some checks failed
Lint & Test / test (push) Failing after 2m16s
screen_overlay.py imported tkinter at module level, which cascaded through processor_manager → every test touching the app on CI where libtk8.6.so is unavailable. Move to TYPE_CHECKING + runtime lazy import so the overlay module loads cleanly on headless systems. Also fix test_processor_manager.py to use ProcessorDependencies().
This commit is contained in:
@@ -1,11 +1,15 @@
|
|||||||
"""Screen overlay visualization for LED calibration testing."""
|
"""Screen overlay visualization for LED calibration testing."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import colorsys
|
import colorsys
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
import tkinter as tk
|
from typing import TYPE_CHECKING, Dict, List, Optional
|
||||||
from typing import Dict, List, Optional
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
import tkinter as tk
|
||||||
|
|
||||||
from wled_controller.core.capture.calibration import CalibrationConfig
|
from wled_controller.core.capture.calibration import CalibrationConfig
|
||||||
from wled_controller.core.capture_engines.base import DisplayInfo
|
from wled_controller.core.capture_engines.base import DisplayInfo
|
||||||
@@ -44,6 +48,8 @@ class OverlayWindow:
|
|||||||
|
|
||||||
def start(self, root: tk.Tk) -> None:
|
def start(self, root: tk.Tk) -> None:
|
||||||
"""Create and show the overlay Toplevel (runs in Tk thread)."""
|
"""Create and show the overlay Toplevel (runs in Tk thread)."""
|
||||||
|
import tkinter as tk # lazy import — tkinter unavailable in headless CI
|
||||||
|
|
||||||
self._window = tk.Toplevel(root)
|
self._window = tk.Toplevel(root)
|
||||||
self._setup_window()
|
self._setup_window()
|
||||||
self._draw_visualization()
|
self._draw_visualization()
|
||||||
@@ -74,6 +80,8 @@ class OverlayWindow:
|
|||||||
win.overrideredirect(True)
|
win.overrideredirect(True)
|
||||||
win.attributes("-topmost", True)
|
win.attributes("-topmost", True)
|
||||||
|
|
||||||
|
import tkinter as tk
|
||||||
|
|
||||||
self._canvas = tk.Canvas(
|
self._canvas = tk.Canvas(
|
||||||
win,
|
win,
|
||||||
width=self.display_info.width,
|
width=self.display_info.width,
|
||||||
@@ -270,6 +278,8 @@ class OverlayManager:
|
|||||||
|
|
||||||
def _start_tk_thread(self) -> None:
|
def _start_tk_thread(self) -> None:
|
||||||
def _run():
|
def _run():
|
||||||
|
import tkinter as tk # lazy import — tkinter unavailable in headless CI
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._tk_root = tk.Tk()
|
self._tk_root = tk.Tk()
|
||||||
self._tk_root.withdraw() # invisible root — never shown
|
self._tk_root.withdraw() # invisible root — never shown
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from wled_controller.core.processing.processor_manager import ProcessorManager
|
from wled_controller.core.processing.processor_manager import ProcessorDependencies, ProcessorManager
|
||||||
from wled_controller.core.processing.processing_settings import ProcessingSettings
|
from wled_controller.core.processing.processing_settings import ProcessingSettings
|
||||||
from wled_controller.core.capture.calibration import create_default_calibration
|
from wled_controller.core.capture.calibration import create_default_calibration
|
||||||
|
|
||||||
@@ -33,12 +33,12 @@ def mock_wled_responses():
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def processor_manager():
|
def processor_manager():
|
||||||
"""Provide processor manager instance."""
|
"""Provide processor manager instance."""
|
||||||
return ProcessorManager()
|
return ProcessorManager(deps=ProcessorDependencies())
|
||||||
|
|
||||||
|
|
||||||
def test_processor_manager_init():
|
def test_processor_manager_init():
|
||||||
"""Test processor manager initialization."""
|
"""Test processor manager initialization."""
|
||||||
manager = ProcessorManager()
|
manager = ProcessorManager(deps=ProcessorDependencies())
|
||||||
assert manager is not None
|
assert manager is not None
|
||||||
assert manager.get_all_devices() == []
|
assert manager.get_all_devices() == []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user