improve platform independence (#296)
* add os.devnull for platform independence fixes #288 * add test for soft_barcode * open devnull as binary * add version identifier to pickle
This commit is contained in:
parent
6fb23d6826
commit
6c94f88c24
|
@ -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'))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
Loading…
Reference in New Issue