Test the 'printers' property

This commit is contained in:
belono 2023-10-22 19:06:41 +02:00
parent 5019b88430
commit 3fb5ce27a1
3 changed files with 12 additions and 0 deletions

View File

@ -65,6 +65,7 @@ def test_open(cupsprinter, caplog, mocker):
mocker.patch("escpos.printer.CupsPrinter.printers", new={"test_printer": "Test"})
cupsprinter.printer_name = "test_printer"
assert cupsprinter.printer_name in cupsprinter.printers
with caplog.at_level(logging.INFO):
cupsprinter.open()

View File

@ -65,6 +65,7 @@ def test_open(lpprinter, caplog, mocker):
mocker.patch("escpos.printer.LP.printers", new={"test_printer": "Test"})
lpprinter.printer_name = "test_printer"
assert lpprinter.printer_name in lpprinter.printers
with caplog.at_level(logging.INFO):
lpprinter.open()

View File

@ -67,6 +67,10 @@ def test_open(win32rawprinter, caplog, mocker):
THEN check the success is logged and the device property is set
"""
mocker.patch("win32print.__init__")
mocker.patch("escpos.printer.Win32Raw.printers", new={"test_printer": "Test"})
win32rawprinter.printer_name = "test_printer"
assert win32rawprinter.printer_name in win32rawprinter.printers
with caplog.at_level(logging.INFO):
win32rawprinter.open()
@ -83,6 +87,9 @@ def test_close_on_reopen(win32rawprinter, mocker):
"""
mocker.patch("win32print.__init__")
spy = mocker.spy(win32rawprinter, "close")
mocker.patch("escpos.printer.Win32Raw.printers", new={"test_printer": "Test"})
win32rawprinter.printer_name = "test_printer"
win32rawprinter.open()
assert win32rawprinter._device
@ -98,6 +105,9 @@ def test_close(win32rawprinter, mocker, caplog):
THEN check the closing is logged and the device property is False
"""
mocker.patch("win32print.__init__")
mocker.patch("escpos.printer.Win32Raw.printers", new={"test_printer": "Test"})
win32rawprinter.printer_name = "test_printer"
win32rawprinter.open()
with caplog.at_level(logging.INFO):