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(): 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_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_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(): zdoc = ZPLDocument() zdoc.add_graphic_circle(3999) assert (zdoc.zpl_bytes == b'^XA\n^GC3999,1,B\n^XZ') zdoc = ZPLDocument() zdoc.add_graphic_circle(3999, 234) assert (zdoc.zpl_bytes == b'^XA\n^GC3999,234,B\n^XZ') zdoc = ZPLDocument() zdoc.add_graphic_circle(3999, 234, 'W') assert (zdoc.zpl_bytes == b'^XA\n^GC3999,234,W\n^XZ')
def test_add_font_orientation(): for val in ('N', 'R', 'I', 'B'): zdoc = ZPLDocument() zdoc.add_font('B', val) assert (zdoc.zpl_bytes == b'^XA\n^AB,' + val.encode('utf-8') + b'\n^XZ') with pytest.raises(ValueError): zdoc = ZPLDocument() zdoc.add_font('A', '') with pytest.raises(ValueError): zdoc = ZPLDocument() zdoc.add_font('A', 7)
def test_field_origin_error(): for x_axis in (-1, 32001, 'E', '', None): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_field_origin(x_axis) for y_axis in (-1, 32001, 'E', '', None): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_field_origin(10, y_axis) for justification in (-1, 3, 'E'): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_field_origin(10, 10, justification)
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 veri(): df = pd.read_excel(r'C:\Users\DELL\Desktop\barcode_test.xlsx') eski_barcode = df['eski'].tolist() yeni_barcode = df['yeni'].tolist() count = 0 #dictionary = dict(zip(eski_barcode, yeni_barcode)) for eski in eski_barcode: if readed_barcode_ == str(eski): new_barcode_ = yeni_barcode[count] print(new_barcode_) zdoc = ZPLDocument() zdoc.add_comment(" TEX {}".format(new_barcode_)) zdoc.add_field_origin(20, 20) zdoc.add_print_quantity(2) code128_data = str(new_barcode_) bc = Code128_Barcode(code128_data, 'N', 100, 'Y') zdoc.add_barcode(bc) print(zdoc.zpl_text) # Get PNG byte array png = zdoc.render_png(label_width=2, label_height=1) # render fake file from bytes fake_file = io.BytesIO(png) img = Image.open(fake_file) # Open image with the default image viewer on your system img.show() else: pass count += 1
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_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_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_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 generateLabel(self, dcNo='0', upc='0', title='', price='$0', ip_add='10.1.10.155', width=2.25, height=1.25): zpl = ZPLDocument() zpl.add_comment('DC No') zpl.add_field_origin(320, 25) zpl.add_font('A', zpl._ORIENTATION_NORMAL, 10) zpl.add_field_data(str(dcNo)) zpl.add_comment('UPC') upcPos = self.__getUPCPosition(upc) zpl.add_field_origin(int(upcPos), 50) code128_data = str(upc) bc = Code128_Barcode(code128_data, 'N', 50, 'Y') zpl.add_barcode(bc) zpl.add_comment('Date') zpl.add_field_origin(30, 180) zpl.add_font('S', zpl._ORIENTATION_NORMAL, 16) zpl.add_field_data(datetime.datetime.now().strftime('%d/%m/%Y')) zpl.add_comment('Price') zpl.add_field_origin(290, 180) zpl.add_font('G', zpl._ORIENTATION_NORMAL, 18) zpl.add_field_data(str('$' + price)) self.printZPL(zpl)
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_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_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_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_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_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_label_home(): # Test value ranges with pytest.raises(ValueError): zdoc = ZPLDocument() zdoc.add_label_home(-1, 0) with pytest.raises(ValueError): zdoc = ZPLDocument() zdoc.add_label_home(32001, 0) with pytest.raises(ValueError): zdoc = ZPLDocument() zdoc.add_label_home(0, -1) with pytest.raises(ValueError): zdoc = ZPLDocument() zdoc.add_label_home(0, 32001) zdoc = ZPLDocument() zdoc.add_label_home() assert (zdoc.zpl_bytes == b'^XA\n^LH\n^XZ') zdoc = ZPLDocument() zdoc.add_label_home(10) assert (zdoc.zpl_bytes == b'^XA\n^LH10\n^XZ') zdoc = ZPLDocument() zdoc.add_label_home(10, 10) assert (zdoc.zpl_bytes == b'^XA\n^LH10,10\n^XZ')
def test_add_font_width(): for val in (10, 100, 32000): zdoc = ZPLDocument() zdoc.add_font('B', 'N', 100, val) assert (zdoc.zpl_bytes == b'^XA\n^AB,N,100,' + str(val).encode('utf-8') + b'\n^XZ') with pytest.raises(ValueError): zdoc = ZPLDocument() zdoc.add_font('A', 'N', 20, 9) with pytest.raises(ValueError): zdoc = ZPLDocument() zdoc.add_font('A', 'N', 20, 32001) with pytest.raises(ValueError): zdoc = ZPLDocument() zdoc.add_font('A', 'N', 20, 'ABC')
def test_add_font(): zdoc = ZPLDocument() zdoc.add_font('A') assert (zdoc.zpl_bytes == b'^XA\n^AA\n^XZ') zdoc = ZPLDocument() zdoc.add_font('Y') assert (zdoc.zpl_bytes == b'^XA\n^AY\n^XZ') zdoc = ZPLDocument() zdoc.add_font(3) assert (zdoc.zpl_bytes == b'^XA\n^A3\n^XZ') with pytest.raises(ValueError): zdoc = ZPLDocument() zdoc.add_font('a') with pytest.raises(ValueError): zdoc = ZPLDocument() zdoc.add_font(23)
def test_graphic_box(): zdoc = ZPLDocument() zdoc.add_graphic_box(3000) assert(zdoc.zpl_bytes == b'^XA\n^GB3000,1,1,B,0^FS\n^XZ') zdoc = ZPLDocument() zdoc.add_graphic_box(3000, 300) assert(zdoc.zpl_bytes == b'^XA\n^GB3000,300,1,B,0^FS\n^XZ') zdoc = ZPLDocument() zdoc.add_graphic_box(3000, 300, 3) assert(zdoc.zpl_bytes == b'^XA\n^GB3000,300,3,B,0^FS\n^XZ') zdoc = ZPLDocument() zdoc.add_graphic_box(3000, 300, 3, 'W') assert(zdoc.zpl_bytes == b'^XA\n^GB3000,300,3,W,0^FS\n^XZ') zdoc = ZPLDocument() zdoc.add_graphic_box(3000, 300, 3, 'W', 6) assert(zdoc.zpl_bytes == b'^XA\n^GB3000,300,3,W,6^FS\n^XZ')
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_graphic_box_errors(): for width in ('A', 0, 32001, '', None): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_graphic_box(width) # Test width vs thickness with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_graphic_box(9, 200, 10) # Test height vs thickness with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_graphic_box(200, 9, 10) for height in ('A', 0, 32001, '', None): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_graphic_box(100, height) for border in ('A', 0, 32001, '', None): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_graphic_box(32000, 32000, border) zdoc = ZPLDocument() for line_color in ('A', 2, '', None): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_graphic_box(100, 100, 1, line_color) for corner_rounding in ('A', -1, 9, '', None): with pytest.raises(Exception): zdoc = ZPLDocument() zdoc.add_graphic_box(100, 100, 1, 'W', corner_rounding)
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')
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_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)