test for the width and height attributes inside the image in the output #601
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is in part a test improvement and in part meant to be an exposition on how to modify the tests in relation to #589 for @mscuthbert.
So, you want to check the content of the output, specifically we want to check whether there is a image element that has width and height attributes set. The
'<img
part is going to pick up the imagesrc="[^"]*?"
handles the base64 encoded data uri and([^>]*?)>'
grabs the remainder of the content until the tag is closed (which will include all of the attributes).To run just this test it's easiest to run
py.test nbconvert/exporters/tests/test_html.py
from the top level directory of nbconvert.To be able to inspect the state of the objects in the test, if you inject a python debugging trace (
import pdb; pdb.set_trace()
) that will inject you into a python interpreter at that point in the process and then you can play around with the actual content. So my first step was to insert that before theassert len(output)>0
and then got a handle on the converted content. I then dumped that into https://regex101.com/ (which I find to be a nice interface for testing regular expressions) until I got something that worked to capture the group that I wanted.Then it's a matter of writing the assert statements that directly address what you about, in this case that there are width and height attributes that are present.