1
0
mirror of https://github.com/python-escpos/python-escpos synced 2025-08-24 09:03:34 +00:00

add with-statement

* with imported from mosquito (adaption of the code in 86a3e8dfb257e3af0ec141ee5d97717501d6e945 by @mosquito)
* encoding of file to utf-8
* added rudimentary test for with
* implement close function for all printers
This commit is contained in:
Patrick Kanzler
2016-03-28 15:54:43 +02:00
parent 16569067c2
commit 910f2fbf2f
5 changed files with 126 additions and 5 deletions

View File

@@ -0,0 +1,24 @@
#!/usr/bin/python
"""test the facility which enables usage of the with-statement
:author: `Patrick Kanzler <patrick.kanzler@fablab.fau.de>`_
:organization: `python-escpos <https://github.com/python-escpos>`_
:copyright: Copyright (c) 2016 `python-escpos <https://github.com/python-escpos>`_
:license: GNU GPL v3
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import escpos.printer as printer
import escpos.escpos as escpos
import os
def test_with_statement():
"""Use with statement"""
dummy_printer = printer.Dummy()
with escpos.EscposIO(dummy_printer) as p:
p.writelines('Some text.\n')
# TODO extend these tests as they don't really do anything at the moment