Skip to content

Commit

Permalink
Fix markdown cell output
Browse files Browse the repository at this point in the history
- Also add a bit more tests and rename dirs to make more sense
- Test that classes make it out when using defs only importer
  • Loading branch information
yuvipanda committed Nov 14, 2016
1 parent d912fb1 commit b266e35
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
8 changes: 5 additions & 3 deletions ipynb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ def code_from_ipynb(nb, markdown=False):
for cell in nb['cells']:
if cell['cell_type'] == 'code':
# transform the input to executable Python
code += '\n'.join(cell['source'])
code += '\n'
code += ''.join(cell['source'])
if cell['cell_type'] == 'markdown':
code += '\n' +'\n# '.join(cell['source'])
code += '\n# ' + '# '.join(cell['source'])
# We want a blank newline after each cell's output.
# And the last line of source doesn't have a newline usually.
code += '\n\n'
return code
File renamed without changes.
24 changes: 23 additions & 1 deletion tests/a/foo.ipynb → tests/pure_ipynb/foo.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This has a mixture of code definitions (classes, etc), variable assignments and markdown.\n",
"\n",
"It has multiple lines!"
]
},
{
"cell_type": "code",
"execution_count": 1,
Expand All @@ -25,14 +34,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"WAT = 'boo'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"class RAWR:\n",
" def rawr(self):\n",
" return 'rawr'"
]
}
],
"metadata": {
Expand Down
8 changes: 5 additions & 3 deletions tests/test_defs.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import ipynb.fs.defs.a as a
import ipynb.fs.defs.a.foo as foo
import ipynb.fs.defs.pure_ipynb as a
import ipynb.fs.defs.pure_ipynb.foo as foo


def test_a():
assert a.init() == 'init'

def test_foo():
assert foo.foo() == 'foo'
rawr = foo.RAWR()
assert rawr.rawr() == 'rawr'

def test_no_execute():
assert not hasattr(foo, 'bar')


def test_allcaps_execute():
assert foo.WAT == 'boo'

4 changes: 2 additions & 2 deletions tests/test_full.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ipynb.fs.full.a as a
import ipynb.fs.full.a.foo as foo
import ipynb.fs.full.pure_ipynb as a
import ipynb.fs.full.pure_ipynb.foo as foo


def test_a():
Expand Down

0 comments on commit b266e35

Please sign in to comment.