mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 22:47:02 +01:00
a12e696 turned CI red two ways, both missed locally because the suite was
run for the brother_printer package alone while CI runs everything in a
random order.
The repo caps Python files at 500 lines and cups_service.py had reached
659. Rather than cut it arbitrarily, extract consumable life tracking -
page counters, replacement baselines, the scale migration, dropped-page
detection - into consumables.py. The seam is real: none of it depends on
CUPS service control, and cups_service needs only estimate_consumable_life
for its fallback query, so the dependency runs one way. The test files are
split along the same seams.
test_main_entry passed or failed depending on execution order: runpy warns
when the target module is already in sys.modules, a sibling test imports
it, and pytest is configured with filterwarnings=error. Drop the module
before running it so the test no longer depends on who ran first.
Structural only; no behaviour change. 692 tests, 100% branch coverage.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RG3eEn8rwZbcXaJrKJxdv8
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
"""Tests for brother_printer.cups_service module - part 4 (IPP queries)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from python_pkg.brother_printer.cups_service import (
|
|
_get_cups_ipp_status,
|
|
_parse_ipp_attributes,
|
|
)
|
|
|
|
MOD = "python_pkg.brother_printer.cups_service"
|
|
|
|
|
|
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") == {}
|