Source code for odoo_xmlrpc_twisted.support.support_get_label

"""
Supporting program to test the module :func:`odoo_xmlrpc_twisted.functions.get_label`.
"""


import sys
import os
import io
import base64
from PIL import Image

# Add functions directory to path for importing custom modules
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'functions'))
from get_label import get_label



[docs] def support_get_label(custom_partner_id, custom_image_name): """ Function to test the module "get_label" A picture stored in the current directory will be captured to a stream and will be handled over to the function "get_label" from that module. Result is the translated text. """ # for the capturing of the image to a BytesIO stream stream = io.BytesIO() # Construct path to test directory where the image is located repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) test_dir = os.path.join(repo_root, 'test') image_path = os.path.join(test_dir, custom_image_name) image = Image.open(image_path) image.save(stream, format="JPEG") # convert PIL image to base64 string img_str = base64.b64encode(stream.getvalue()) custom_datas = img_str.decode('ascii') # call the function get_label to get the name and other information from the picture custom_label = get_label(custom_partner_id, custom_datas) custom_name = custom_label[0] custom_desc = custom_label[1] return(custom_name, custom_desc)