testsAndMisc/python_pkg/brother_printer/tests/test_cups_service_part4.py
Krzysztof kuhy Rudnicki 143dd9ff3d Split brother_printer CUPS fallback query out of cups_service
cups_service.py 406 -> 234. The IPP attribute queries, the CUPS
status-code mapping, find_cups_printer_name and query_usb_via_cups move
to _cups_fallback.py; cups_service keeps service control and raw USB
port status.

The seam is not the section header: test_cups_service_part2.py imports
_get_cups_economode and find_cups_printer_name together and patches
shutil once, so those two had to travel as a pair. test_cups_service.py,
the largest module, needs no edit.

usb_query.py reaches the fallback through a late import_module, so both
that string and the absolute patch target in test_usb_query.py moved
with it. 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:02:42 +02:00

47 lines
1.6 KiB
Python

"""Tests for brother_printer._cups_fallback module - part 4 (IPP queries)."""
from __future__ import annotations
import subprocess
from unittest.mock import MagicMock, patch
from python_pkg.brother_printer._cups_fallback import (
_get_cups_ipp_status,
_parse_ipp_attributes,
)
MOD = "python_pkg.brother_printer._cups_fallback"
class TestParseIppAttributes:
def test_parse(self) -> None:
output = " printer-state (enum) = idle\n printer-name (name) = Brother\n"
result = _parse_ipp_attributes(output)
assert result["printer-state"] == "idle"
assert result["printer-name"] == "Brother"
def test_no_match(self) -> None:
result = _parse_ipp_attributes("no attributes here\n")
assert result == {}
class TestGetCupsIppStatus:
@patch(f"{MOD}.shutil.which", return_value=None)
def test_no_ipptool(self, m: MagicMock) -> None:
assert _get_cups_ipp_status("Brother") == {}
@patch(f"{MOD}.subprocess.run")
@patch(f"{MOD}.shutil.which", return_value="/usr/bin/ipptool")
def test_success(self, w: MagicMock, mock_run: MagicMock) -> None:
mock_run.return_value = MagicMock(
stdout=" printer-state (enum) = idle\n",
)
result = _get_cups_ipp_status("Brother")
assert result["printer-state"] == "idle"
@patch(f"{MOD}.subprocess.run")
@patch(f"{MOD}.shutil.which", return_value="/usr/bin/ipptool")
def test_timeout(self, w: MagicMock, mock_run: MagicMock) -> None:
mock_run.side_effect = subprocess.TimeoutExpired("ipptool", 10)
assert _get_cups_ipp_status("Brother") == {}