From e2e52c98ed1ee91a805777e89587f8dc31287e16 Mon Sep 17 00:00:00 2001 From: belono Date: Wed, 8 Oct 2025 20:41:58 +0200 Subject: [PATCH 1/5] Implement _read() into the Dummy() connector --- src/escpos/printer/dummy.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/escpos/printer/dummy.py b/src/escpos/printer/dummy.py index a712016e..37c7ff62 100644 --- a/src/escpos/printer/dummy.py +++ b/src/escpos/printer/dummy.py @@ -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 self._output_list[-1] + @property def output(self) -> bytes: """Get the data that was sent to this printer.""" From f388f6ae43a330694a6eb50a4faf416843e7fe9e Mon Sep 17 00:00:00 2001 From: belono Date: Mon, 20 Oct 2025 16:08:16 +0200 Subject: [PATCH 2/5] Fix _read() return value --- src/escpos/printer/dummy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/escpos/printer/dummy.py b/src/escpos/printer/dummy.py index 37c7ff62..03746896 100644 --- a/src/escpos/printer/dummy.py +++ b/src/escpos/printer/dummy.py @@ -56,7 +56,7 @@ def _read(self) -> bytes: """Read the last byte of data and return it to the caller.""" if not self._output_list: return b"" - return self._output_list[-1] + return bytes([self._output_list[-1][-1]]) @property def output(self) -> bytes: From b7693d494327286f93bd9cd959073f3328f2bd44 Mon Sep 17 00:00:00 2001 From: belono Date: Mon, 20 Oct 2025 16:22:14 +0200 Subject: [PATCH 3/5] Add tests for the dummy printer to the tests battery --- test/test_printers/test_printer_dummy.py | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/test_printers/test_printer_dummy.py diff --git a/test/test_printers/test_printer_dummy.py b/test/test_printers/test_printer_dummy.py new file mode 100644 index 00000000..b13871cb --- /dev/null +++ b/test/test_printers/test_printer_dummy.py @@ -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 `_ +:copyright: Copyright (c) 2025 `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" From 82cdd9454a959a3f8440536e0c46112c592c9d4e Mon Sep 17 00:00:00 2001 From: belono Date: Mon, 20 Oct 2025 16:26:07 +0200 Subject: [PATCH 4/5] Remove test_function_dummy.py --- test/test_functions/test_function_dummy_clear.py | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 test/test_functions/test_function_dummy_clear.py diff --git a/test/test_functions/test_function_dummy_clear.py b/test/test_functions/test_function_dummy_clear.py deleted file mode 100644 index b6bdd7be..00000000 --- a/test/test_functions/test_function_dummy_clear.py +++ /dev/null @@ -1,8 +0,0 @@ -from escpos.printer import Dummy - - -def test_printer_dummy_clear() -> None: - printer = Dummy() - printer.text("Hello") - printer.clear() - assert printer.output == b"" From da86a284d00dc8264672153259f84737d8371f43 Mon Sep 17 00:00:00 2001 From: belono Date: Mon, 20 Oct 2025 16:34:33 +0200 Subject: [PATCH 5/5] Fix trailing whitespace --- test/test_printers/test_printer_dummy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_printers/test_printer_dummy.py b/test/test_printers/test_printer_dummy.py index b13871cb..8ded07b4 100644 --- a/test/test_printers/test_printer_dummy.py +++ b/test/test_printers/test_printer_dummy.py @@ -23,7 +23,7 @@ def test_clear(driver) -> None: def test_read_no_output(driver) -> None: """ GIVEN a dummy printer object with no output data - WHEN reading the last byte of data + WHEN reading the last byte of data THEN check the return value is the expected """ driver.clear()