Merge pull request #123 from python-escpos/refactor/misc-issues

Refactor misc issues
This commit is contained in:
Patrick Kanzler 2016-04-03 21:46:15 +02:00
commit 2aa0878f54
6 changed files with 18 additions and 11 deletions

View File

@ -1,5 +1,5 @@
Config Config
--------- ------
Module :py:mod:`escpos.config` Module :py:mod:`escpos.config`
.. automodule:: escpos.config .. automodule:: escpos.config

View File

@ -238,12 +238,12 @@ class Escpos(object):
(width, height) = image.size (width, height) = image.size
self._raw(S_RASTER_N) self._raw(S_RASTER_N)
headerX = int(width / 8) header_x = int(width / 8)
headerY = height header_y = height
buf = "{0:02X}".format((headerX & 0xff)) buf = "{0:02X}".format((header_x & 0xff))
buf += "{0:02X}".format(((headerX >> 8) & 0xff)) buf += "{0:02X}".format(((header_x >> 8) & 0xff))
buf += "{0:02X}".format((headerY & 0xff)) buf += "{0:02X}".format((header_y & 0xff))
buf += "{0:02X}".format(((headerY >> 8) & 0xff)) buf += "{0:02X}".format(((header_y >> 8) & 0xff))
#self._raw(binascii.unhexlify(buf)) #self._raw(binascii.unhexlify(buf))
for y in range(height): for y in range(height):
for x in range(width): for x in range(width):
@ -550,8 +550,8 @@ class Escpos(object):
:param columns: amount of columns :param columns: amount of columns
:return: None :return: None
""" """
colCount = self.columns if columns is None else columns col_count = self.columns if columns is None else columns
self.text(textwrap.fill(txt, colCount)) self.text(textwrap.fill(txt, col_count))
def set(self, align='left', font='a', text_type='normal', width=1, height=1, density=9, invert=False, smooth=False, flip=False): def set(self, align='left', font='a', text_type='normal', width=1, height=1, density=9, invert=False, smooth=False, flip=False):
""" Set text properties by sending them to the printer """ Set text properties by sending them to the printer
@ -733,7 +733,7 @@ class Escpos(object):
:raises: :py:exc:`~escpos.exceptions.TabPosError` :raises: :py:exc:`~escpos.exceptions.TabPosError`
""" """
# Set tab positions # Set tab positions
if pos < 1 or pos > 16: if not (1 <= pos <= 16):
raise TabPosError() raise TabPosError()
else: else:
self._raw(CTL_SET_HT + six.int2byte(pos)) self._raw(CTL_SET_HT + six.int2byte(pos))

View File

@ -17,7 +17,7 @@ import usb.util
import serial import serial
import socket import socket
from .escpos import * from .escpos import Escpos
from .exceptions import * from .exceptions import *

View File

@ -28,6 +28,7 @@ printer:
testfile=DEVFILE, testfile=DEVFILE,
) )
class TestCLI: class TestCLI:
""" Contains setups, teardowns, and tests for CLI """ Contains setups, teardowns, and tests for CLI
""" """

View File

@ -21,6 +21,7 @@ import filecmp
devfile = 'testfile' devfile = 'testfile'
def setup_testfile(): def setup_testfile():
"""create a testfile as devfile""" """create a testfile as devfile"""
fhandle = open(devfile, 'a') fhandle = open(devfile, 'a')
@ -29,10 +30,12 @@ def setup_testfile():
finally: finally:
fhandle.close() fhandle.close()
def teardown_testfile(): def teardown_testfile():
"""destroy testfile again""" """destroy testfile again"""
os.remove(devfile) os.remove(devfile)
@with_setup(setup_testfile, teardown_testfile) @with_setup(setup_testfile, teardown_testfile)
def test_function_text_dies_ist_ein_test_lf(): def test_function_text_dies_ist_ein_test_lf():
"""test the text printing function with simple string and compare output""" """test the text printing function with simple string and compare output"""

View File

@ -19,6 +19,7 @@ import os
devfile = 'testfile' devfile = 'testfile'
def setup_testfile(): def setup_testfile():
"""create a testfile as devfile""" """create a testfile as devfile"""
fhandle = open(devfile, 'a') fhandle = open(devfile, 'a')
@ -27,10 +28,12 @@ def setup_testfile():
finally: finally:
fhandle.close() fhandle.close()
def teardown_testfile(): def teardown_testfile():
"""destroy testfile again""" """destroy testfile again"""
os.remove(devfile) os.remove(devfile)
@with_setup(setup_testfile, teardown_testfile) @with_setup(setup_testfile, teardown_testfile)
def test_instantiation(): def test_instantiation():
"""test the instantiation of a escpos-printer class and basic printing""" """test the instantiation of a escpos-printer class and basic printing"""