def test_serialization_data(): zdoc = ZPLDocument() zdoc.add_serialization_data(111, 1) assert(zdoc.zpl_bytes == b'^XA\n^SN111,1,N\n^XZ') zdoc = ZPLDocument() zdoc.add_serialization_data(999999999999, -99999999999, 'Y') assert(zdoc.zpl_bytes == b'^XA\n^SN999999999999,-99999999999,Y\n^XZ')
def test_serialization_data_starting_error(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_serialization_data(1000000000000, 1) with pytest.raises(Exception): zdoc.add_serialization_data(-1, 1) with pytest.raises(Exception): zdoc.add_serialization_data('A', 1)
def test_serialization_data_change_error(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_serialization_data(1, 1000000000000) with pytest.raises(Exception): zdoc.add_serialization_data(1, -100000000000) with pytest.raises(Exception): zdoc.add_serialization_data(1, 'A')
def test_print_quantity_replicates_error(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_print_quantity(1, 0, -1) with pytest.raises(Exception): zdoc.add_print_quantity(1, 0, 'A') with pytest.raises(Exception): zdoc.add_print_quantity(1, 0, 100000000)
def test_field_origin(): zdoc = ZPLDocument() zdoc.add_field_origin(1000, 999, 2) assert (zdoc.zpl_bytes == b'^XA\n^FO1000,999,2\n^XZ') zdoc = ZPLDocument() zdoc.add_field_origin() assert (zdoc.zpl_bytes == b'^XA\n^FO0,0\n^XZ')
def test_print_quantity_pause_error(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_print_quantity(1, -1) with pytest.raises(Exception): zdoc.add_print_quantity(1, 'A') with pytest.raises(Exception): zdoc.add_print_quantity(1, 100000000)
def test_print_quantity_range(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_print_quantity(0) with pytest.raises(Exception): zdoc.add_print_quantity('A') with pytest.raises(Exception): zdoc.add_print_quantity(100000000)
def test_graphic_field(image): zdoc = ZPLDocument() zdoc.add_graphic_field(image, 1) assert zdoc.zpl_bytes == b'^XA\n^GFA,2,1,1,00\n^XZ' zdoc = ZPLDocument() zdoc.add_graphic_field(image, 2, 2) expected = b'^XA\n^GFA,4,2,1,0000\n^XZ' assert zdoc.zpl_bytes == expected
def test_graphic_circle_errors(): zdoc = ZPLDocument() with pytest.raises(ValueError): for val in ('A', 2, 4096, '', None): zdoc.add_graphic_circle(val) with pytest.raises(ValueError): for val in ('A', 0, 4096, '', None): zdoc.add_graphic_circle(100, val) with pytest.raises(ValueError): for val in ('A', 3, '', None): zdoc.add_graphic_circle(100, 2, val)
def test_printer_sleep_bad_shutdown_while_queued(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_printer_sleep(10, 'A') with pytest.raises(Exception): zdoc.add_printer_sleep(10, 12)
def test_printer_sleep_bad_sleep_seconds(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_printer_sleep('A', 'N') with pytest.raises(Exception): zdoc.add_printer_sleep(-1, 'N')
def test_text_blocks_bad_block_rotation(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_text_blocks('Z', 1000, 500) with pytest.raises(Exception): zdoc.add_text_blocks(2, 1000, 500)
def test_text_blocks_bad_block_width(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_text_blocks('N', 0, 500) with pytest.raises(Exception): zdoc.add_text_blocks('N', 'FC', 500)
def test_text_blocks_bad_block_height(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_text_blocks('N', 1000, 0) with pytest.raises(Exception): zdoc.add_text_blocks('N', 1000, 'ABC')
def test_start_print_error(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_start_print(-1) with pytest.raises(Exception): zdoc.add_start_print(32001)
def test_print_quantity(): zdoc = ZPLDocument() zdoc.add_print_quantity(4) assert (zdoc.zpl_bytes == b'^XA\n^PQ4,0,0,N,Y\n^XZ')
def test_printer_sleep(): zdoc = ZPLDocument() zdoc.add_printer_sleep(10, 'Y') assert (zdoc.zpl_bytes == b'^XA\n^ZZ10,Y\n^XZ')
def text_print_quantity_cut_on_error(): zdoc = ZPLDocument() zdoc.add_print_quantity(1000, 22, 901, 'Y', 'N') assert (zdoc.zpl_bytes == b'^XA\n^PQ1000,22,901,Y,N\n^XZ')
def text_print_quantity_override(): zdoc = ZPLDocument() zdoc.add_print_quantity(1000, 22, 901, 'Y') assert (zdoc.zpl_bytes == b'^XA\n^PQ1000,22,901,Y,Y\n^XZ')
def text_print_quantity_replicates(): zdoc = ZPLDocument() zdoc.add_print_quantity(1000, 22, 901) assert (zdoc.zpl_bytes == b'^XA\n^PQ1000,22,901,N,Y\n^XZ')
def text_print_quantity_pause(): zdoc = ZPLDocument() zdoc.add_print_quantity(4, 5) assert (zdoc.zpl_bytes == b'^XA\n^PQ4,5,0,N,Y\n^XZ')
def test_text_blocks(): zdoc = ZPLDocument() zdoc.add_text_blocks('N', 1000, 500) assert (zdoc.zpl_bytes == b'^XA\n^TBN,1000,500\n^XZ')
from simple_zpl2 import ZPLDocument, QR_Barcode zpl = ZPLDocument() zpl.add_comment('Create a QR Code') zpl.add_field_origin(20, 20) qr_data = 'This is data inside a QR code. This is a barcode often read by cell phones.' qr = QR_Barcode(qr_data, 2, 2, zpl._QR_ERROR_CORRECTION_STANDARD) zpl.add_barcode(qr) zpl.add_comment('Now some text') zpl.add_field_origin(200, 20) zpl.add_font('C', zpl._ORIENTATION_NORMAL, 15) zpl.add_field_data('Text on Label') # Print generated text print(zpl.zpl_text)
def test_print_quantity_override_error(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_print_quantity(1, 0, 0, 'A') with pytest.raises(Exception): zdoc.add_print_quantity(1, 0, 0, 10)
def test_field_data(): zdoc = ZPLDocument() zdoc.add_field_data('data') assert (zdoc.zpl_bytes == b'^XA\n^FDdata^FS\n^XZ') zdoc = ZPLDocument() zdoc.add_field_data(['data', 'data2', 'data3']) assert (zdoc.zpl_bytes == b'^XA\n^FDdata^FSdata2^FSdata3^FS\n^XZ') zdoc = ZPLDocument() zdoc.add_field_data('data\ndata2') assert (zdoc.zpl_bytes == b'^XA\n^FDdata\ndata2^FS\n^XZ') zdoc = ZPLDocument() zdoc.add_field_data('data\ndata2', True) assert (zdoc.zpl_bytes == b'^XA\n^FDdata\\&data2^FS\n^XZ')
def test_comment(): zdoc = ZPLDocument() zdoc.add_comment('Testing Comment') assert zdoc.zpl_bytes == b'^XA\n^FXTesting Comment^FS\n^XZ'
def test_field_block_error(): for width in (-1, 'A', '', None): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_field_block(width=width) for lines in (0, 10000, 'A', '', None): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_field_block(max_lines=lines) for space in (-10000, 10000, 'A', '', None): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_field_block(dots_between_lines=space) for justify in (0, 'Q', '', None): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_field_block(text_justification=justify) for indent in (-1, 10000, 'B', '', None): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_field_block(hanging_indent=indent)
def test_serialization_data_add_leading_error(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_serialization_data(1, 1, 'A') with pytest.raises(Exception): zdoc.add_serialization_data(1, 1, 1)
def test_print_quantity_cut_on_error_error(): zdoc = ZPLDocument() with pytest.raises(Exception): zdoc.add_print_quantity(1, 0, 0, 'N', 1) with pytest.raises(Exception): zdoc.add_print_quantity(1, 0, 0, 'N', 'A')
def test_field_block(): zdoc = ZPLDocument() zdoc.add_field_block() assert (zdoc.zpl_bytes == b'^XA\n^FB0,1,0,L,0\n^XZ') zdoc = ZPLDocument() zdoc.add_field_block(1000) assert (zdoc.zpl_bytes == b'^XA\n^FB1000,1,0,L,0\n^XZ') zdoc = ZPLDocument() zdoc.add_field_block(100, 99) assert (zdoc.zpl_bytes == b'^XA\n^FB100,99,0,L,0\n^XZ') zdoc = ZPLDocument() zdoc.add_field_block(99, 98, -78) assert (zdoc.zpl_bytes == b'^XA\n^FB99,98,-78,L,0\n^XZ') zdoc = ZPLDocument() zdoc.add_field_block(111, 9999, -9999, 'C') assert (zdoc.zpl_bytes == b'^XA\n^FB111,9999,-9999,C,0\n^XZ') zdoc = ZPLDocument() zdoc.add_field_block(222, 1, 9999, 'R', 9999) assert (zdoc.zpl_bytes == b'^XA\n^FB222,1,9999,R,9999\n^XZ')