import logging
import tkinter as tk
from target_simulator.utils import logger as tlogger


def test_queue_putter_and_emit(monkeypatch):
    qh = tlogger.QueuePuttingHandler(handler_queue=tlogger.Queue())
    rec = logging.LogRecord('test', logging.INFO, '', 0, 'msg', None, None)
    qh.emit(rec)
    # ensure record is queued
    assert not qh.handler_queue.empty()


def test_add_tkinter_handler_noop_when_not_active(monkeypatch):
    # Ensure logging system inactive
    tlogger._logging_system_active = False
    # Create dummy widget that is not considered a tk.Text
    class Dummy:
        def winfo_exists(self):
            return True

    # Should not raise
    tlogger.add_tkinter_handler(Dummy(), {})
