From f6e0edc7c7a4ac280b84efae20eebe4f999c062c Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sat, 2 Apr 2016 15:26:00 +0200 Subject: [PATCH 1/5] REFACTOR variables to be lower case --- escpos/escpos.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/escpos/escpos.py b/escpos/escpos.py index d073736..efc9a16 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -238,12 +238,12 @@ class Escpos(object): (width, height) = image.size self._raw(S_RASTER_N) - headerX = int(width / 8) - headerY = height - buf = "{0:02X}".format((headerX & 0xff)) - buf += "{0:02X}".format(((headerX >> 8) & 0xff)) - buf += "{0:02X}".format((headerY & 0xff)) - buf += "{0:02X}".format(((headerY >> 8) & 0xff)) + header_x = int(width / 8) + header_y = height + buf = "{0:02X}".format((header_x & 0xff)) + buf += "{0:02X}".format(((header_x >> 8) & 0xff)) + buf += "{0:02X}".format((header_y & 0xff)) + buf += "{0:02X}".format(((header_y >> 8) & 0xff)) #self._raw(binascii.unhexlify(buf)) for y in range(height): for x in range(width): @@ -486,8 +486,8 @@ class Escpos(object): :param columns: amount of columns :return: None """ - colCount = self.columns if columns is None else columns - self.text(textwrap.fill(txt, colCount)) + col_count = self.columns if columns is None else columns + 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): """ Set text properties by sending them to the printer From 7547bfddd2aa6c4f41f748a0e054f4ed30bfff6a Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sat, 2 Apr 2016 15:27:47 +0200 Subject: [PATCH 2/5] DOC fix underline length in doc --- doc/api/config.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/config.rst b/doc/api/config.rst index c5e3691..ab17067 100644 --- a/doc/api/config.rst +++ b/doc/api/config.rst @@ -1,5 +1,5 @@ Config ---------- +------ Module :py:mod:`escpos.config` .. automodule:: escpos.config From 0121aa0bfb7f462f8d13a139aed448341fc98dca Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sat, 2 Apr 2016 15:29:51 +0200 Subject: [PATCH 3/5] REFACTOR add PEP8-newlines --- test/test_cli.py | 1 + test/test_function_text.py | 3 +++ test/test_load_module.py | 3 +++ 3 files changed, 7 insertions(+) diff --git a/test/test_cli.py b/test/test_cli.py index 331eff6..03beb2d 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -28,6 +28,7 @@ printer: testfile=DEVFILE, ) + class TestCLI: """ Contains setups, teardowns, and tests for CLI """ diff --git a/test/test_function_text.py b/test/test_function_text.py index 2ad7bd1..b0b1ca1 100644 --- a/test/test_function_text.py +++ b/test/test_function_text.py @@ -21,6 +21,7 @@ import filecmp devfile = 'testfile' + def setup_testfile(): """create a testfile as devfile""" fhandle = open(devfile, 'a') @@ -29,10 +30,12 @@ def setup_testfile(): finally: fhandle.close() + def teardown_testfile(): """destroy testfile again""" os.remove(devfile) + @with_setup(setup_testfile, teardown_testfile) def test_function_text_dies_ist_ein_test_lf(): """test the text printing function with simple string and compare output""" diff --git a/test/test_load_module.py b/test/test_load_module.py index 0cfcce9..daf94b4 100644 --- a/test/test_load_module.py +++ b/test/test_load_module.py @@ -19,6 +19,7 @@ import os devfile = 'testfile' + def setup_testfile(): """create a testfile as devfile""" fhandle = open(devfile, 'a') @@ -27,10 +28,12 @@ def setup_testfile(): finally: fhandle.close() + def teardown_testfile(): """destroy testfile again""" os.remove(devfile) + @with_setup(setup_testfile, teardown_testfile) def test_instantiation(): """test the instantiation of a escpos-printer class and basic printing""" From 1ee657a75049dcdc545e4eca86ce75cfcef0bbb8 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sat, 2 Apr 2016 15:33:24 +0200 Subject: [PATCH 4/5] REFACTOR remove wildcard-import from escpos in printer --- escpos/printer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/escpos/printer.py b/escpos/printer.py index 5a4d126..ddd6ae5 100644 --- a/escpos/printer.py +++ b/escpos/printer.py @@ -17,7 +17,7 @@ import usb.util import serial import socket -from .escpos import * +from .escpos import Escpos from .exceptions import * From 481285625be75bc02455166911c46317d6aa5b50 Mon Sep 17 00:00:00 2001 From: Patrick Kanzler Date: Sat, 2 Apr 2016 16:02:04 +0200 Subject: [PATCH 5/5] REFACTOR simplify out-of-bounds-check in control() --- escpos/escpos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/escpos/escpos.py b/escpos/escpos.py index efc9a16..6b819a4 100644 --- a/escpos/escpos.py +++ b/escpos/escpos.py @@ -669,7 +669,7 @@ class Escpos(object): :raises: :py:exc:`~escpos.exceptions.TabPosError` """ # Set tab positions - if pos < 1 or pos > 16: + if not (1 <= pos <= 16): raise TabPosError() else: self._raw(CTL_SET_HT + six.int2byte(pos))