remove more SIX usage
This commit is contained in:
parent
0f2ee2b8b5
commit
99b9484c4b
@ -3,8 +3,6 @@
|
||||
|
||||
import sys
|
||||
|
||||
import six
|
||||
|
||||
from escpos import printer
|
||||
from escpos.constants import (
|
||||
CODEPAGE_CHANGE,
|
||||
@ -38,7 +36,7 @@ def print_codepage(printer, codepage):
|
||||
"""Print a codepage."""
|
||||
if codepage.isdigit():
|
||||
codepage = int(codepage)
|
||||
printer._raw(CODEPAGE_CHANGE + six.int2byte(codepage))
|
||||
printer._raw(CODEPAGE_CHANGE + bytes((codepage,)))
|
||||
printer._raw("after")
|
||||
else:
|
||||
printer.charcode(codepage)
|
||||
@ -58,7 +56,9 @@ def print_codepage(printer, codepage):
|
||||
printer.set()
|
||||
|
||||
for y in range(0, 16):
|
||||
byte = six.int2byte(x * 16 + y)
|
||||
byte = bytes(
|
||||
(x * 16 + y),
|
||||
)
|
||||
|
||||
if byte in (ESC, CTL_LF, CTL_FF, CTL_CR, CTL_HT, CTL_VT):
|
||||
byte = " "
|
||||
|
@ -1,14 +1,13 @@
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from escpos import printer
|
||||
from escpos.constants import BUZZER
|
||||
|
||||
|
||||
def test_buzzer_function_with_default_params():
|
||||
def test_buzzer_function_with_default_params() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.buzzer()
|
||||
expected = BUZZER + six.int2byte(2) + six.int2byte(4)
|
||||
expected = BUZZER + bytes((2, 4))
|
||||
assert instance.output == expected
|
||||
|
||||
|
||||
@ -26,10 +25,10 @@ def test_buzzer_function_with_default_params():
|
||||
[9, 9],
|
||||
],
|
||||
)
|
||||
def test_buzzer_function(times, duration):
|
||||
def test_buzzer_function(times: int, duration: int) -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.buzzer(times, duration)
|
||||
expected = BUZZER + six.int2byte(times) + six.int2byte(duration)
|
||||
expected = BUZZER + bytes((times, duration))
|
||||
assert instance.output == expected
|
||||
|
||||
|
||||
@ -46,7 +45,9 @@ def test_buzzer_function(times, duration):
|
||||
[3, 11, "duration must be between 1 and 9"],
|
||||
],
|
||||
)
|
||||
def test_buzzer_fuction_with_outrange_values(times, duration, expected_message):
|
||||
def test_buzzer_fuction_with_outrange_values(
|
||||
times: int, duration: int, expected_message: str
|
||||
) -> None:
|
||||
instance = printer.Dummy()
|
||||
with pytest.raises(ValueError) as e:
|
||||
instance.buzzer(times, duration)
|
||||
|
@ -16,7 +16,7 @@ from escpos.exceptions import ImageWidthError
|
||||
|
||||
|
||||
# Raster format print
|
||||
def test_bit_image_black():
|
||||
def test_bit_image_black() -> None:
|
||||
"""
|
||||
Test printing solid black bit image (raster)
|
||||
"""
|
||||
@ -30,7 +30,7 @@ def test_bit_image_black():
|
||||
assert instance.output == b"\x1dv0\x00\x01\x00\x01\x00\x80"
|
||||
|
||||
|
||||
def test_bit_image_white():
|
||||
def test_bit_image_white() -> None:
|
||||
"""
|
||||
Test printing solid white bit image (raster)
|
||||
"""
|
||||
@ -39,7 +39,7 @@ def test_bit_image_white():
|
||||
assert instance.output == b"\x1dv0\x00\x01\x00\x01\x00\x00"
|
||||
|
||||
|
||||
def test_bit_image_both():
|
||||
def test_bit_image_both() -> None:
|
||||
"""
|
||||
Test printing black/white bit image (raster)
|
||||
"""
|
||||
@ -58,7 +58,7 @@ def test_bit_image_transparent():
|
||||
|
||||
|
||||
# Column format print
|
||||
def test_bit_image_colfmt_black():
|
||||
def test_bit_image_colfmt_black() -> None:
|
||||
"""
|
||||
Test printing solid black bit image (column format)
|
||||
"""
|
||||
@ -67,7 +67,7 @@ def test_bit_image_colfmt_black():
|
||||
assert instance.output == b"\x1b3\x10\x1b*!\x01\x00\x80\x00\x00\x0a\x1b2"
|
||||
|
||||
|
||||
def test_bit_image_colfmt_white():
|
||||
def test_bit_image_colfmt_white() -> None:
|
||||
"""
|
||||
Test printing solid white bit image (column format)
|
||||
"""
|
||||
@ -76,7 +76,7 @@ def test_bit_image_colfmt_white():
|
||||
assert instance.output == b"\x1b3\x10\x1b*!\x01\x00\x00\x00\x00\x0a\x1b2"
|
||||
|
||||
|
||||
def test_bit_image_colfmt_both():
|
||||
def test_bit_image_colfmt_both() -> None:
|
||||
"""
|
||||
Test printing black/white bit image (column format)
|
||||
"""
|
||||
@ -87,7 +87,7 @@ def test_bit_image_colfmt_both():
|
||||
)
|
||||
|
||||
|
||||
def test_bit_image_colfmt_transparent():
|
||||
def test_bit_image_colfmt_transparent() -> None:
|
||||
"""
|
||||
Test printing black/transparent bit image (column format)
|
||||
"""
|
||||
@ -99,7 +99,7 @@ def test_bit_image_colfmt_transparent():
|
||||
|
||||
|
||||
# Graphics print
|
||||
def test_graphics_black():
|
||||
def test_graphics_black() -> None:
|
||||
"""
|
||||
Test printing solid black graphics
|
||||
"""
|
||||
@ -111,7 +111,7 @@ def test_graphics_black():
|
||||
)
|
||||
|
||||
|
||||
def test_graphics_white():
|
||||
def test_graphics_white() -> None:
|
||||
"""
|
||||
Test printing solid white graphics
|
||||
"""
|
||||
@ -123,7 +123,7 @@ def test_graphics_white():
|
||||
)
|
||||
|
||||
|
||||
def test_graphics_both():
|
||||
def test_graphics_both() -> None:
|
||||
"""
|
||||
Test printing black/white graphics
|
||||
"""
|
||||
@ -135,7 +135,7 @@ def test_graphics_both():
|
||||
)
|
||||
|
||||
|
||||
def test_graphics_transparent():
|
||||
def test_graphics_transparent() -> None:
|
||||
"""
|
||||
Test printing black/transparent graphics
|
||||
"""
|
||||
@ -147,7 +147,7 @@ def test_graphics_transparent():
|
||||
)
|
||||
|
||||
|
||||
def test_large_graphics():
|
||||
def test_large_graphics() -> None:
|
||||
"""
|
||||
Test whether 'large' graphics that induce a fragmentation are handled correctly.
|
||||
"""
|
||||
@ -162,13 +162,13 @@ def test_large_graphics():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def dummy_with_width():
|
||||
def dummy_with_width() -> printer.Dummy:
|
||||
instance = printer.Dummy()
|
||||
instance.profile.profile_data = {"media": {"width": {"pixels": 384}}}
|
||||
return instance
|
||||
|
||||
|
||||
def test_width_too_large(dummy_with_width):
|
||||
def test_width_too_large(dummy_with_width: printer.Dummy) -> None:
|
||||
"""
|
||||
Test printing an image that is too large in width.
|
||||
"""
|
||||
@ -180,7 +180,7 @@ def test_width_too_large(dummy_with_width):
|
||||
instance.image(Image.new("RGB", (384, 200)))
|
||||
|
||||
|
||||
def test_center_image(dummy_with_width):
|
||||
def test_center_image(dummy_with_width: printer.Dummy) -> None:
|
||||
instance = dummy_with_width
|
||||
|
||||
with pytest.raises(ImageWidthError):
|
||||
|
@ -11,21 +11,21 @@
|
||||
import escpos.printer as printer
|
||||
|
||||
|
||||
def test_function_linedisplay_select_on():
|
||||
def test_function_linedisplay_select_on() -> None:
|
||||
"""test the linedisplay_select function (activate)"""
|
||||
instance = printer.Dummy()
|
||||
instance.linedisplay_select(select_display=True)
|
||||
assert instance.output == b"\x1B\x3D\x02"
|
||||
|
||||
|
||||
def test_function_linedisplay_select_off():
|
||||
def test_function_linedisplay_select_off() -> None:
|
||||
"""test the linedisplay_select function (deactivate)"""
|
||||
instance = printer.Dummy()
|
||||
instance.linedisplay_select(select_display=False)
|
||||
assert instance.output == b"\x1B\x3D\x01"
|
||||
|
||||
|
||||
def test_function_linedisplay_clear():
|
||||
def test_function_linedisplay_clear() -> None:
|
||||
"""test the linedisplay_clear function"""
|
||||
instance = printer.Dummy()
|
||||
instance.linedisplay_clear()
|
||||
|
@ -1,12 +1,13 @@
|
||||
import pytest
|
||||
import six
|
||||
from typing import Optional
|
||||
|
||||
import escpos.printer as printer
|
||||
from escpos.constants import SET_FONT, TXT_NORMAL, TXT_SIZE, TXT_STYLE
|
||||
from escpos.exceptions import SetVariableError
|
||||
|
||||
|
||||
def test_default_values_with_default():
|
||||
def test_default_values_with_default() -> None:
|
||||
"""Default test, please copy and paste this block to test set method calls"""
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default()
|
||||
@ -26,7 +27,7 @@ def test_default_values_with_default():
|
||||
assert instance.output == b"".join(expected_sequence)
|
||||
|
||||
|
||||
def test_default_values():
|
||||
def test_default_values() -> None:
|
||||
"""Default test"""
|
||||
instance = printer.Dummy()
|
||||
instance.set()
|
||||
@ -37,7 +38,7 @@ def test_default_values():
|
||||
# Size tests
|
||||
|
||||
|
||||
def test_set_size_2h():
|
||||
def test_set_size_2h() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(double_height=True)
|
||||
|
||||
@ -56,7 +57,7 @@ def test_set_size_2h():
|
||||
assert instance.output == b"".join(expected_sequence)
|
||||
|
||||
|
||||
def test_set_size_2h_no_default():
|
||||
def test_set_size_2h_no_default() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set(double_height=True)
|
||||
|
||||
@ -68,7 +69,7 @@ def test_set_size_2h_no_default():
|
||||
assert instance.output == b"".join(expected_sequence)
|
||||
|
||||
|
||||
def test_set_size_2w():
|
||||
def test_set_size_2w() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(double_width=True)
|
||||
|
||||
@ -87,7 +88,7 @@ def test_set_size_2w():
|
||||
assert instance.output == b"".join(expected_sequence)
|
||||
|
||||
|
||||
def test_set_size_2w_no_default():
|
||||
def test_set_size_2w_no_default() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set(double_width=True)
|
||||
|
||||
@ -99,7 +100,7 @@ def test_set_size_2w_no_default():
|
||||
assert instance.output == b"".join(expected_sequence)
|
||||
|
||||
|
||||
def test_set_size_2x():
|
||||
def test_set_size_2x() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(double_height=True, double_width=True)
|
||||
|
||||
@ -118,7 +119,7 @@ def test_set_size_2x():
|
||||
assert instance.output == b"".join(expected_sequence)
|
||||
|
||||
|
||||
def test_set_size_2x_no_default():
|
||||
def test_set_size_2x_no_default() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set(double_width=True, double_height=True)
|
||||
|
||||
@ -130,7 +131,7 @@ def test_set_size_2x_no_default():
|
||||
assert instance.output == b"".join(expected_sequence)
|
||||
|
||||
|
||||
def test_set_size_custom():
|
||||
def test_set_size_custom() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(custom_size=True, width=8, height=7)
|
||||
|
||||
@ -151,7 +152,7 @@ def test_set_size_custom():
|
||||
|
||||
@pytest.mark.parametrize("width", [1, 8])
|
||||
@pytest.mark.parametrize("height", [1, 8])
|
||||
def test_set_size_custom_no_default(width, height):
|
||||
def test_set_size_custom_no_default(width: int, height: int) -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set(custom_size=True, width=width, height=height)
|
||||
|
||||
@ -165,7 +166,9 @@ def test_set_size_custom_no_default(width, height):
|
||||
|
||||
@pytest.mark.parametrize("width", [None, 0, 9, 10, 4444])
|
||||
@pytest.mark.parametrize("height", [None, 0, 9, 10, 4444])
|
||||
def test_set_size_custom_invalid_input(width, height):
|
||||
def test_set_size_custom_invalid_input(
|
||||
width: Optional[int], height: Optional[int]
|
||||
) -> None:
|
||||
instance = printer.Dummy()
|
||||
with pytest.raises(SetVariableError):
|
||||
instance.set(custom_size=True, width=width, height=height)
|
||||
@ -174,7 +177,7 @@ def test_set_size_custom_invalid_input(width, height):
|
||||
# Flip
|
||||
|
||||
|
||||
def test_set_flip():
|
||||
def test_set_flip() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(flip=True)
|
||||
|
||||
@ -193,7 +196,7 @@ def test_set_flip():
|
||||
assert instance.output == b"".join(expected_sequence)
|
||||
|
||||
|
||||
def test_set_flip_no_default():
|
||||
def test_set_flip_no_default() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set(flip=True)
|
||||
|
||||
@ -205,7 +208,7 @@ def test_set_flip_no_default():
|
||||
# Smooth
|
||||
|
||||
|
||||
def test_smooth():
|
||||
def test_smooth() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(smooth=True)
|
||||
|
||||
@ -227,7 +230,7 @@ def test_smooth():
|
||||
# Type
|
||||
|
||||
|
||||
def test_set_bold():
|
||||
def test_set_bold() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(bold=True)
|
||||
|
||||
@ -246,7 +249,7 @@ def test_set_bold():
|
||||
assert instance.output == b"".join(expected_sequence)
|
||||
|
||||
|
||||
def test_set_underline():
|
||||
def test_set_underline() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(underline=1)
|
||||
|
||||
@ -265,7 +268,7 @@ def test_set_underline():
|
||||
assert instance.output == b"".join(expected_sequence)
|
||||
|
||||
|
||||
def test_set_underline2():
|
||||
def test_set_underline2() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(underline=2)
|
||||
|
||||
@ -287,7 +290,7 @@ def test_set_underline2():
|
||||
# Align
|
||||
|
||||
|
||||
def test_align_center():
|
||||
def test_align_center() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(align="center")
|
||||
|
||||
@ -306,7 +309,7 @@ def test_align_center():
|
||||
assert instance.output == b"".join(expected_sequence)
|
||||
|
||||
|
||||
def test_align_right():
|
||||
def test_align_right() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(align="right")
|
||||
|
||||
@ -328,7 +331,7 @@ def test_align_right():
|
||||
# Densities
|
||||
|
||||
|
||||
def test_densities():
|
||||
def test_densities() -> None:
|
||||
for density in range(8):
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(density=density)
|
||||
@ -352,7 +355,7 @@ def test_densities():
|
||||
# Invert
|
||||
|
||||
|
||||
def test_invert():
|
||||
def test_invert() -> None:
|
||||
instance = printer.Dummy()
|
||||
instance.set_with_default(invert=True)
|
||||
|
||||
|
@ -7,11 +7,12 @@ converted to ESC/POS column & raster formats.
|
||||
:copyright: Copyright (c) 2016 `Michael Billington <michael.billington@gmail.com>`_
|
||||
:license: MIT
|
||||
"""
|
||||
from typing import List
|
||||
|
||||
from escpos.image import EscposImage
|
||||
|
||||
|
||||
def test_image_black():
|
||||
def test_image_black() -> None:
|
||||
"""
|
||||
Test rendering solid black image
|
||||
"""
|
||||
@ -19,7 +20,7 @@ def test_image_black():
|
||||
_load_and_check_img("canvas_black." + img_format, 1, 1, b"\x80", [b"\x80"])
|
||||
|
||||
|
||||
def test_image_black_transparent():
|
||||
def test_image_black_transparent() -> None:
|
||||
"""
|
||||
Test rendering black/transparent image
|
||||
"""
|
||||
@ -29,7 +30,7 @@ def test_image_black_transparent():
|
||||
)
|
||||
|
||||
|
||||
def test_image_black_white():
|
||||
def test_image_black_white() -> None:
|
||||
"""
|
||||
Test rendering black/white image
|
||||
"""
|
||||
@ -39,7 +40,7 @@ def test_image_black_white():
|
||||
)
|
||||
|
||||
|
||||
def test_image_white():
|
||||
def test_image_white() -> None:
|
||||
"""
|
||||
Test rendering solid white image
|
||||
"""
|
||||
@ -47,7 +48,7 @@ def test_image_white():
|
||||
_load_and_check_img("canvas_white." + img_format, 1, 1, b"\x00", [b"\x00"])
|
||||
|
||||
|
||||
def test_split():
|
||||
def test_split() -> None:
|
||||
"""
|
||||
test whether the split-function works as expected
|
||||
"""
|
||||
@ -62,12 +63,12 @@ def test_split():
|
||||
|
||||
|
||||
def _load_and_check_img(
|
||||
filename,
|
||||
width_expected,
|
||||
height_expected,
|
||||
raster_format_expected,
|
||||
column_format_expected,
|
||||
):
|
||||
filename: str,
|
||||
width_expected: int,
|
||||
height_expected: int,
|
||||
raster_format_expected: bytes,
|
||||
column_format_expected: List[bytes],
|
||||
) -> None:
|
||||
"""
|
||||
Load an image, and test whether raster & column formatted output, sizes, etc match expectations.
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user