-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for EPS, PDF, and SVG image comparison #194
Conversation
@ConorMacBride @Cadair - this mostly works except that I can't get the hash comparison to work because the hashes for the vector graphics files are not deterministic (e.g. in SVG files the date changes and also some of the hrefs). Should we convert to PNG and then compute a hash? |
Also the docs failure seems unrelated? |
I pass Also, PDF and EPS won't work with the HTML summaries. We could convert them to PNG after testing or just link to them instead. The diff image will always be PNG though, which might be enough to display. |
Also, we should get the default format from |
@ConorMacBride - for detecting the format, I wonder if it would make sense to actually restrict ourselves to supporting savefig_kwargs and no other mechanism - just because someone's default backend/format (e.g. in matplotlibrc) is SVG doesn't mean that if they run e.g. the astropy test suite we should generate SVGs there? I think pytest-mpl should always default to PNG unless overriden in savefig_kwargs? (and we can document this). For the hashes, I wonder if it is desirable to have a different behavior for e.g. SVG and PDF or if we should simply always convert to PNG? |
The HTML summary does seem to work without modifications - it seems to always show PNGs for the before/diff/images - could you double check to see if you agree? |
5ad49ac
to
761f1e7
Compare
Ok so latest status:
|
@ConorMacBride @Cadair I think this is actually ready for a first review |
I investigated a little more whether we could avoid converting the figures to PNG for the hashes, and here's what I've found:
I think we should therefore be able to compute the hashes from the native files which would be preferable - will try and push a commit shortly. |
Ok well that escalated quickly but I think it's all done and ready for review! Just to be clear, hashes are now computed using the raw files, not converted to PNG. I wonder if we might want to add a The docs build is failing and that made me realise there are actual docs separate from the README which is what I updated. What is the plan going forward with this, will we just have the docs and not all the stuff in the README? (as it might get out of sync). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is brilliant! I am seeing issues with vector images in the HTML summaries. The diff image has the wrong filename and EPS files are not displayed. And deterministic=True
would be useful but in another PR.
actual_path=test_image, | ||
actual_shape=actual_shape) | ||
summary['status_msg'] = error_message | ||
return error_message | ||
|
||
results = compare_images(str(baseline_image), str(test_image), tol=tolerance, in_decorator=True) | ||
summary['tolerance'] = tolerance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran a simple test with PDF, EPS, and SVG and generated the HTML summary. The baseline and result images are the original vector format but the diff image is a PNG. On my browser (Safari) PDF works inside an <img>
, but EPS does not. SVG should be compatible with all browsers. I think we should show the PNG versions for the baseline and result images for PDF and EPS.
All these files are available for PDF for example: result.pdf baseline_pdf.png baseline.pdf result_pdf-failed-diff.png result_pdf.png
We could use something like this to get the file name for the images:
def _filename(self, item, image_type):
ext = self._file_extension(item)
if image_type == 'result':
if ext == 'png':
return 'result-failed-diff.png'
return f'result_{ext}-failed-diff.png'
if ext == 'svg':
return f'{image_type}.svg'
return f'{image_type}_{ext}.png'
@ConorMacBride - I think I've fixed the summary. I originally started using the function you wrote but then realised that we can simplify this by just using the results object from compare_image to give us the PNG names when we want to use PNGs. This seems to work for me now - does it work for you? EDIT: ok I broke the tests, will investigate more |
pytest_mpl/plugin.py
Outdated
summary['result_image'] = test_image.relative_to(self.results_dir).as_posix() | ||
summary['baseline_image'] = baseline_image.relative_to(self.results_dir).as_posix() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move these lines back to were they were above and just have a if ext not in ['png', 'svg']
for the two lines below? There are a couple of failure return
points these lines have moved past. In SunPy, the baseline images are not committed when a new test is added (they are stored in a separate repo). So the result_image
needs to be set so we can see an image for new tests in PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should fix the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha I just did that and then read your comment :)
22e2e52
to
70b5d55
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ready. I can migrate the docs in a separate PR.
Thanks! I'll go ahead and merge this and can try and open a PR later on for adding the 'deterministic' option |
This makes it possible to compare EPS, PDF and SVG output. This doesn't add any new parameters, instead it relies on checking
savefig_kwargs['format']
, which I think is reasonable?I haven't yet checked how this works with the hash library approach, will do so shortly.