如何统一测试是否正确生成了PDF文件? [英] How can I unittest whether PDF files have been generated correctly?
本文介绍了如何统一测试是否正确生成了PDF文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个使用matplotlib和seaborn绘制图表的小型python库,我想知道如何测试图表是否符合我的实际需求.
I write a small python library that uses matplotlib and seaborn to draw charts, and I wonder how I can test whether the charts look like what I actually want.
因此,给定一个我声明正确的参考pdf文件,我如何自动检查它是否等于带有伪数据的动态生成文件?
Thus, given a reference pdf file which I declared as correct, how would I automatically check whether it equals a dynamically generated file with dummy data?
我认为由于时间戳等原因,对文件进行散列是不可靠的.
I assume that it's not reliable to hash the file due to timestamps etc.
推荐答案
一些想法:
- 使用 diff-pdf
- 将其转换为图像(例如,使用ImageMagick)并使用 PerceptualDiff
- 以某种方式从PDF中获取数据(也许是 PyPDF2 ?)并进行比较
- 使用某些内容(PyPDF2? pdftk ?)来修补标头信息(如时间戳记),直到文件相等并比较哈希值
- Use diff-pdf
- Convert it to an image (e.g. using ImageMagick) and use PerceptualDiff
- Get the data out of the PDF somehow (PyPDF2 maybe?) and compare that
- Use something (PyPDF2? pdftk?) to patch the header information (like timestamps) to the point the files are equal and compare hashes
这篇关于如何统一测试是否正确生成了PDF文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文