Skip to content

Commit 24d1bc1

Browse files
committed
chore: fix ruff lint + format issues in modified files
1 parent 236907a commit 24d1bc1

File tree

8 files changed

+91
-80
lines changed

8 files changed

+91
-80
lines changed

tests/test_cli.py

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Tests for the zebra_day CLI commands.
33
"""
44

5+
import http.client
6+
import socket
57
from unittest.mock import MagicMock, patch
68

79
from typer.testing import CliRunner
@@ -180,10 +182,21 @@ def _fake_probe(ip_stub="192.168.1", progress_callback=None, scan_http_port=None
180182
"serial": p.get("serial", "Unknown"),
181183
}
182184
if progress_callback:
183-
progress_callback({"kind": "found", "ip": ip, "model": p.get("model", "Unknown"), "serial": p.get("serial", "Unknown")})
184-
progress_callback({"kind": "checked", "ip": ip, "checked": idx + 1, "total": 255, "open": True})
185+
progress_callback(
186+
{
187+
"kind": "found",
188+
"ip": ip,
189+
"model": p.get("model", "Unknown"),
190+
"serial": p.get("serial", "Unknown"),
191+
}
192+
)
193+
progress_callback(
194+
{"kind": "checked", "ip": ip, "checked": idx + 1, "total": 255, "open": True}
195+
)
185196
if progress_callback:
186-
progress_callback({"kind": "done", "cancelled": False, "checked": len(found_printers), "total": 255})
197+
progress_callback(
198+
{"kind": "done", "cancelled": False, "checked": len(found_printers), "total": 255}
199+
)
187200

188201
mock_zp.probe_zebra_printers_add_to_printers_json = _fake_probe
189202
return mock_zp
@@ -287,7 +300,6 @@ def test_printer_scan_rejects_trailing_dot_short_flag(self):
287300
assert "trailing dot" in result.output
288301

289302

290-
291303
# ---------------------------------------------------------------------------
292304
# zday man — interactive documentation browser
293305
# ---------------------------------------------------------------------------
@@ -397,7 +409,7 @@ class TestCLIManGracefulDegradation:
397409

398410
def test_missing_file_shows_warning(self):
399411
"""A topic pointing to a missing file shows a warning, not a crash."""
400-
from zebra_day.cli.man import TOPICS, Topic, TopicSource, _get_topic_content
412+
from zebra_day.cli.man import Topic, TopicSource, _get_topic_content
401413

402414
fake_topic = Topic(
403415
name="Missing",
@@ -409,7 +421,7 @@ def test_missing_file_shows_warning(self):
409421

410422
def test_missing_section_shows_warning(self):
411423
"""A topic with a bad heading shows a warning, not a crash."""
412-
from zebra_day.cli.man import TOPICS, Topic, TopicSource, _get_topic_content
424+
from zebra_day.cli.man import Topic, TopicSource, _get_topic_content
413425

414426
fake_topic = Topic(
415427
name="BadSection",
@@ -420,15 +432,10 @@ def test_missing_section_shows_warning(self):
420432
assert "not found" in content.lower()
421433

422434

423-
424435
# =====================================================================
425436
# Simulator tests
426437
# =====================================================================
427438

428-
import socket
429-
import http.client
430-
import time
431-
432439

433440
class TestSimulatorCore:
434441
"""Tests for the simulator module (non-CLI)."""
@@ -536,11 +543,13 @@ def test_http_discovery_page(self):
536543

537544
def test_cmd_mgr_integration(self):
538545
"""cmd_mgr.ZebraPrinter can query the simulator and parse responses."""
539-
from zebra_day.simulator import PrinterProfile, SimulatedPrinter
540546
from zebra_day.cmd_mgr import ZebraPrinter
547+
from zebra_day.simulator import PrinterProfile, SimulatedPrinter
541548

542549
profile = PrinterProfile(
543-
model="ZT411-203dpi ZPL", serial="INTEG001", firmware="V99.0.0",
550+
model="ZT411-203dpi ZPL",
551+
serial="INTEG001",
552+
firmware="V99.0.0",
544553
label_count=500,
545554
)
546555
printer = SimulatedPrinter("127.0.0.1", zpl_port=19206, http_port=18206, profile=profile)
@@ -598,7 +607,9 @@ def test_simulator_list_empty(self):
598607

599608
def test_simulator_stop_nonexistent(self):
600609
"""simulator stop on non-running simulator doesn't crash."""
601-
result = runner.invoke(app, ["simulator", "stop", "--host", "127.0.0.1", "--zpl-port", "19999"])
610+
result = runner.invoke(
611+
app, ["simulator", "stop", "--host", "127.0.0.1", "--zpl-port", "19999"]
612+
)
602613
assert result.exit_code == 0
603614

