Feature/clear content in dummy printer (#271)

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.
This commit is contained in:
Christoph Heuel 2017-12-04 00:13:28 +01:00 committed by Patrick Kanzler
parent 01e28bbcf6
commit 26d72a69f0
2 changed files with 16 additions and 0 deletions

View File

@ -312,5 +312,13 @@ class Dummy(Escpos):
""" 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

View File

@ -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'')