Source code for odoo_xmlrpc_twisted.support.support_crop_hints
"""Supporting program to test the module :func:`odoo_xmlrpc_twisted.functions.crop_hints`."""importsysimportosimportioimportbase64fromPILimportImage# Add functions directory to path for importing custom modulessys.path.append(os.path.join(os.path.dirname(__file__),'..','functions'))fromcrop_hintsimportcrop_hints# Set the name and path of the resulting image filecurrent_path=os.path.dirname(os.path.realpath(__file__))filename='picture_crop_hints.png'fullpath=os.path.join(current_path,filename)
[docs]defsupport_crop_hints(custom_image_name):""" Function to test the module "crop_hints" A picture stored in the current directory will be captured into a stream. The stream will be handled over to the module "crop_hints". The result from that module will be save as a "PNG" image file to check if "crop_hints" works as expected. """# for the capturing of the image to a BytesIO streamstream=io.BytesIO()# Construct path to test directory where the image is locatedrepo_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)# Open an image and save it as a PIL imageimage=Image.open(image_path)image.save(stream,format="JPEG")# convert PIL image to base64 stringimg_str=base64.b64encode(stream.getvalue())custom_datas=img_str.decode('ascii')# call the function "crop_hints" to crop_hints the picturecrop_custom_datas=crop_hints(custom_datas)# converting the picture from a base64 stringimage_str=base64.b64decode(crop_custom_datas)# save it as a picture in the actual path withopen(fullpath,'wb')asimageFile:imageFile.write(image_str)return(filename)