604615

@@ -612,7 +623,9 @@ def test_start_and_list(self):
612623
mgr = SimulatorManager()
613624
try:
614625
mgr.start_printer(
615-
host="127.0.0.1", zpl_port=19210, http_port=18210,
626+
host="127.0.0.1",
627+
zpl_port=19210,
628+
http_port=18210,
616629
profile=PrinterProfile(model="ZD420-203dpi ZPL", serial="MGR001"),
617630
)
618631
printers = mgr.list_printers()
@@ -626,6 +639,7 @@ def test_start_and_list(self):
626639
def test_start_duplicate_raises(self):
627640
"""Starting a printer on same address raises RuntimeError."""
628641
import pytest
642+
629643
from zebra_day.simulator import SimulatorManager
630644

631645
mgr = SimulatorManager()
@@ -649,17 +663,21 @@ def test_stop_all(self):
649663

650664
def test_multiple_printers(self):
651665
"""Multiple simulators can run simultaneously with different responses."""
652-
from zebra_day.simulator import PrinterProfile, SimulatorManager
653666
from zebra_day.cmd_mgr import ZebraPrinter
667+
from zebra_day.simulator import PrinterProfile, SimulatorManager
654668

655669
mgr = SimulatorManager()
656670
try:
657671
mgr.start_printer(
658-
host="127.0.0.1", zpl_port=19214, http_port=18214,
672+
host="127.0.0.1",
673+
zpl_port=19214,
674+
http_port=18214,
659675
profile=PrinterProfile(model="ZD620-203dpi ZPL", serial="FLEET1"),
660676
)
661677
mgr.start_printer(
662-
host="127.0.0.1", zpl_port=19215, http_port=18215,
678+
host="127.0.0.1",
679+
zpl_port=19215,
680+
http_port=18215,
663681
profile=PrinterProfile(model="ZT411-300dpi ZPL", serial="FLEET2"),
664682
)
665683
zp1 = ZebraPrinter("127.0.0.1", port=19214)
@@ -707,8 +725,9 @@ def test_scan_finds_printer_via_zpl(self):
707725
"""Default scan (no scan_http_port) discovers printer via ZPL port 9100."""
708726
import threading
709727
from unittest.mock import patch as _patch
710-
from zebra_day.simulator import PrinterProfile, SimulatedPrinter
728+
711729
import zebra_day.print_mgr as zdpm
730+
from zebra_day.simulator import PrinterProfile, SimulatedPrinter
712731

713732
profile = PrinterProfile(model="ZD620-203dpi ZPL", serial="SCANTEST1")
714733
printer = SimulatedPrinter("127.0.0.1", zpl_port=19220, http_port=18220, profile=profile)
@@ -748,8 +767,9 @@ def test_scan_http_fallback(self):
748767
"""scan_http_port enables HTTP-based discovery when ZPL fails."""
749768
import threading
750769
from unittest.mock import patch as _patch
751-
from zebra_day.simulator import PrinterProfile, SimulatedPrinter
770+
752771
import zebra_day.print_mgr as zdpm
772+
from zebra_day.simulator import PrinterProfile, SimulatedPrinter
753773

