diff --git a/src/escpos/capabilities.py b/src/escpos/capabilities.py index 9272c01..0cf76e1 100644 --- a/src/escpos/capabilities.py +++ b/src/escpos/capabilities.py @@ -8,12 +8,13 @@ import six import yaml from tempfile import gettempdir +import platform logging.basicConfig() logger = logging.getLogger(__name__) pickle_dir = environ.get('ESCPOS_CAPABILITIES_PICKLE_DIR', gettempdir()) -pickle_path = path.join(pickle_dir, 'capabilities.pickle') +pickle_path = path.join(pickle_dir, '{v}.capabilities.pickle'.format(v=platform.python_version())) capabilities_path = environ.get( 'ESCPOS_CAPABILITIES_FILE', path.join(path.dirname(__file__), 'capabilities.json')) diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index c14e44a..98a6e93 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -24,6 +24,8 @@ from re import match as re_match import barcode from barcode.writer import ImageWriter +import os + from .constants import ESC, GS, NUL, QR_ECLEVEL_L, QR_ECLEVEL_M, QR_ECLEVEL_H, QR_ECLEVEL_Q from .constants import QR_MODEL_1, QR_MODEL_2, QR_MICRO, BARCODE_TYPES, BARCODE_HEIGHT, BARCODE_WIDTH from .constants import BARCODE_FONT_A, BARCODE_FONT_B, BARCODE_FORMATS @@ -487,11 +489,12 @@ class Escpos(object): barcode_class = barcode.get_barcode_class(barcode_type) my_code = barcode_class(data, writer=image_writer) - my_code.write("/dev/null", { - 'module_height': module_height, - 'module_width': module_width, - 'text_distance': text_distance - }) + with open(os.devnull, "wb") as nullfile: + my_code.write(nullfile, { + 'module_height': module_height, + 'module_width': module_width, + 'text_distance': text_distance + }) # Retrieve the Pillow image and print it image = my_code.writer._image diff --git a/test/test_function_softbarcode.py b/test/test_function_softbarcode.py new file mode 100644 index 0000000..89c7d86 --- /dev/null +++ b/test/test_function_softbarcode.py @@ -0,0 +1,16 @@ +#!/usr/bin/python +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +import escpos.printer as printer +import pytest + + +def test_soft_barcode(): + """just execute soft_barcode + """ + instance = printer.Dummy() + instance.soft_barcode("ean8", "1234") +