2016-03-02 22:16:58 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
"""tests for the text printing function
|
|
|
|
|
2023-08-14 23:03:36 +00:00
|
|
|
:author: `Patrick Kanzler <dev@pkanzler.de>`_
|
2016-03-02 22:16:58 +00:00
|
|
|
:organization: `python-escpos <https://github.com/python-escpos>`_
|
|
|
|
:copyright: Copyright (c) 2016 `python-escpos <https://github.com/python-escpos>`_
|
2017-01-29 23:39:43 +00:00
|
|
|
:license: MIT
|
2016-03-02 22:16:58 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
2016-07-23 20:16:11 +00:00
|
|
|
import hypothesis.strategies as st
|
2023-08-14 23:03:36 +00:00
|
|
|
import mock
|
2023-12-16 21:02:24 +00:00
|
|
|
from hypothesis import given
|
2023-08-14 23:03:36 +00:00
|
|
|
|
2016-08-25 15:30:20 +00:00
|
|
|
from escpos.printer import Dummy
|
2016-03-02 22:16:58 +00:00
|
|
|
|
2016-04-02 13:29:51 +00:00
|
|
|
|
2016-08-30 15:05:31 +00:00
|
|
|
def get_printer():
|
2021-10-30 16:15:22 +00:00
|
|
|
return Dummy(magic_encode_args={"disabled": True, "encoding": "CP437"})
|
2016-08-30 15:05:31 +00:00
|
|
|
|
|
|
|
|
2016-07-23 20:16:11 +00:00
|
|
|
@given(text=st.text())
|
2023-12-16 21:02:24 +00:00
|
|
|
def test_text(text: str) -> None:
|
2021-10-30 16:15:22 +00:00
|
|
|
"""Test that text() calls the MagicEncode object."""
|
2016-08-30 15:05:31 +00:00
|
|
|
instance = get_printer()
|
|
|
|
instance.magic.write = mock.Mock()
|
2016-07-23 20:16:11 +00:00
|
|
|
instance.text(text)
|
2016-08-30 15:05:31 +00:00
|
|
|
instance.magic.write.assert_called_with(text)
|
2016-08-25 15:30:20 +00:00
|
|
|
|
|
|
|
|
2023-12-16 21:02:24 +00:00
|
|
|
def test_block_text() -> None:
|
2016-08-30 15:05:31 +00:00
|
|
|
printer = get_printer()
|
2016-08-25 15:30:20 +00:00
|
|
|
printer.block_text(
|
2021-10-30 16:15:22 +00:00
|
|
|
"All the presidents men were eating falafel for breakfast.", font="a"
|
|
|
|
)
|
|
|
|
assert (
|
|
|
|
printer.output == b"All the presidents men were eating falafel\nfor breakfast."
|
|
|
|
)
|
2017-08-01 15:09:24 +00:00
|
|
|
|
|
|
|
|
2023-12-16 21:02:24 +00:00
|
|
|
def test_textln() -> None:
|
2017-08-01 15:09:24 +00:00
|
|
|
printer = get_printer()
|
2021-10-30 16:15:22 +00:00
|
|
|
printer.textln("hello, world")
|
|
|
|
assert printer.output == b"hello, world\n"
|
2017-08-01 15:09:24 +00:00
|
|
|
|
|
|
|
|
2023-12-16 21:02:24 +00:00
|
|
|
def test_textln_empty() -> None:
|
2017-08-01 15:09:24 +00:00
|
|
|
printer = get_printer()
|
|
|
|
printer.textln()
|
2021-10-30 16:15:22 +00:00
|
|
|
assert printer.output == b"\n"
|
2017-08-01 15:09:24 +00:00
|
|
|
|
|
|
|
|
2023-12-16 21:02:24 +00:00
|
|
|
def test_ln() -> None:
|
2017-08-01 15:09:24 +00:00
|
|
|
printer = get_printer()
|
|
|
|
printer.ln()
|
2021-10-30 16:15:22 +00:00
|
|
|
assert printer.output == b"\n"
|
2017-08-01 15:09:24 +00:00
|
|
|
|
|
|
|
|
2023-12-16 21:02:24 +00:00
|
|
|
def test_multiple_ln() -> None:
|
2017-08-01 15:09:24 +00:00
|
|
|
printer = get_printer()
|
|
|
|
printer.ln(3)
|
2021-10-30 16:15:22 +00:00
|
|
|
assert printer.output == b"\n\n\n"
|