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

Port to current version of escpos-printer-db.

This commit is contained in:
Michael Elsdörfer
2016-08-30 17:05:31 +02:00
parent 40be69347c
commit 2f89f3fe3a
7 changed files with 216 additions and 277 deletions

View File

@@ -12,23 +12,29 @@ from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import pytest
import mock
from hypothesis import given
from hypothesis import given, assume
import hypothesis.strategies as st
from escpos.printer import Dummy
def get_printer():
return Dummy(magic_encode_args={'disabled': True, 'encoding': 'cp437'})
@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 = Dummy()
instance.magic.encode_text = mock.Mock()
def test_text(text):
"""Test that text() calls the MagicEncode object.
"""
instance = get_printer()
instance.magic.write = mock.Mock()
instance.text(text)
instance.magic.encode_text.assert_called_with(txt=text)
instance.magic.write.assert_called_with(text)
def test_block_text():
printer = Dummy()
printer = get_printer()
printer.block_text(
"All the presidents men were eating falafel for breakfast.", font='a')
assert printer.output == \

View File

@@ -17,7 +17,8 @@ import pytest
from nose.tools import raises, assert_raises
from hypothesis import given, example
import hypothesis.strategies as st
from escpos.magicencode import MagicEncode, Encoder, encode_katakana
from escpos.magicencode import MagicEncode, Encoder
from escpos.katakana import encode_katakana
from escpos.exceptions import CharCodeError, Error
@@ -25,13 +26,13 @@ from escpos.exceptions import CharCodeError, Error
class TestEncoder:
def test_can_encode(self):
assert not Encoder({1: 'cp437'}).can_encode('cp437', u'')
assert Encoder({1: 'cp437'}).can_encode('cp437', u'á')
assert not Encoder({1: 'foobar'}).can_encode('foobar', 'a')
assert not Encoder({'cp437': 1}).can_encode('cp437', u'')
assert Encoder({'cp437': 1}).can_encode('cp437', u'á')
assert not Encoder({'foobar': 1}).can_encode('foobar', 'a')
def test_find_suitable_encoding(self):
assert not Encoder({1: 'cp437'}).find_suitable_codespace(u'')
assert Encoder({1: 'cp858'}).find_suitable_codespace(u'') == 'cp858'
assert not Encoder({'cp437': 1}).find_suitable_encoding(u'')
assert Encoder({'cp858': 1}).find_suitable_encoding(u'') == 'cp858'
@raises(ValueError)
def test_get_encoding(self):
@@ -51,12 +52,12 @@ class TestMagicEncode:
def test_init_from_none(self, driver):
encode = MagicEncode(driver, encoding=None)
encode.write_with_encoding('cp858', '€ ist teuro.')
assert driver.output == b'\x1bt\xd5 ist teuro.'
assert driver.output == b'\x1bt\x13\xd5 ist teuro.'
def test_change_from_another(self, driver):
encode = MagicEncode(driver, encoding='cp437')
encode.write_with_encoding('cp858', '€ ist teuro.')
assert driver.output == b'\x1bt\xd5 ist teuro.'
assert driver.output == b'\x1bt\x13\xd5 ist teuro.'
def test_no_change(self, driver):
encode = MagicEncode(driver, encoding='cp858')
@@ -68,7 +69,7 @@ class TestMagicEncode:
def test_write(self, driver):
encode = MagicEncode(driver)
encode.write('€ ist teuro.')
assert driver.output == b'\x1bt\xa4 ist teuro.'
assert driver.output == b'\x1bt\x0f\xa4 ist teuro.'
def test_write_disabled(self, driver):
encode = MagicEncode(driver, encoding='cp437', disabled=True)
@@ -77,7 +78,7 @@ class TestMagicEncode:
def test_write_no_codepage(self, driver):
encode = MagicEncode(
driver, defaultsymbol="_", encoder=Encoder({1: 'cp437'}),
driver, defaultsymbol="_", encoder=Encoder({'cp437': 1}),
encoding='cp437')
encode.write(u'€ ist teuro.')
assert driver.output == b'_ ist teuro.'
@@ -87,10 +88,10 @@ class TestMagicEncode:
def test(self, driver):
encode = MagicEncode(driver)
encode.force_encoding('cp437')
assert driver.output == b'\x1bt'
assert driver.output == b'\x1bt\x00'
encode.write('€ ist teuro.')
assert driver.output == b'\x1bt? ist teuro.'
assert driver.output == b'\x1bt\x00? ist teuro.'
class TestKatakana: