mirror of
https://github.com/python-escpos/python-escpos
synced 2025-09-13 09:09:58 +00:00
add automatic codepage-changing
This code is adapted from the works by Frédéric Van der Essen in pyxmlescpos. I had to adapt the code completely in order to make it compatible with modern unicode-handling Further changes: * improve text unittests in CLI and MagicEncode with hypothesis * add feature force_encoding in order to enable old behaviour * disable cli_text_test (for now) * fix charcode(): it does now cooperate with the new structure * remove redundant variable codepage from class Escpos
This commit is contained in:

committed by
Patrick Kanzler

parent
b0af9e9652
commit
0cfedb5706
@@ -12,34 +12,16 @@ from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from nose.tools import with_setup
|
||||
import mock
|
||||
from hypothesis import given
|
||||
import hypothesis.strategies as st
|
||||
|
||||
import escpos.printer as printer
|
||||
import os
|
||||
|
||||
import filecmp
|
||||
|
||||
devfile = 'testfile'
|
||||
|
||||
|
||||
def setup_testfile():
|
||||
"""create a testfile as devfile"""
|
||||
fhandle = open(devfile, 'a')
|
||||
try:
|
||||
os.utime(devfile, None)
|
||||
finally:
|
||||
fhandle.close()
|
||||
|
||||
|
||||
def teardown_testfile():
|
||||
"""destroy testfile again"""
|
||||
os.remove(devfile)
|
||||
|
||||
|
||||
@with_setup(setup_testfile, teardown_testfile)
|
||||
def test_function_text_dies_ist_ein_test_lf():
|
||||
@given(text=st.text())
|
||||
def test_function_text_dies_ist_ein_test_lf(text):
|
||||
"""test the text printing function with simple string and compare output"""
|
||||
instance = printer.File(devfile=devfile)
|
||||
instance.text('Dies ist ein Test.\n')
|
||||
instance.flush()
|
||||
assert(filecmp.cmp('test/Dies ist ein Test.LF.txt', devfile))
|
||||
instance = printer.Dummy()
|
||||
instance.magic.encode_text = mock.Mock()
|
||||
instance.text(text)
|
||||
instance.magic.encode_text.assert_called_with(txt=text)
|
||||
|
Reference in New Issue
Block a user