如何对绘制PDF图形的Python函数进行单元测试? [英] How to unit test a Python function that draws PDF graphics?

查看:125
本文介绍了如何对绘制PDF图形的Python函数进行单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用Cairo图形库输出PDF文件的CAD应用程序。许多单元测试不需要实际生成PDF文件,例如计算对象的预期边界框。但是,我想确保在更改代码后生成的PDF文件看起来正确。有没有自动化的方法来做到这一点?我怎样才能尽可能自动化?我是否需要目视检查每个生成的PDF?如何在不拔头的情况下解决这个问题?

I'm writing a CAD application that outputs PDF files using the Cairo graphics library. A lot of the unit testing does not require actually generating the PDF files, such as computing the expected bounding boxes of the objects. However, I want to make sure that the generated PDF files "look" correct after I change the code. Is there an automated way to do this? How can I automate as much as possible? Do I need to visually inspect each generated PDF? How can I solve this problem without pulling my hair out?

推荐答案

您可以将PDF捕获为位图(或者至少是无损压缩的图像,然后将每个测试生成的图像与它应该看起来像的参考图像进行比较。任何差异都会被标记为测试错误。

You could capture the PDF as a bitmap (or at least a losslessly-compressed) image, and then compare the image generated by each test with a reference image of what it's supposed to look like. Any differences would be flagged as an error for the test.

这篇关于如何对绘制PDF图形的Python函数进行单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