mirror of
https://github.com/python-escpos/python-escpos
synced 2025-08-24 09:03:34 +00:00
Merge branch 'capabilities' into text-encoding
This commit is contained in:
34
test/test_function_barcode.py
Normal file
34
test/test_function_barcode.py
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/usr/bin/python
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import escpos.printer as printer
|
||||
from escpos.constants import BARCODE_TYPE_A, BARCODE_TYPE_B
|
||||
from escpos.capabilities import Profile, BARCODE_B
|
||||
from escpos.exceptions import BarcodeTypeError
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize("bctype,data,expected", [
|
||||
('EAN13', '4006381333931',
|
||||
b'\x1ba\x01\x1dh@\x1dw\x03\x1df\x00\x1dH\x02\x1dk\x024006381333931\x00')
|
||||
])
|
||||
def test_barcode(bctype, data, expected):
|
||||
instance = printer.Dummy()
|
||||
instance.barcode(data, bctype)
|
||||
assert instance.output == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize("bctype,supports_b", [
|
||||
('invalid', True),
|
||||
('CODE128', False),
|
||||
])
|
||||
def test_lacks_support(bctype, supports_b):
|
||||
profile = Profile(features={BARCODE_B: supports_b})
|
||||
instance = printer.Dummy(profile=profile)
|
||||
with pytest.raises(BarcodeTypeError):
|
||||
instance.barcode('test', bctype)
|
||||
|
||||
assert instance.output == b''
|
@@ -16,13 +16,12 @@ import mock
|
||||
from hypothesis import given
|
||||
import hypothesis.strategies as st
|
||||
from escpos.printer import Dummy
|
||||
import escpos.printer as printer
|
||||
|
||||
|
||||
@given(text=st.text())
|
||||
def test_function_text_dies_ist_ein_test_lf(text):
|
||||
"""test the text printing function with simple string and compare output"""
|
||||
instance = printer.Dummy()
|
||||
instance = Dummy()
|
||||
instance.magic.encode_text = mock.Mock()
|
||||
instance.text(text)
|
||||
instance.magic.encode_text.assert_called_with(txt=text)
|
||||
@@ -33,4 +32,4 @@ def test_block_text():
|
||||
printer.block_text(
|
||||
"All the presidents men were eating falafel for breakfast.", font='a')
|
||||
assert printer.output == \
|
||||
'All the presidents men were eating falafel\nfor breakfast.'
|
||||
b'All the presidents men were eating falafel\nfor breakfast.'
|
||||
|
26
test/test_functions.py
Normal file
26
test/test_functions.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from nose.tools import assert_raises
|
||||
from escpos.printer import Dummy
|
||||
|
||||
|
||||
def test_line_spacing_code_gen():
|
||||
printer = Dummy()
|
||||
printer.line_spacing(10)
|
||||
assert printer.output == b'\x1b3\n'
|
||||
|
||||
|
||||
def test_line_spacing_rest():
|
||||
printer = Dummy()
|
||||
printer.line_spacing()
|
||||
assert printer.output == b'\x1b2'
|
||||
|
||||
|
||||
def test_line_spacing_error_handling():
|
||||
printer = Dummy()
|
||||
with assert_raises(ValueError):
|
||||
printer.line_spacing(99, divisor=44)
|
||||
with assert_raises(ValueError):
|
||||
printer.line_spacing(divisor=80, spacing=86)
|
||||
with assert_raises(ValueError):
|
||||
printer.line_spacing(divisor=360, spacing=256)
|
||||
with assert_raises(ValueError):
|
||||
printer.line_spacing(divisor=180, spacing=256)
|
34
test/test_profile.py
Normal file
34
test/test_profile.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import pytest
|
||||
from escpos.capabilities import get_profile, NotSupported, BARCODE_B, Profile
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def profile():
|
||||
return get_profile('default')
|
||||
|
||||
|
||||
class TestBaseProfile:
|
||||
|
||||
def test_get_font(self, profile):
|
||||
with pytest.raises(NotSupported):
|
||||
assert profile.get_font('3')
|
||||
assert profile.get_font(1) == 1
|
||||
assert profile.get_font('a') == 0
|
||||
|
||||
def test_supports(self, profile):
|
||||
assert not profile.supports('asdf asdf')
|
||||
assert profile.supports(BARCODE_B)
|
||||
|
||||
def test_get_columns(self, profile):
|
||||
assert profile.get_columns('a') > 5
|
||||
with pytest.raises(NotSupported):
|
||||
assert profile.get_columns('asdfasdf')
|
||||
|
||||
|
||||
class TestCustomProfile:
|
||||
|
||||
def test_columns(self):
|
||||
assert Profile(columns=10).get_columns('sdfasdf') == 10
|
||||
|
||||
def test_features(self):
|
||||
assert Profile(features={'foo': True}).supports('foo')
|
Reference in New Issue
Block a user