mirror of
https://github.com/python-escpos/python-escpos
synced 2025-08-24 09:03:34 +00:00
First attempt at centering images and QRs (#250)
This was tested on ZJ-5890 with success. By default centering is deactivated for backward compatibility. Trying to center a QR code in native mode will raise an exception as we do not know ATM if the native rendering is centered by default or not. * Added basic tests for center feature * Check image size before centering
This commit is contained in:

committed by
Patrick Kanzler

parent
50c627fbb0
commit
b648cfd67f
@@ -145,10 +145,8 @@ def test_large_graphics():
|
||||
assert(instance.output == b'\x1dv0\x00\x01\x00\x01\x00\xc0\x1dv0\x00\x01\x00\x01\x00\x00')
|
||||
|
||||
|
||||
def test_width_too_large():
|
||||
"""
|
||||
Test printing an image that is too large in width.
|
||||
"""
|
||||
@pytest.fixture
|
||||
def dummy_with_width():
|
||||
instance = printer.Dummy()
|
||||
instance.profile.profile_data = {
|
||||
'media': {
|
||||
@@ -157,8 +155,25 @@ def test_width_too_large():
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance
|
||||
|
||||
|
||||
def test_width_too_large(dummy_with_width):
|
||||
"""
|
||||
Test printing an image that is too large in width.
|
||||
"""
|
||||
instance = dummy_with_width
|
||||
|
||||
with pytest.raises(ImageWidthError):
|
||||
instance.image(Image.new("RGB", (385, 200)))
|
||||
|
||||
instance.image(Image.new("RGB", (384, 200)))
|
||||
instance.image(Image.new("RGB", (384, 200)))
|
||||
|
||||
|
||||
def test_center_image(dummy_with_width):
|
||||
instance = dummy_with_width
|
||||
|
||||
with pytest.raises(ImageWidthError):
|
||||
instance.image(Image.new("RGB", (385, 200)), center=True)
|
||||
|
||||
instance.image(Image.new("RGB", (384, 200)), center=True)
|
||||
|
@@ -13,6 +13,8 @@ from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from nose.tools import raises
|
||||
import pytest
|
||||
|
||||
import escpos.printer as printer
|
||||
from escpos.constants import QR_ECLEVEL_H, QR_MODEL_1
|
||||
|
||||
@@ -25,7 +27,6 @@ def test_defaults():
|
||||
b'(k\x07\x001P01234\x1d(k\x03\x001Q0'
|
||||
assert(instance.output == expected)
|
||||
|
||||
|
||||
def test_empty():
|
||||
"""Test QR printing blank code"""
|
||||
instance = printer.Dummy()
|
||||
@@ -99,3 +100,13 @@ def test_image_invalid_model():
|
||||
"""Test unsupported QR model as image"""
|
||||
instance = printer.Dummy()
|
||||
instance.qr("1234", native=False, model=QR_MODEL_1)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def instance():
|
||||
return printer.Dummy()
|
||||
|
||||
|
||||
def test_center_not_implementer(instance):
|
||||
with pytest.raises(NotImplementedError):
|
||||
instance.qr("test", center=True, native=True)
|
@@ -13,6 +13,7 @@ from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pytest
|
||||
import mock
|
||||
|
||||
from escpos.printer import Dummy
|
||||
@@ -30,3 +31,12 @@ def test_type_of_object_passed_to_image_function(img_function):
|
||||
d.qr("LoremIpsum")
|
||||
args, kwargs = img_function.call_args
|
||||
assert isinstance(args[0], Image.Image)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def instance():
|
||||
return Dummy()
|
||||
|
||||
|
||||
def test_center(instance):
|
||||
instance.qr("LoremIpsum", center=True)
|
||||
|
Reference in New Issue
Block a user