754774
profile = PrinterProfile(model="ZT411-300dpi ZPL", serial="HTTPFB1")
755775
printer = SimulatedPrinter("127.0.0.1", zpl_port=19221, http_port=18221, profile=profile)
@@ -789,8 +809,9 @@ def test_scan_no_http_port_skips_http(self):
789809
"""Without scan_http_port, HTTP is not attempted (backward compat)."""
790810
import threading
791811
from unittest.mock import patch as _patch
792-
from zebra_day.simulator import PrinterProfile, SimulatedPrinter
812+
793813
import zebra_day.print_mgr as zdpm
814+
from zebra_day.simulator import PrinterProfile, SimulatedPrinter
794815

795816
profile = PrinterProfile(model="ZD420-203dpi ZPL", serial="NOHTTP1")
796817
printer = SimulatedPrinter("127.0.0.1", zpl_port=19222, http_port=18222, profile=profile)
@@ -817,7 +838,9 @@ def _cb(evt):
817838
)
818839

819840
lab_printers = zp.printers.get("labs", {}).get("nohttp-test", {}).get("printers", {})
820-
found_any = [ip for ip, p in lab_printers.items() if p.get("model") == "ZD420-203dpi ZPL"]
841+
found_any = [
842+
ip for ip, p in lab_printers.items() if p.get("model") == "ZD420-203dpi ZPL"
843+
]
821844
assert len(found_any) >= 1
822845
p = lab_printers[found_any[0]]
823846
assert "zpl" in p.get("notes", "").lower()

zebra_day/cli/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import typer
88
import yaml
9-
109
from cli_core_yo.app import create_app
1110
from cli_core_yo.runtime import _reset, initialize
1211
from cli_core_yo.spec import CliSpec, ConfigSpec, PluginSpec, XdgSpec

zebra_day/cli/printer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import annotations
44

5-
import json
65
import socket
76
from typing import TYPE_CHECKING
87

