Skip to content

Commit

Permalink
Updated dot magic, with tests (#268)
Browse files Browse the repository at this point in the history
* Updated dot magic, with tests

* Added pydot to docs/requirements.txt; is this right place?

* Get the dot command from graphviz

* install graphviz on linux only

* Skip dot tests if not on linux

---------

Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
  • Loading branch information
dsblank and blink1073 committed Aug 29, 2023
1 parent 26f1a86 commit 1dff94e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:
- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

- name: Install graphviz on Linux
if: ${{ startsWith("ubuntu", matrix.os }}
run: sudo apt install -y graphviz

- name: Install dependencies
run: |
pip install coveralls
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ requests
sphinx_bootstrap_theme
numpydoc
myst-parser
pydot
2 changes: 1 addition & 1 deletion metakernel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

__all__ = ['Magic', 'MetaKernel', 'option']

__version__ = '0.29.5'
__version__ = '0.29.6'
4 changes: 4 additions & 0 deletions metakernel/magics/dot_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def line_dot(self, code):
except:
raise Exception("You need to install pydot")
graph = pydot.graph_from_dot_data(str(code))
if isinstance(graph, list):
graph = graph[0]
svg = graph.create_svg()
if hasattr(svg, "decode"):
svg = svg.decode("utf-8")
Expand All @@ -46,6 +48,8 @@ def cell_dot(self):
except:
raise Exception("You need to install pydot")
graph = pydot.graph_from_dot_data(str(self.code))
if isinstance(graph, list):
graph = graph[0]
svg = graph.create_svg()
if hasattr(svg, "decode"):
svg = svg.decode("utf-8")
Expand Down
25 changes: 25 additions & 0 deletions metakernel/magics/tests/test_dot_magic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys

from metakernel.tests.utils import (get_kernel, get_log_text,
clear_log_text, EvalKernel)

import pytest

@pytest.mark.skipif(sys.platform != "linux", reason="Requires dot from grahviz")
def test_dot_magic_cell():
kernel = get_kernel(EvalKernel)
kernel.do_execute("""%%dot
graph A { a->b };
""")

text = get_log_text(kernel)
assert "Display Data" in text, text

@pytest.mark.skipif(sys.platform != "linux", reason="Requires dot from grahviz")
def test_dot_magic_line():
kernel = get_kernel(EvalKernel)
kernel.do_execute("%dot graph A { a->b };")

text = get_log_text(kernel)
assert "Display Data" in text, text

0 comments on commit 1dff94e

Please sign in to comment.