testsAndMisc/python_pkg/brother_printer/tests/test_cups_queue_display.py
Krzysztof kuhy Rudnicki 65bc65c7e3 Split the brother_printer cups_queue test modules under the cap
test_cups_queue.py 458 -> 167, partitioned at class boundaries into
_actions (the four shell-out primitives) and _backend (health check and
error-log scanning). test_cups_queue_part2.py 278 -> 131, with the four
_handle_* dispatchers moving to _handlers.

No MOD changed: unlike the source splits, every patched name already
lives in the module each file names, so this is a pure partition. The
two part-numbered survivors are renamed for what they cover.

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 17:15:55 +02:00

77 lines
2.5 KiB
Python

"""Tests for brother_printer._queue_fix - the queue status display."""
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()