mirror of
https://github.com/python-escpos/python-escpos
synced 2025-08-24 09:03:34 +00:00
Merge branch 'capabilities' into text-encoding
This commit is contained in:
@@ -130,3 +130,12 @@ def test_graphics_transparent():
|
||||
instance = printer.Dummy()
|
||||
instance.image('test/resources/black_transparent.png', impl="graphics")
|
||||
assert(instance.output == b'\x1d(L\x0c\x000p0\x01\x011\x02\x00\x02\x00\xc0\x00\x1d(L\x02\x0002')
|
||||
|
||||
|
||||
def test_large_graphics():
|
||||
"""
|
||||
Test whether 'large' graphics that induce a fragmentation are handled correctly.
|
||||
"""
|
||||
instance = printer.Dummy()
|
||||
instance.image('test/resources/black_white.png', impl="bitImageRaster", fragment_height=1)
|
||||
assert(instance.output == b'\x1dv0\x00\x01\x00\x01\x00\xc0\x1dv0\x00\x01\x00\x01\x00\x00')
|
||||
|
32
test/test_function_qr_non-native.py
Normal file
32
test/test_function_qr_non-native.py
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""tests for the non-native part of qr()
|
||||
|
||||
: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 mock
|
||||
|
||||
from escpos.printer import Dummy
|
||||
from PIL import Image
|
||||
|
||||
|
||||
@mock.patch('escpos.printer.Dummy.image', spec=Dummy)
|
||||
def test_type_of_object_passed_to_image_function(img_function):
|
||||
"""
|
||||
Test the type of object that is passed to the image function during non-native qr-printing.
|
||||
|
||||
The type should be PIL.Image
|
||||
"""
|
||||
d = Dummy()
|
||||
d.qr("LoremIpsum")
|
||||
args, kwargs = img_function.call_args
|
||||
assert isinstance(args[0], Image.Image)
|
@@ -15,9 +15,10 @@ from __future__ import unicode_literals
|
||||
import mock
|
||||
from hypothesis import given
|
||||
import hypothesis.strategies as st
|
||||
|
||||
from escpos.printer import Dummy
|
||||
import escpos.printer as printer
|
||||
|
||||
|
||||
@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"""
|
||||
@@ -25,3 +26,11 @@ def test_function_text_dies_ist_ein_test_lf(text):
|
||||
instance.magic.encode_text = mock.Mock()
|
||||
instance.text(text)
|
||||
instance.magic.encode_text.assert_called_with(txt=text)
|
||||
|
||||
|
||||
def test_block_text():
|
||||
printer = Dummy()
|
||||
printer.block_text(
|
||||
"All the presidents men were eating falafel for breakfast.", font='a')
|
||||
assert printer.output == \
|
||||
'All the presidents men were eating falafel\nfor breakfast.'
|
||||
|
@@ -43,6 +43,20 @@ def test_image_white():
|
||||
_load_and_check_img('canvas_white.' + img_format, 1, 1, b'\x00', [b'\x00'])
|
||||
|
||||
|
||||
def test_split():
|
||||
"""
|
||||
test whether the split-function works as expected
|
||||
"""
|
||||
im = EscposImage('test/resources/black_white.png')
|
||||
(upper_part, lower_part) = im.split(1)
|
||||
upper_part = EscposImage(upper_part)
|
||||
lower_part = EscposImage(lower_part)
|
||||
assert(upper_part.width == lower_part.width == 2)
|
||||
assert(upper_part.height == lower_part.height == 1)
|
||||
assert(upper_part.to_raster_format() == b'\xc0')
|
||||
assert(lower_part.to_raster_format() == b'\x00')
|
||||
|
||||
|
||||
def _load_and_check_img(filename, width_expected, height_expected, raster_format_expected, column_format_expected):
|
||||
"""
|
||||
Load an image, and test whether raster & column formatted output, sizes, etc match expectations.
|
||||
|
Reference in New Issue
Block a user