testsAndMisc/python_pkg/brother_printer/tests/test_cups_queue_part3.py
Krzysztof kuhy Rudnicki cf44e54215 Split brother_printer queue display and fix prompt out of cups_queue
cups_queue.py 424 -> 245. display_cups_queue_status, _offer_queue_fix,
the _dwj_* choices and the _handle_* dispatchers move to _queue_fix.py.

The _cups_* action primitives stay put: test_cups_queue.py patches
subprocess and time on cups_queue, and those primitives are their only
consumers, so moving them would have left subprocess.run unpatched and
free to restart the real CUPS service mid-suite. test_cups_queue.py
therefore needs no edit; only part2/part3 repoint their MOD.

Pass count is 402 before and after.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
2026-08-16 16:53:51 +02:00

77 lines
2.5 KiB
Python

"""Tests for brother_printer._queue_fix module - part 3 (display status)."""
from __future__ import annotations
from io import StringIO
from unittest.mock import MagicMock, patch
from python_pkg.brother_printer._queue_fix import (
display_cups_queue_status,
)
from python_pkg.brother_printer.data_classes import CUPSJob, CUPSQueueStatus
MOD = "python_pkg.brother_printer._queue_fix"
class TestDisplayCupsQueueStatus:
def test_no_printer(self) -> None:
queue = CUPSQueueStatus(printer_name="")
with patch("sys.stdout", new_callable=StringIO) as out:
display_cups_queue_status(queue)
assert out.getvalue() == ""
def test_all_ok(self) -> None:
queue = CUPSQueueStatus(
printer_name="B",
enabled=True,
jobs=[],
has_backend_errors=False,
)
with patch("sys.stdout", new_callable=StringIO) as out:
display_cups_queue_status(queue)
assert out.getvalue() == ""
@patch(f"{MOD}._offer_queue_fix")
def test_disabled(self, mock_fix: MagicMock) -> None:
queue = CUPSQueueStatus(
printer_name="B",
enabled=False,
reason="paused",
)
with patch("sys.stdout", new_callable=StringIO):
display_cups_queue_status(queue)
mock_fix.assert_called_once()
@patch(f"{MOD}._offer_queue_fix")
def test_with_jobs(self, mock_fix: MagicMock) -> None:
queue = CUPSQueueStatus(
printer_name="B",
enabled=True,
jobs=[CUPSJob("j1", "alice", "1024", "Mon")],
)
with patch("sys.stdout", new_callable=StringIO):
display_cups_queue_status(queue)
mock_fix.assert_called_once()
@patch(f"{MOD}._offer_queue_fix")
def test_backend_errors_only(self, mock_fix: MagicMock) -> None:
queue = CUPSQueueStatus(
printer_name="B",
enabled=True,
has_backend_errors=True,
)
with patch("sys.stdout", new_callable=StringIO):
display_cups_queue_status(queue)
mock_fix.assert_called_once()
@patch(f"{MOD}._offer_queue_fix")
def test_disabled_no_reason(self, mock_fix: MagicMock) -> None:
queue = CUPSQueueStatus(
printer_name="B",
enabled=False,
reason="",
)
with patch("sys.stdout", new_callable=StringIO):
display_cups_queue_status(queue)
mock_fix.assert_called_once()