From e9e4385117b7399eb147df165a12a6ae07fe529f Mon Sep 17 00:00:00 2001 From: Christoph Heuel Date: Thu, 23 Nov 2017 02:09:28 +0100 Subject: [PATCH 1/2] Add Function to Dummy Printer for Clearing Buffer * If you are using the dummy printer, you may want to use the printer again after sending the output to a physical printer. * This method empties the list of the output buffer --- src/escpos/printer.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/escpos/printer.py b/src/escpos/printer.py index e51eba0c..a652b98a 100644 --- a/src/escpos/printer.py +++ b/src/escpos/printer.py @@ -312,5 +312,13 @@ def output(self): """ Get the data that was sent to this printer """ return b''.join(self._output_list) + def clear(self): + """ Clear the buffer of the printer + + This method can be called if you send the contents to a physical printer + and want to use the Dummy printer for new output. + """ + del self._output_list[:] + def close(self): pass From 6bca277f52e454b7b74333448eac8ddfbdf1121f Mon Sep 17 00:00:00 2001 From: Christoph Heuel Date: Sat, 25 Nov 2017 02:31:50 +0100 Subject: [PATCH 2/2] Add Test Function for dummy.clear --- test/test_function_dummy_clear.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test/test_function_dummy_clear.py diff --git a/test/test_function_dummy_clear.py b/test/test_function_dummy_clear.py new file mode 100644 index 00000000..431eb9a4 --- /dev/null +++ b/test/test_function_dummy_clear.py @@ -0,0 +1,8 @@ +from nose.tools import assert_raises +from escpos.printer import Dummy + +def test_printer_dummy_clear(): + printer = Dummy() + printer.text("Hello") + printer.clear() + assert(printer.output == b'')