Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/escpos/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
pass # noqa
import sys

from . import config
from . import config, escpos
from . import printer as escpos_printer_module
from . import version

Expand Down Expand Up @@ -617,7 +617,7 @@ def main() -> None:
globals()[target_command](**command_arguments)


def demo(printer, **kwargs) -> None:
def demo(printer: escpos.Escpos, **kwargs) -> None:
"""Print demos.

Called when CLI is passed `demo`. This function
Expand Down
12 changes: 6 additions & 6 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@


@pytest.fixture
def driver():
def driver() -> Dummy:
return Dummy()


@pytest.fixture
def usbprinter():
def usbprinter() -> Usb:
return Usb()


@pytest.fixture
def serialprinter():
def serialprinter() -> Serial:
return Serial()


@pytest.fixture
def networkprinter():
def networkprinter() -> Network:
return Network()


@pytest.fixture
def fileprinter():
def fileprinter() -> File:
return File()


@pytest.fixture
def lpprinter():
def lpprinter() -> LP:
return LP()


Expand Down
2 changes: 1 addition & 1 deletion test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_config_load_with_missing_config(tmp_path):
@pytest.mark.skip(
"This test creates in the actual appdir files and is therefore skipped."
)
def test_config_load_from_appdir():
def test_config_load_from_appdir() -> None:
"""Test the loading of a config in appdir."""
from escpos import config

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from escpos.exceptions import CashDrawerError


def test_raise_CashDrawerError():
def test_raise_CashDrawerError() -> None:
"""should raise an error if the sequence is invalid."""
instance = printer.Dummy()
with pytest.raises(CashDrawerError):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from escpos.constants import GS


def test_cut_without_feed():
def test_cut_without_feed() -> None:
"""Test cut without feeding paper"""
instance = printer.Dummy()
instance.cut(feed=False)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from escpos.printer import Dummy


def test_printer_dummy_clear():
def test_printer_dummy_clear() -> None:
printer = Dummy()
printer.text("Hello")
printer.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_bit_image_both() -> None:
assert instance.output == b"\x1dv0\x00\x01\x00\x02\x00\xc0\x00"


def test_bit_image_transparent():
def test_bit_image_transparent() -> None:
"""
Test printing black/transparent bit image (raster)
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import escpos.printer as printer


def test_function_panel_button_on():
def test_function_panel_button_on() -> None:
"""test the panel button function (enabling) by comparing output"""
instance = printer.Dummy()
instance.panel_buttons()
assert instance.output == b"\x1B\x63\x35\x00"


