I'm creating a small program that generate a report as a .docx file with the python-docx-template library. In this program i have a function that generates this report with different values and pictures (which are placed in a dummy logo placeholder).
What would be the best way to unit test this function ?
I first thought of generating a report and compare it with an expected one but I'm still not sure how i would proceed to make this check.
Here's the function in question :
def generate_report(name, logo):
doc = DocxTemplate("templates/template.docx")
context = { 'name' : name,
'stat1': "955$",
'stat2': "800$"
}
with Image.open(logo) as logo:
padded_logo = pad_logo(logo)
buffered_logo = image_to_bytes_buffer(padded_logo)
doc.replace_pic('dummy', buffered_logo)
doc.render(context)
doc.save("output/generated_doc.docx")
padded_logo.close()
buffered_logo.close()