|
7 | 7 | from sphinx.testing.util import SphinxTestApp, path
|
8 | 8 | from sphinx.errors import ExtensionError
|
9 | 9 | from docutils.nodes import raw
|
| 10 | +from nbformat import from_dict |
10 | 11 |
|
11 | 12 | import pytest
|
12 | 13 |
|
13 | 14 | from jupyter_sphinx.ast import (
|
14 | 15 | JupyterCellNode,
|
15 | 16 | JupyterWidgetViewNode,
|
16 | 17 | JupyterWidgetStateNode,
|
| 18 | + cell_output_to_nodes, |
17 | 19 | )
|
18 | 20 | from jupyter_sphinx.thebelab import ThebeSourceNode, ThebeOutputNode, ThebeButtonNode
|
19 | 21 |
|
@@ -512,3 +514,23 @@ def test_latex(doctree):
|
512 | 514 | tree = doctree(source.format(start, end))
|
513 | 515 | (cell,) = tree.traverse(JupyterCellNode)
|
514 | 516 | assert cell.children[1].astext() == r"\int"
|
| 517 | + |
| 518 | + |
| 519 | +def test_image_mimetype_uri(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 | + for index, cell in enumerate(cells): |
| 534 | + cell = from_dict(cell) |
| 535 | + output_node = cell_output_to_nodes(cell, priority, True, output_dir, None) |
| 536 | + assert output_node[0].attributes['uri'] == img_locs[index] |
0 commit comments