improve type annotations in tests (#613)

This commit is contained in:
Patrick Kanzler 2023-12-17 01:15:59 +01:00 committed by GitHub
parent 0c824cf295
commit b66dafc90e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 16 deletions

View File

@ -14,14 +14,14 @@ import pytest
import escpos.escpos as escpos
def test_abstract_base_class_raises():
def test_abstract_base_class_raises() -> None:
"""test whether the abstract base class raises an exception for ESC/POS"""
with pytest.raises(TypeError):
# This call should raise TypeError because of abstractmethod _raw()
escpos.Escpos()
escpos.Escpos() # type: ignore [abstract]
def test_abstract_base_class():
def test_abstract_base_class() -> None:
"""test whether Escpos has the metaclass ABCMeta"""
assert issubclass(escpos.Escpos, object)
assert type(escpos.Escpos) is ABCMeta

View File

@ -11,7 +11,7 @@
import escpos.printer as printer
def test_instantiation():
def test_instantiation() -> None:
"""test the instantiation of a escpos-printer class and basic printing"""
instance = printer.Dummy()
instance.text("This is a test\n")

View File

@ -13,7 +13,7 @@ import tempfile
import pytest
def test_instantiation():
def test_instantiation() -> None:
"""test the instantiation of a escpos-printer class"""
# inject an environment variable that points to an empty capabilities file
os.environ["ESCPOS_CAPABILITIES_FILE"] = tempfile.NamedTemporaryFile().name

View File

@ -13,6 +13,7 @@ import hypothesis.strategies as st
import pytest
from hypothesis import example, given
from escpos import printer
from escpos.exceptions import Error
from escpos.katakana import encode_katakana
from escpos.magicencode import Encoder, MagicEncode
@ -54,7 +55,7 @@ class TestMagicEncode:
Test initialization.
"""
def test_disabled_requires_encoding(self, driver):
def test_disabled_requires_encoding(self, driver: printer.Dummy) -> None:
"""
Test that disabled without encoder raises an error.
@ -64,33 +65,33 @@ class TestMagicEncode:
MagicEncode(driver, disabled=True)
class TestWriteWithEncoding:
def test_init_from_none(self, driver):
def test_init_from_none(self, driver: printer.Dummy) -> None:
encode = MagicEncode(driver, encoding=None)
encode.write_with_encoding("CP858", "€ ist teuro.")
assert driver.output == b"\x1bt\x13\xd5 ist teuro."
def test_change_from_another(self, driver):
def test_change_from_another(self, driver: printer.Dummy) -> None:
encode = MagicEncode(driver, encoding="CP437")
encode.write_with_encoding("CP858", "€ ist teuro.")
assert driver.output == b"\x1bt\x13\xd5 ist teuro."
def test_no_change(self, driver):
def test_no_change(self, driver: printer.Dummy) -> None:
encode = MagicEncode(driver, encoding="CP858")
encode.write_with_encoding("CP858", "€ ist teuro.")
assert driver.output == b"\xd5 ist teuro."
class TestWrite:
def test_write(self, driver):
def test_write(self, driver: printer.Dummy) -> None:
encode = MagicEncode(driver)
encode.write("€ ist teuro.")
assert driver.output == b"\x1bt\x0f\xa4 ist teuro."
def test_write_disabled(self, driver):
def test_write_disabled(self, driver: printer.Dummy) -> None:
encode = MagicEncode(driver, encoding="CP437", disabled=True)
encode.write("€ ist teuro.")
assert driver.output == b"? ist teuro."
def test_write_no_codepage(self, driver):
def test_write_no_codepage(self, driver: printer.Dummy) -> None:
encode = MagicEncode(
driver,
defaultsymbol="_",
@ -101,7 +102,7 @@ class TestMagicEncode:
assert driver.output == b"_ ist teuro."
class TestForceEncoding:
def test(self, driver):
def test(self, driver: printer.Dummy) -> None:
encode = MagicEncode(driver)
encode.force_encoding("CP437")
assert driver.output == b"\x1bt\x00"

View File

@ -14,13 +14,13 @@ import escpos
import escpos.exceptions
def test_raise_error_wrongly():
def test_raise_error_wrongly() -> None:
"""raise error the wrong way
should reproduce https://github.com/python-escpos/python-escpos/issues/257
"""
with pytest.raises(AttributeError):
raise escpos.Error("This should raise an AttributeError.")
raise escpos.Error("This should raise an AttributeError.") # type: ignore [attr-defined]
def tests_raise_error() -> None:

View File

@ -12,7 +12,7 @@ import escpos.escpos as escpos
import escpos.printer as printer
def test_with_statement():
def test_with_statement() -> None:
"""Use with statement
.. todo:: Extend these tests as they don't really do anything at the moment"""