test fixes - just case-changes to match code page names, seems to need 'future' pip module
This commit is contained in:
parent
7a7ea23628
commit
7b68d97f5f
1
setup.py
1
setup.py
|
@ -113,6 +113,7 @@ setup(
|
||||||
'pyyaml',
|
'pyyaml',
|
||||||
'argparse',
|
'argparse',
|
||||||
'argcomplete',
|
'argcomplete',
|
||||||
|
'future'
|
||||||
],
|
],
|
||||||
setup_requires=[
|
setup_requires=[
|
||||||
'setuptools_scm',
|
'setuptools_scm',
|
||||||
|
|
|
@ -145,7 +145,7 @@ class Encoder(object):
|
||||||
:param encoding: Encoding name to use (must be defined in capabilities)
|
:param encoding: Encoding name to use (must be defined in capabilities)
|
||||||
:param defaultchar: Fallback for non-encodable characters
|
:param defaultchar: Fallback for non-encodable characters
|
||||||
"""
|
"""
|
||||||
codepage_char_map = self.available_characters[encoding]
|
codepage_char_map = self._get_codepage_char_map(encoding)
|
||||||
output_bytes = bytes([self._encode_char(char, codepage_char_map, defaultchar) for char in text])
|
output_bytes = bytes([self._encode_char(char, codepage_char_map, defaultchar) for char in text])
|
||||||
return output_bytes
|
return output_bytes
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ from escpos.printer import Dummy
|
||||||
|
|
||||||
|
|
||||||
def get_printer():
|
def get_printer():
|
||||||
return Dummy(magic_encode_args={'disabled': True, 'encoding': 'cp437'})
|
return Dummy(magic_encode_args={'disabled': True, 'encoding': 'CP437'})
|
||||||
|
|
||||||
|
|
||||||
@given(text=st.text())
|
@given(text=st.text())
|
||||||
|
|
|
@ -26,13 +26,13 @@ from escpos.exceptions import CharCodeError, Error
|
||||||
class TestEncoder:
|
class TestEncoder:
|
||||||
|
|
||||||
def test_can_encode(self):
|
def test_can_encode(self):
|
||||||
assert not Encoder({'cp437': 1}).can_encode('cp437', u'€')
|
assert not Encoder({'CP437': 1}).can_encode('CP437', u'€')
|
||||||
assert Encoder({'cp437': 1}).can_encode('cp437', u'á')
|
assert Encoder({'CP437': 1}).can_encode('CP437', u'á')
|
||||||
assert not Encoder({'foobar': 1}).can_encode('foobar', 'a')
|
assert not Encoder({'foobar': 1}).can_encode('foobar', 'a')
|
||||||
|
|
||||||
def test_find_suitable_encoding(self):
|
def test_find_suitable_encoding(self):
|
||||||
assert not Encoder({'cp437': 1}).find_suitable_encoding(u'€')
|
assert not Encoder({'CP437': 1}).find_suitable_encoding(u'€')
|
||||||
assert Encoder({'cp858': 1}).find_suitable_encoding(u'€') == 'cp858'
|
assert Encoder({'CP858': 1}).find_suitable_encoding(u'€') == 'CP858'
|
||||||
|
|
||||||
@raises(ValueError)
|
@raises(ValueError)
|
||||||
def test_get_encoding(self):
|
def test_get_encoding(self):
|
||||||
|
@ -51,17 +51,17 @@ class TestMagicEncode:
|
||||||
|
|
||||||
def test_init_from_none(self, driver):
|
def test_init_from_none(self, driver):
|
||||||
encode = MagicEncode(driver, encoding=None)
|
encode = MagicEncode(driver, encoding=None)
|
||||||
encode.write_with_encoding('cp858', '€ ist teuro.')
|
encode.write_with_encoding('CP858', '€ ist teuro.')
|
||||||
assert driver.output == b'\x1bt\x13\xd5 ist teuro.'
|
assert driver.output == b'\x1bt\x13\xd5 ist teuro.'
|
||||||
|
|
||||||
def test_change_from_another(self, driver):
|
def test_change_from_another(self, driver):
|
||||||
encode = MagicEncode(driver, encoding='cp437')
|
encode = MagicEncode(driver, encoding='CP437')
|
||||||
encode.write_with_encoding('cp858', '€ ist teuro.')
|
encode.write_with_encoding('CP858', '€ ist teuro.')
|
||||||
assert driver.output == b'\x1bt\x13\xd5 ist teuro.'
|
assert driver.output == b'\x1bt\x13\xd5 ist teuro.'
|
||||||
|
|
||||||
def test_no_change(self, driver):
|
def test_no_change(self, driver):
|
||||||
encode = MagicEncode(driver, encoding='cp858')
|
encode = MagicEncode(driver, encoding='CP858')
|
||||||
encode.write_with_encoding('cp858', '€ ist teuro.')
|
encode.write_with_encoding('CP858', '€ ist teuro.')
|
||||||
assert driver.output == b'\xd5 ist teuro.'
|
assert driver.output == b'\xd5 ist teuro.'
|
||||||
|
|
||||||
class TestWrite:
|
class TestWrite:
|
||||||
|
@ -72,14 +72,14 @@ class TestMagicEncode:
|
||||||
assert driver.output == b'\x1bt\x0f\xa4 ist teuro.'
|
assert driver.output == b'\x1bt\x0f\xa4 ist teuro.'
|
||||||
|
|
||||||
def test_write_disabled(self, driver):
|
def test_write_disabled(self, driver):
|
||||||
encode = MagicEncode(driver, encoding='cp437', disabled=True)
|
encode = MagicEncode(driver, encoding='CP437', disabled=True)
|
||||||
encode.write('€ ist teuro.')
|
encode.write('€ ist teuro.')
|
||||||
assert driver.output == b'? ist teuro.'
|
assert driver.output == b'? ist teuro.'
|
||||||
|
|
||||||
def test_write_no_codepage(self, driver):
|
def test_write_no_codepage(self, driver):
|
||||||
encode = MagicEncode(
|
encode = MagicEncode(
|
||||||
driver, defaultsymbol="_", encoder=Encoder({'cp437': 1}),
|
driver, defaultsymbol="_", encoder=Encoder({'CP437': 1}),
|
||||||
encoding='cp437')
|
encoding='CP437')
|
||||||
encode.write(u'€ ist teuro.')
|
encode.write(u'€ ist teuro.')
|
||||||
assert driver.output == b'_ ist teuro.'
|
assert driver.output == b'_ ist teuro.'
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class TestMagicEncode:
|
||||||
|
|
||||||
def test(self, driver):
|
def test(self, driver):
|
||||||
encode = MagicEncode(driver)
|
encode = MagicEncode(driver)
|
||||||
encode.force_encoding('cp437')
|
encode.force_encoding('CP437')
|
||||||
assert driver.output == b'\x1bt\x00'
|
assert driver.output == b'\x1bt\x00'
|
||||||
|
|
||||||
encode.write('€ ist teuro.')
|
encode.write('€ ist teuro.')
|
||||||
|
|
Loading…
Reference in New Issue