test add type-check for the qr-printing

This commit is contained in:
Patrick Kanzler 2016-08-15 22:33:23 +02:00
parent a38c124bb1
commit e8d91a6735
No known key found for this signature in database
GPG Key ID: F07F07153306FCEF
2 changed files with 34 additions and 3 deletions

View File

@ -157,7 +157,7 @@ class Escpos(object):
if not native: if not native:
# Map ESC/POS error correction levels to python 'qrcode' library constant and render to an image # Map ESC/POS error correction levels to python 'qrcode' library constant and render to an image
if model != QR_MODEL_2: if model != QR_MODEL_2:
raise ValueError("Invalid QR model for qrlib rendering (must be QR_MODEL_2)") raise ValueError("Invalid QR model for python-qrcode rendering (must be QR_MODEL_2)")
python_qr_ec = { python_qr_ec = {
QR_ECLEVEL_H: qrcode.constants.ERROR_CORRECT_H, QR_ECLEVEL_H: qrcode.constants.ERROR_CORRECT_H,
QR_ECLEVEL_L: qrcode.constants.ERROR_CORRECT_L, QR_ECLEVEL_L: qrcode.constants.ERROR_CORRECT_L,
@ -168,8 +168,7 @@ class Escpos(object):
qr_code.add_data(content) qr_code.add_data(content)
qr_code.make(fit=True) qr_code.make(fit=True)
qr_img = qr_code.make_image() qr_img = qr_code.make_image()
im = qr_img._img.convert("RGB") im = qr_img.convert("RGB") # Convert the RGB image in printable image
# Convert the RGB image in printable image
self.image(im) self.image(im)
return return
# Native 2D code printing # Native 2D code printing

View 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)