mirror of
				https://github.com/python-escpos/python-escpos
				synced 2025-10-23 09:30:00 +00:00 
			
		
		
		
	Separate method open() and constructor, enhance consistency between connectors: Rework printer tests (#587)
* Add fixtures * Add test_printer_file.py * Remove old broken printer tests * Include a close_on_reopen test * Add test_printer_network.py * Add test_printer_serial.py * Add test_printer_usb.py * Add test_printer_lp.py * Add test_printer_cups.py * Add test_printer_win32raw.py * Test the 'printers' property * Fix conftest import formatting * Fix failing LP tests * Cancel close only if literal False|None _device * Fix win32raw failing tests (maybe) * Include win32raw close_on_reopen test * Include test _raw methods to win32raw * Replace general exceptions in win32raw * Replace wrong exception in cups * Include more tests to cups * Extend cups tests
This commit is contained in:
		@@ -172,9 +172,9 @@ class CupsPrinter(Escpos):
 | 
			
		||||
        self.pending_job = True
 | 
			
		||||
        try:
 | 
			
		||||
            self.tmpfile.write(msg)
 | 
			
		||||
        except ValueError:
 | 
			
		||||
        except TypeError:
 | 
			
		||||
            self.pending_job = False
 | 
			
		||||
            raise ValueError("Printer job not opened")
 | 
			
		||||
            raise TypeError("Bytes required. Printer job not opened")
 | 
			
		||||
 | 
			
		||||
    def send(self):
 | 
			
		||||
        """Send the print job to the printer."""
 | 
			
		||||
 
 | 
			
		||||
@@ -138,7 +138,7 @@ class Win32Raw(Escpos):
 | 
			
		||||
 | 
			
		||||
    def close(self) -> None:
 | 
			
		||||
        """Close connection to default printer."""
 | 
			
		||||
        if not self._device:
 | 
			
		||||
        if self._device is False or self._device is None:  # Literal False | None
 | 
			
		||||
            return
 | 
			
		||||
        logging.info("Closing Win32Raw connection to printer %s", self.printer_name)
 | 
			
		||||
        win32print.EndPagePrinter(self._device)
 | 
			
		||||
@@ -153,7 +153,7 @@ class Win32Raw(Escpos):
 | 
			
		||||
        :type msg: bytes
 | 
			
		||||
        """
 | 
			
		||||
        if self.printer_name is None:
 | 
			
		||||
            raise Exception("Printer not found")
 | 
			
		||||
            raise DeviceNotFoundError("Printer not found")
 | 
			
		||||
        if not self.device:
 | 
			
		||||
            raise Exception("Printer job not opened")
 | 
			
		||||
            raise DeviceNotFoundError("Printer job not opened")
 | 
			
		||||
        win32print.WritePrinter(self.device, msg)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user