Skip to content

Commit 61c5543

Browse files
committed
formatting test
1 parent d2b037f commit 61c5543

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

jupyter_sphinx/ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def cell_output_to_nodes(cell, data_priority, write_stderr, dir, thebe_config):
275275
# as being relative to the current working directory.
276276
filename = os.path.basename(output.metadata["filenames"][mime_type])
277277

278-
# checks if file dir path is inside a subpath of dir
278+
# checks if file dir path is inside a subdir of dir
279279
filedir = os.path.dirname(output.metadata["filenames"][mime_type])
280280
subpaths = filedir.split(dir)
281281
if subpaths and len(subpaths) > 1:

tests/test_execute.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
from sphinx.testing.util import SphinxTestApp, path
88
from sphinx.errors import ExtensionError
99
from docutils.nodes import raw
10+
from nbformat import from_dict
1011

1112
import pytest
1213

1314
from jupyter_sphinx.ast import (
1415
JupyterCellNode,
1516
JupyterWidgetViewNode,
1617
JupyterWidgetStateNode,
18+
cell_output_to_nodes,
1719
)
1820
from jupyter_sphinx.thebelab import ThebeSourceNode, ThebeOutputNode, ThebeButtonNode
1921

@@ -512,3 +514,25 @@ def test_latex(doctree):
512514
tree = doctree(source.format(start, end))
513515
(cell,) = tree.traverse(JupyterCellNode)
514516
assert cell.children[1].astext() == r"\int"
517+
518+
519+
def test_image_mimetype(doctree):
520+
# tests the image uri paths on conversion to docutils image nodes
521+
priority = ['image/png', 'image/jpeg', 'text/latex', 'text/plain']
522+
output_dir = '/_build/jupyter_execute'
523+
img_locs = ['/_build/jupyter_execute/docs/image_1.png','/_build/jupyter_execute/image_2.png']
524+
525+
cells = [
526+
{'outputs':
527+
[{'data': {'image/png': 'Vxb6L1wAAAABJRU5ErkJggg==\n', 'text/plain': '<Figure size 432x288 with 1 Axes>'}, 'metadata': {'filenames': {'image/png': img_locs[0]}}, 'output_type': 'display_data'}]
528+
},
529+
{'outputs':
530+
[{'data': {'image/png': 'iVBOJggg==\n', 'text/plain': '<Figure size 432x288 with 1 Axes>'}, 'metadata': {'filenames': {'image/png': img_locs[1]}}, 'output_type': 'display_data'}]
531+
}]
532+
533+
index = 0
534+
for cell in cells:
535+
cell = from_dict(cell)
536+
output_node = cell_output_to_nodes(cell, priority, True, output_dir, None)
537+
assert output_node[0].attributes['uri'] == img_locs[index]
538+
index += 1

0 commit comments

Comments
 (0)