
* fix unfinished Python2 -> 3 translation * remove some six usage * annotate * fix regression in Six removal * mypy: self.enf is always defined * fix return type of cups.py * Usb idVendor/idProduct are integers * self.default_args is always defined * tweak usb_args, PEP589 is better * lp.py: reassure mypy * correctly cast call to CashDrawerError() * update CUPS test * add missing close() method in metaclass * document a bug in typeshed * query_status() returns bytes as seen in constants.py * remove more SIX usage * test examples too * remove type comment where type is annotated * adapt behavior of cups printer to match other implementations --------- Co-authored-by: Patrick Kanzler <dev@pkanzler.de> Co-authored-by: Patrick Kanzler <4189642+patkan@users.noreply.github.com>
63 lines
1.5 KiB
Python
63 lines
1.5 KiB
Python
#!/usr/bin/python
|
|
"""tests for the text printing function
|
|
|
|
:author: `Patrick Kanzler <dev@pkanzler.de>`_
|
|
:organization: `python-escpos <https://github.com/python-escpos>`_
|
|
:copyright: Copyright (c) 2016 `python-escpos <https://github.com/python-escpos>`_
|
|
:license: MIT
|
|
"""
|
|
|
|
|
|
import hypothesis.strategies as st
|
|
import mock
|
|
from hypothesis import given
|
|
|
|
from escpos.printer import Dummy
|
|
|
|
|
|
def get_printer():
|
|
return Dummy(magic_encode_args={"disabled": True, "encoding": "CP437"})
|
|
|
|
|
|
@given(text=st.text())
|
|
def test_text(text: str) -> None:
|
|
"""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)
|
|
|
|
|
|
def test_block_text() -> None:
|
|
printer = get_printer()
|
|
printer.block_text(
|
|
"All the presidents men were eating falafel for breakfast.", font="a"
|
|
)
|
|
assert (
|
|
printer.output == b"All the presidents men were eating falafel\nfor breakfast."
|
|
)
|
|
|
|
|
|
def test_textln() -> None:
|
|
printer = get_printer()
|
|
printer.textln("hello, world")
|
|
assert printer.output == b"hello, world\n"
|
|
|
|
|
|
def test_textln_empty() -> None:
|
|
printer = get_printer()
|
|
printer.textln()
|
|
assert printer.output == b"\n"
|
|
|
|
|
|
def test_ln() -> None:
|
|
printer = get_printer()
|
|
printer.ln()
|
|
assert printer.output == b"\n"
|
|
|
|
|
|
def test_multiple_ln() -> None:
|
|
printer = get_printer()
|
|
printer.ln(3)
|
|
assert printer.output == b"\n\n\n"
|