fix force-encoding REBASE (contains todos)
* fixed the code of forced-encoding in order to make it work * extended unittest for forced-encoding * fixed the constant for Katakana-encoding
This commit is contained in:
parent
046a08896c
commit
87a6647053
|
@ -106,7 +106,7 @@ CHARCODE = {
|
|||
'PC437':
|
||||
[ESC + b'\x74\x00', 'cp437'], # PC437 USA
|
||||
'KATAKANA':
|
||||
[ESC + b'\x74\x01', 'katakana'], # KATAKANA (JAPAN)
|
||||
[ESC + b'\x74\x01', ''], # KATAKANA (JAPAN)
|
||||
'PC850':
|
||||
[ESC + b'\x74\x02', 'cp850'], # PC850 Multilingual
|
||||
'PC860':
|
||||
|
|
|
@ -143,7 +143,7 @@ class MagicEncode(object):
|
|||
# make sure the right codepage is set in the printer
|
||||
buffer = self.codepage_sequence(self.encoding)
|
||||
if self.force_encoding:
|
||||
buffer += txt.encode(self.codepage)
|
||||
buffer += txt.encode(self.codepage_name(self.encoding))
|
||||
else:
|
||||
for c in txt:
|
||||
buffer += self.encode_char(c)
|
||||
|
@ -178,6 +178,7 @@ class MagicEncode(object):
|
|||
|
||||
# todo emoticons mit charmap encoden
|
||||
# todo Escpos liste von unterdrückten charcodes mitgeben
|
||||
# TODO Sichtbarkeit der Methode anpassen (Eigentlich braucht man nur die set_encode und die encode_text)
|
||||
|
||||
TXT_ENC_KATAKANA_MAP = {
|
||||
# Maps UTF-8 Katakana symbols to KATAKANA Page Codes
|
||||
|
|
|
@ -93,12 +93,22 @@ def test_magic_encode_constants_getter():
|
|||
assert name == MagicEncode.codepage_name(key)
|
||||
assert MagicEncode.codepage_sequence(key) == CHARCODE[key][0]
|
||||
|
||||
def test_magic_encode_force_encoding():
|
||||
@given(st.text())
|
||||
def test_magic_encode_force_encoding(text):
|
||||
"""test whether force_encoding works as expected"""
|
||||
me = MagicEncode()
|
||||
assert me.force_encoding is False
|
||||
me.set_encoding(encoding='KATAKANA', force_encoding=True)
|
||||
assert me.encoding == 'KATAKANA'
|
||||
me.set_encoding(encoding='PC850', force_encoding=True)
|
||||
assert me.encoding == 'PC850'
|
||||
assert me.force_encoding is True
|
||||
try:
|
||||
me.encode_text(text)
|
||||
except UnicodeEncodeError:
|
||||
# we discard these errors as they are to be expected
|
||||
# what we want to check here is, whether encoding or codepage will switch through some of the magic code
|
||||
# being called accidentally
|
||||
pass
|
||||
assert me.encoding == 'PC850'
|
||||
assert me.force_encoding is True
|
||||
|
||||
|
||||
|
@ -109,3 +119,5 @@ def test_magic_encode_force_encoding():
|
|||
# fertigen String mit hypothesis-string vergleichen (Achtung bei katana-conversion. Die am besten auch auf den hypothesis-string
|
||||
# anwenden)
|
||||
# TODO bei nicht kodierbarem Zeichen Fehler werfen! Als Option das verhalten von jetzt hinzufügen
|
||||
# TODO tests sollten eigentlich nicht gehen, wenn encode_char gerufen wird (extra_char ist nicht definiert)
|
||||
# TODO verhalten bei leerem String festlegen und testen
|
||||
|
|
Loading…
Reference in New Issue