improve doc, improve codepage_tables.py

This commit is contained in:
Patrick Kanzler 2017-01-29 23:36:33 +01:00
parent e904500312
commit e4a21e94fc
No known key found for this signature in database
GPG Key ID: F07F07153306FCEF
4 changed files with 30 additions and 8 deletions

View File

@ -56,4 +56,5 @@ def print_codepage(printer, codepage):
printer._raw(sep)
printer._raw('\n')
main()
if __name__ == '__main__':
main()

View File

@ -99,9 +99,10 @@ def clean(s):
return str(s)
# For users, who want to provide their profile
class Profile(get_profile_class('default')):
"""
For users, who want to provide their profile
"""
def __init__(self, columns=None, features=None):
super(Profile, self).__init__()

View File

@ -208,14 +208,20 @@ class MagicEncode(object):
If the printer does not support a suitable code page, it can
insert an error character.
"""
def __init__(self, driver, encoding=None, disabled=False,
defaultsymbol='?', encoder=None):
"""
:param driver:
:param encoding: If you know the current encoding of the printer
when initializing this class, set it here. If the current
encoding is unknown, the first character emitted will be a
codepage switch.
:param disabled:
:param defaultsymbol:
:param encoder:
"""
def __init__(self, driver, encoding=None, disabled=False,
defaultsymbol='?', encoder=None):
if disabled and not encoding:
raise Error('If you disable magic encode, you need to define an encoding!')

View File

@ -24,6 +24,9 @@ from escpos.exceptions import CharCodeError, Error
class TestEncoder:
"""
Tests the single encoders.
"""
def test_can_encode(self):
assert not Encoder({'CP437': 1}).can_encode('CP437', u'')
@ -40,10 +43,21 @@ class TestEncoder:
class TestMagicEncode:
"""
Tests the magic encode functionality.
"""
class TestInit:
"""
Test initialization.
"""
def test_disabled_requires_encoding(self, driver):
"""
Test that disabled without encoder raises an error.
:param driver:
"""
with pytest.raises(Error):
MagicEncode(driver, disabled=True)