zebra_day/cli/root_commands.py

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ def _status_callback() -> None:
6565
if hasattr(zp, "printers") and "labs" in zp.printers:
6666
labs = list(zp.printers["labs"].keys())
6767
status_data["printers"]["labs"] = labs
68-
total_printers = sum(
69-
len(list(zp.printers["labs"][lab].keys())) for lab in labs
70-
)
68+
total_printers = sum(len(list(zp.printers["labs"][lab].keys())) for lab in labs)
7169
status_data["printers"]["configured"] = total_printers
7270
except Exception:
7371
pass
@@ -79,10 +77,7 @@ def _status_callback() -> None:
7977
# Human-readable output
8078
output.heading("Service Status")
8179
if status_data["gui_server"]["running"]:
82-
output.success(
83-
f"GUI Server: Running"
84-
f" (PID {status_data['gui_server']['pid']})"
85-
)
80+
output.success(f"GUI Server: Running (PID {status_data['gui_server']['pid']})")
8681
output.detail(f"URL: {status_data['gui_server']['url']}")
8782
else:
8883
output.detail("GUI Server: Not running")
@@ -91,9 +86,7 @@ def _status_callback() -> None:
9186
if status_data["config"]["exists"]:
9287
output.success("Config: Loaded")
9388
output.detail(f"Printers: {status_data['printers']['configured']}")
94-
output.detail(
95-
f"Labs: {', '.join(status_data['printers']['labs']) or 'none'}"
96-
)
89+
output.detail(f"Labs: {', '.join(status_data['printers']['labs']) or 'none'}")
9790
else:
9891
output.warning("Config: Not found")
9992
output.detail("Run 'zday bootstrap' to initialize")
@@ -103,9 +96,7 @@ def _bootstrap_callback(
10396
ip_stub: str | None = typer.Option(
10497
None, "--ip-stub", "-i", help="IP stub for printer scan (e.g., 192.168.1)"
10598
),
106-
skip_scan: bool = typer.Option(
107-
False, "--skip-scan", "-s", help="Skip printer network scan"
108-
),
99+
skip_scan: bool = typer.Option(False, "--skip-scan", "-s", help="Skip printer network scan"),
109100
silent_scan: bool = typer.Option(
110101
False, "--silent-scan", help="Suppress per-IP scan output (show summary only)"
111102
),
@@ -169,17 +160,12 @@ def _scan_progress(event: dict) -> None:
169160
checked = event.get("checked", 0)
170161
total = event.get("total", 255)
171162
ip_addr = event.get("ip", "")
172-
output.print_text(
173-
f" [{checked + 1}/{total}] Probing {ip_addr}..."
174-
)
163+
output.print_text(f" [{checked + 1}/{total}] Probing {ip_addr}...")
175164
elif kind == "found":
176165
ip_addr = event.get("ip", "")
177166
model = event.get("model", "Unknown")
178167
serial = event.get("serial", "Unknown")
179-
output.success(
180-
f"Found printer at {ip_addr}"
181-
f" model={model} serial={serial}"
182-
)
168+
output.success(f"Found printer at {ip_addr} model={model} serial={serial}")
183169
elif kind == "done":
184170
checked = event.get("checked", 0)
185171
total = event.get("total", 255)
@@ -218,24 +204,19 @@ def _scan_progress(event: dict) -> None:
218204
if not mkcert.is_mkcert_installed():
219205
output.warning("mkcert not installed")
220206
output.detail(
221-
"Install with: brew install mkcert (macOS) or "
222-
"sudo apt install mkcert (Ubuntu)"
207+
"Install with: brew install mkcert (macOS) or sudo apt install mkcert (Ubuntu)"
223208
)
224209
elif not mkcert.is_ca_installed():
225210
output.warning("mkcert CA not installed")
226-
output.detail(
227-
"Run: mkcert -install (one-time, requires password)"
228-
)
211+
output.detail("Run: mkcert -install (one-time, requires password)")
229212
elif mkcert.certificates_exist():
230213
output.success(f"Certificates exist: {mkcert.CERT_FILE}")
231214
certs_generated = True
232215
cert_path_str = str(mkcert.CERT_FILE)
233216
else:
234217
output.detail("Generating certificates...")
235218
if mkcert.generate_certificates():
236-
output.success(
237-
f"Certificates generated: {mkcert.CERT_FILE}"
238-
)
219+
output.success(f"Certificates generated: {mkcert.CERT_FILE}")
239220
certs_generated = True
240221
cert_path_str = str(mkcert.CERT_FILE)
241222
else:
@@ -260,4 +241,3 @@ def _scan_progress(event: dict) -> None:
260241
output.detail("zday gui start Start the web UI")
261242
output.detail("zday printer list Show configured printers")
262243
output.detail("zday info Show configuration details")
263-

zebra_day/cli/simulator.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import signal
6-
import sys
76
import time
87
from typing import TYPE_CHECKING
98

@@ -61,9 +60,7 @@ def sim_start(
6160

6261
mgr = _get_manager()
6362
try:
64-
printer = mgr.start_printer(
65-
host=host, zpl_port=zpl_port, http_port=http_port, profile=profile
66-
)
63+
mgr.start_printer(host=host, zpl_port=zpl_port, http_port=http_port, profile=profile)
6764
except RuntimeError as exc:
6865
output.error(str(exc))
6966
raise typer.Exit(1) from None
@@ -128,4 +125,3 @@ def sim_list() -> None:
128125
def register(registry: CommandRegistry, spec: CliSpec) -> None:
129126
"""cli-core-yo plugin: register the simulator command group."""
130127
registry.add_typer_app(None, sim_app, "simulator", "Mock Zebra printer simulator")
131-

0 commit comments

Comments
 (0)