Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/escpos/printer/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def _raw(self, msg: bytes) -> None:
"""
self._output_list.append(msg)

def _read(self) -> bytes:
"""Read the last byte of data and return it to the caller."""
if not self._output_list:
return b""
return bytes([self._output_list[-1][-1]])

@property
def output(self) -> bytes:
"""Get the data that was sent to this printer."""
Expand Down
8 changes: 0 additions & 8 deletions test/test_functions/test_function_dummy_clear.py

This file was deleted.

42 changes: 42 additions & 0 deletions test/test_printers/test_printer_dummy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""tests for the Dummy printer

:author: Benito López and the python-escpos developers
:organization: `python-escpos <https://github.com/python-escpos>`_
:copyright: Copyright (c) 2025 `python-escpos <https://github.com/python-escpos>`_
:license: MIT
"""


def test_clear(driver) -> None:
"""
GIVEN a dummy printer object
WHEN clear method is called
THEN check the return value is the expected
"""
driver.text("Hello")
driver.clear()
assert driver.output == b""


def test_read_no_output(driver) -> None:
"""
GIVEN a dummy printer object with no output data
WHEN reading the last byte of data
THEN check the return value is the expected
"""
driver.clear()
assert driver._read() == b""


def test_read(driver) -> None:
"""
GIVEN a dummy printer object
WHEN reading the last byte of data
THEN check the return value is the expected
"""
driver._raw(b"\x10\x04\x01") # RT_STATUS_ONLINE
assert driver._read() == b"\x01"
driver._raw(b"\x12") # Simulate an 'is online' response
assert driver._read() == b"\x12"