22Tests for the zebra_day CLI commands.
33"""
44
5+ import http .client
6+ import socket
57from unittest .mock import MagicMock , patch
68
79from 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
433440class 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 ()
0 commit comments