def test_function_panel_button_off():
def test_function_panel_button_off() -> None:
"""test the panel button function (disabling) by comparing output"""
instance = printer.Dummy()
instance.panel_buttons(False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from escpos.constants import QR_ECLEVEL_H, QR_MODEL_1


def test_defaults():
def test_defaults() -> None:
"""Test QR code with defaults"""
instance = printer.Dummy()
instance.qr("1234", native=True)
Expand All @@ -25,14 +25,14 @@ def test_defaults():
assert instance.output == expected


def test_empty():
def test_empty() -> None:
"""Test QR printing blank code"""
instance = printer.Dummy()
instance.qr("", native=True)
assert instance.output == b""


def test_ec():
def test_ec() -> None:
"""Test QR error correction setting"""
instance = printer.Dummy()
instance.qr("1234", native=True, ec=QR_ECLEVEL_H)
Expand All @@ -43,7 +43,7 @@ def test_ec():
assert instance.output == expected


def test_size():
def test_size() -> None:
"""Test QR box size"""
instance = printer.Dummy()
instance.qr("1234", native=True, size=7)
Expand All @@ -54,7 +54,7 @@ def test_size():
assert instance.output == expected


def test_model():
def test_model() -> None:
"""Test QR model"""
instance = printer.Dummy()
instance.qr("1234", native=True, model=QR_MODEL_1)
Expand All @@ -65,28 +65,28 @@ def test_model():
assert instance.output == expected


def test_invalid_ec():
def test_invalid_ec() -> None:
"""Test invalid QR error correction"""
instance = printer.Dummy()
with pytest.raises(ValueError):
instance.qr("1234", native=True, ec=-1)


def test_invalid_size():
def test_invalid_size() -> None:
"""Test invalid QR size"""
instance = printer.Dummy()
with pytest.raises(ValueError):
instance.qr("1234", native=True, size=0)


def test_invalid_model():
def test_invalid_model() -> None:
"""Test invalid QR model"""
instance = printer.Dummy()
with pytest.raises(ValueError):
instance.qr("1234", native=True, model="Hello")


def test_image_invalid_model():
def test_image_invalid_model() -> None:
"""Test unsupported QR model as image"""
instance = printer.Dummy()
with pytest.raises(ValueError):
Expand All @@ -98,6 +98,6 @@ def instance():
return printer.Dummy()


def test_center_not_implementer(instance):
def test_center_not_implementer(instance: printer.Dummy) -> None:
with pytest.raises(NotImplementedError):
instance.qr("test", center=True, native=True)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from escpos.printer import Dummy


def test_image():
def test_image() -> None:
"""Test QR as image"""
instance = Dummy()
image_arguments = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Optional

import pytest
import six

import escpos.printer as printer
from escpos.constants import SET_FONT, TXT_NORMAL, TXT_SIZE, TXT_STYLE
Expand Down Expand Up @@ -138,7 +137,7 @@ def test_set_size_custom() -> None:

expected_sequence = (
TXT_SIZE, # Custom text size, no normal reset
six.int2byte(TXT_STYLE["width"][8] + TXT_STYLE["height"][7]),
bytes((TXT_STYLE["width"][8] + TXT_STYLE["height"][7],)),
TXT_STYLE["flip"][False], # Flip OFF
TXT_STYLE["smooth"][False], # Smooth OFF
TXT_STYLE["bold"][False], # Bold OFF
Expand All @@ -159,7 +158,7 @@ def test_set_size_custom_no_default(width: int, height: int) -> None:

expected_sequence = (
TXT_SIZE, # Custom text size, no normal reset
six.int2byte(TXT_STYLE["width"][width] + TXT_STYLE["height"][height]),
bytes((TXT_STYLE["width"][width] + TXT_STYLE["height"][height],)),
)

assert instance.output == b"".join(expected_sequence)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ def instance():
return printer.Dummy()


def test_soft_barcode_ean8_invalid(instance):
def test_soft_barcode_ean8_invalid(instance: printer.Dummy) -> None:
"""test with an invalid barcode"""
with pytest.raises(barcode.errors.BarcodeError):
instance.barcode("1234", "ean8", force_software=True)


def test_soft_barcode_ean8(instance):
def test_soft_barcode_ean8(instance: printer.Dummy) -> None:
"""test with a valid ean8 barcode"""
instance.barcode("1234567", "ean8", force_software=True)


def test_soft_barcode_ean8_nocenter(instance):
def test_soft_barcode_ean8_nocenter(instance: printer.Dummy) -> None:
instance.barcode("1234567", "ean8", align_ct=False, force_software=True)
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
from escpos.printer import Dummy


def get_printer():
def get_printer() -> Dummy:
return Dummy(magic_encode_args={"disabled": True, "encoding": "CP437"})


@given(text=st.text())
def test_text(text: str) -> None:
def test_text(text: str):
"""Test that text() calls the MagicEncode object."""
instance = get_printer()
instance.magic.write = mock.Mock()
instance.text(text)
instance.magic.write.assert_called_with(text)
with mock.patch.object(instance.magic, "write") as write:
instance.text(text)
write.assert_called_with(text)


def test_block_text() -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
from escpos.printer import Dummy


def test_line_spacing_code_gen():
def test_line_spacing_code_gen() -> None:
printer = Dummy()
printer.line_spacing(10)
assert printer.output == b"\x1b3\n"


def test_line_spacing_rest():
def test_line_spacing_rest() -> None:
printer = Dummy()
printer.line_spacing()
assert printer.output == b"\x1b2"


def test_line_spacing_error_handling():
def test_line_spacing_error_handling() -> None:
printer = Dummy()
with pytest.raises(ValueError):
printer.line_spacing(99, divisor=44)
Expand Down
2 changes: 1 addition & 1 deletion test/test_raise_arbitrary_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_raise_error_wrongly():
raise escpos.Error("This should raise an AttributeError.")


def tests_raise_error():
def tests_raise_error() -> None:
"""raise error the right way"""
with pytest.raises(escpos.exceptions.Error):
raise escpos.exceptions.Error("This should raise an error.")