Skip to content

Commit

Permalink
Fix handling of matplotlib in hidden cells
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Sep 30, 2020
1 parent 6426cbf commit d6b4d97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions doc/tutorials/html_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,16 @@ def execute_notebook(nb, src, cell_separator):
for filepath in args.scripts:
add_cell_from_script(nb, filepath)

# convert solution cells to code cells
if args.exercise2:
convert_exercise2_to_code(nb)

# disable plot interactivity
disable_plot_interactivity(nb)

# guard against a jupyter bug involving matplotlib
split_matplotlib_cells(nb)

if args.exercise2:
convert_exercise2_to_code(nb)

if args.substitutions or args.execute:
# substitute global variables
cell_separator = '\n##{}\n'.format(uuid.uuid4().hex)
Expand Down
7 changes: 5 additions & 2 deletions testsuite/scripts/tutorials/test_html_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_exercise2_plugin(self):
cell_md['metadata']['solution2_first'] = True
cell_md['metadata']['solution2'] = 'hidden'
nb['cells'].append(cell_md)
code = '```python\n2\nglobal_var = 5\n```'
code = '```python\n2\nimport matplotlib.pyplot\nglobal_var = 5\n```'
cell_md = nbformat.v4.new_markdown_cell(source=code)
cell_md['metadata']['solution2'] = 'hidden'
nb['cells'].append(cell_md)
Expand Down Expand Up @@ -195,7 +195,10 @@ def test_exercise2_plugin(self):
self.assertEqual(cell['source'], 'Question 2')
cell = next(cells)
self.assertEqual(cell['cell_type'], 'code')
self.assertEqual(cell['source'], '2\nglobal_var = 20')
self.assertEqual(cell['source'], '2\nimport matplotlib.pyplot')
cell = next(cells)
self.assertEqual(cell['cell_type'], 'code')
self.assertEqual(cell['source'], 'global_var = 20')
cell = next(cells)
self.assertEqual(cell['cell_type'], 'code')
self.assertEqual(cell['source'], '3')
Expand Down

0 comments on commit d6b4d97

Please sign in to comment.