Skip to content
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

test for the width and height attributes inside the image in the output #601

Merged
merged 1 commit into from
Jun 2, 2017

Conversation

mpacer
Copy link
Member

@mpacer mpacer commented Jun 1, 2017

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 image src="[^"]*?" 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 the assert 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.

@takluyver takluyver added this to the 5.3 milestone Jun 2, 2017
@Carreau Carreau merged commit 2fa33b9 into jupyter:master Jun 2, 2017
mscuthbert added a commit to mscuthbert/nbconvert that referenced this pull request Jun 5, 2017
Tests for actual presence of correctly formatted output rather than
just some metadata. As shown so patiently by @mpacer in jupyter#601.
@mscuthbert mscuthbert mentioned this pull request Jun 5, 2017
@mpacer mpacer added unlogged and removed unlogged labels Aug 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants