python-escpos/test/test_function_text.py

42 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/python
"""tests for the text printing function
:author: `Patrick Kanzler <patrick.kanzler@fablab.fau.de>`_
: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
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import pytest
import mock
from hypothesis import given, assume
import hypothesis.strategies as st
from escpos.printer import Dummy
2016-04-02 13:29:51 +00:00
def get_printer():
return Dummy(magic_encode_args={'disabled': True, 'encoding': 'CP437'})
@given(text=st.text())
def test_text(text):
"""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():
printer = get_printer()
printer.block_text(
"All the presidents men were eating falafel for breakfast.", font='a')
assert printer.output == \
2016-08-30 11:20:42 +00:00
b'All the presidents men were eating falafel\nfor breakfast.'