How to use escpos - 10 common examples

To help you get started, we’ve selected a few escpos examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github python-escpos / python-escpos / test / test_image.py View on Github external
def test_split():
    """
    test whether the split-function works as expected
    """
    im = EscposImage('test/resources/black_white.png')
    (upper_part, lower_part) = im.split(1)
    upper_part = EscposImage(upper_part)
    lower_part = EscposImage(lower_part)
    assert(upper_part.width == lower_part.width == 2)
    assert(upper_part.height == lower_part.height == 1)
    assert(upper_part.to_raster_format() == b'\xc0')
    assert(lower_part.to_raster_format() == b'\x00')
github python-escpos / python-escpos / test / test_magicencode.py View on Github external
def test(self, driver):
            encode = MagicEncode(driver)
            encode.force_encoding('CP437')
            assert driver.output == b'\x1bt\x00'

            encode.write('€ ist teuro.')
            assert driver.output == b'\x1bt\x00? ist teuro.'
github python-escpos / python-escpos / test / test_function_text.py View on Github external
def get_printer():
    return Dummy(magic_encode_args={'disabled': True, 'encoding': 'CP437'})
github python-escpos / python-escpos / test / test_function_set.py View on Github external
def test_default_values():
    instance = printer.Dummy()
    instance.set()

    expected_sequence = (
        TXT_NORMAL, TXT_STYLE['size']['normal'],  # Normal text size
        TXT_STYLE['flip'][False],  # Flip OFF
        TXT_STYLE['smooth'][False],  # Smooth OFF
        TXT_STYLE['bold'][False],  # Bold OFF
        TXT_STYLE['underline'][0],  # Underline OFF
        SET_FONT(b'\x00'),  # Default font
        TXT_STYLE['align']['left'],  # Align left
        TXT_STYLE['invert'][False]  # Inverted OFF
    )

    assert(instance.output == b''.join(expected_sequence))
github python-escpos / python-escpos / test / test_function_qr_native.py View on Github external
def test_size():
    """Test QR box size"""
    instance = printer.Dummy()
    instance.qr("1234", native=True, size=7)
    expected = b'\x1d(k\x04\x001A2\x00\x1d(k\x03\x001C\x07\x1d(k\x03\x001E0\x1d' \
        b'(k\x07\x001P01234\x1d(k\x03\x001Q0'
    assert(instance.output == expected)
github python-escpos / python-escpos / test / test_function_panel_button.py View on Github external
def test_function_panel_button_on():
    """test the panel button function (enabling) by comparing output"""
    instance = printer.Dummy()
    instance.panel_buttons()
    assert(instance.output == b'\x1B\x63\x35\x00')
github python-escpos / python-escpos / test / test_functions.py View on Github external
def test_line_spacing_code_gen():
    printer = Dummy()
    printer.line_spacing(10)
    assert printer.output == b'\x1b3\n'
github python-escpos / python-escpos / test / test_function_barcode.py View on Github external
def test_code_check(bctype, data):
    """should raise an error if the barcode code is invalid.
    """
    instance = printer.Dummy()
    with pytest.raises(BarcodeCodeError):
        instance.barcode(data, bctype)

    assert instance.output == b''
github python-escpos / python-escpos / test / test_function_image.py View on Github external
def test_graphics_both():
    """
    Test printing black/white graphics
    """
    instance = printer.Dummy()
    instance.image('test/resources/black_white.png', impl="graphics")
    assert(instance.output == b'\x1d(L\x0c\x000p0\x01\x011\x02\x00\x02\x00\xc0\x00\x1d(L\x02\x0002')
github python-escpos / python-escpos / test / test_load_module.py View on Github external
def test_instantiation():
    """test the instantiation of a escpos-printer class and basic printing"""
    instance = printer.Dummy()
    instance.text('This is a test\n')