2026-03-21 17:51:36 +01:00
|
|
|
"""Tests for brother_printer.display module - part 2 (network display)."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from io import StringIO
|
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
from python_pkg.brother_printer.data_classes import (
|
|
|
|
|
NetworkResult,
|
|
|
|
|
)
|
|
|
|
|
from python_pkg.brother_printer.display import (
|
|
|
|
|
_display_network_device_info,
|
|
|
|
|
display_network_results,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
MOD = "python_pkg.brother_printer.display"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestDisplayNetworkDeviceInfo:
|
|
|
|
|
def test_full_info(self) -> None:
|
|
|
|
|
result = NetworkResult(
|
|
|
|
|
ip="1.2.3.4",
|
|
|
|
|
product="HL-1110",
|
|
|
|
|
serial="SN1",
|
|
|
|
|
display="Ready",
|
|
|
|
|
page_count="500",
|
|
|
|
|
)
|
|
|
|
|
with patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
|
_display_network_device_info(result)
|
|
|
|
|
text = out.getvalue()
|
|
|
|
|
assert "HL-1110" in text
|
|
|
|
|
assert "1.2.3.4" in text
|
|
|
|
|
assert "SN1" in text
|
|
|
|
|
assert "500" in text
|
|
|
|
|
|
|
|
|
|
def test_no_serial(self) -> None:
|
|
|
|
|
result = NetworkResult(ip="1.2.3.4")
|
|
|
|
|
with patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
|
_display_network_device_info(result)
|
|
|
|
|
assert "Serial" not in out.getvalue()
|
|
|
|
|
|
|
|
|
|
def test_no_display(self) -> None:
|
|
|
|
|
result = NetworkResult(ip="1.2.3.4")
|
|
|
|
|
with patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
|
_display_network_device_info(result)
|
|
|
|
|
assert "Display" not in out.getvalue()
|
|
|
|
|
|
|
|
|
|
def test_non_digit_page_count(self) -> None:
|
|
|
|
|
result = NetworkResult(ip="1.2.3.4", page_count="abc")
|
|
|
|
|
with patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
|
_display_network_device_info(result)
|
|
|
|
|
assert "Pages" not in out.getvalue()
|
|
|
|
|
|
|
|
|
|
def test_no_page_count(self) -> None:
|
|
|
|
|
result = NetworkResult(ip="1.2.3.4", page_count="")
|
|
|
|
|
with patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
|
_display_network_device_info(result)
|
|
|
|
|
assert "Pages" not in out.getvalue()
|
|
|
|
|
|
|
|
|
|
def test_no_product(self) -> None:
|
|
|
|
|
result = NetworkResult(ip="1.2.3.4", product="")
|
|
|
|
|
with patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
|
_display_network_device_info(result)
|
|
|
|
|
assert "Unknown" in out.getvalue()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestDisplayNetworkResults:
|
|
|
|
|
@patch(f"{MOD}._display_supply_levels")
|
|
|
|
|
@patch(f"{MOD}._display_network_device_info")
|
|
|
|
|
@patch(f"{MOD}._display_report_header")
|
|
|
|
|
def test_normal(
|
|
|
|
|
self,
|
Reduce per-file-ignores by fixing lint violations across codebase
Fix ruff violations in ~15 source files and ~60+ test files to minimize
per-file-ignores in pyproject.toml. Remaining ignores are justified with
comments explaining why each suppression is necessary.
Source fixes: FBT003 (keyword args), S310 (URL validation), SLF001
(private access), T201 (print→logging), C901 (complexity), E501 (line
length), E402 (import order).
Test fixes: SIM117 (combined with), FBT (boolean args), PERF203 (try in
loop), S310/S607 (URLs/executables), E402/E501 (imports/lines), S108
(tmp paths), PLR0913 (too many args), ARG (unused args), ANN (type
annotations), RUF059 (unused unpacked vars), PT019 (fixture naming).
Remaining per-file-ignores (with justifications):
- Tests: ARG, D, PLC0415, PLR2004, S101, SLF001
- music_gen sources: PLC0415 (heavy ML lazy imports)
- moviepy_showcase: PLC0415 (circular dependency)
- generate_images: PLR0913 (matplotlib helpers need many params)
- praca_magisterska_video: E501, E402 (long paths, mpl.use)
2026-03-25 18:58:05 +01:00
|
|
|
h: MagicMock,
|
|
|
|
|
d: MagicMock,
|
|
|
|
|
s: MagicMock,
|
2026-03-21 17:51:36 +01:00
|
|
|
) -> None:
|
|
|
|
|
r = NetworkResult(ip="1.2.3.4")
|
|
|
|
|
with patch("sys.stdout", new_callable=StringIO) as out:
|
|
|
|
|
display_network_results(r)
|
|
|
|
|
assert "1.2.3.4" in out.getvalue()
|
|
|
|
|
|
|
|
|
|
def test_error(self) -> None:
|
|
|
|
|
r = NetworkResult(error="fail")
|
|
|
|
|
with (
|
|
|
|
|
patch("sys.stdout", new_callable=StringIO),
|
|
|
|
|
pytest.raises(SystemExit),
|
|
|
|
|
):
|
|
|
|
|
display_network_results(r)
|