Skip to content

Commit 4d304de

Browse files
author
Martin Journois
committed
Create test_notebooks
1 parent 878a98f commit 4d304de

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

docs/examples/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.ipynb
2+
*.md

tests/test_notebooks.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Folium Notebooks Tests
4+
----------------------
5+
6+
Here we try to execute all notebooks that are in `folium/examples`.
7+
"""
8+
9+
import os
10+
import folium
11+
import nbconvert
12+
13+
rootpath = os.path.abspath(os.path.dirname(__file__))
14+
15+
16+
class NotebookTester(object):
17+
def __init__(self, filename):
18+
self.filename = filename
19+
def __call__(self, exporter=None, filename=None):
20+
raw_nb = nbconvert.exporters.Exporter().from_filename(self.filename)
21+
raw_nb[0].metadata.setdefault('kernelspec',{})['name'] = 'python'
22+
exec_nb = nbconvert.preprocessors.ExecutePreprocessor().preprocess(*raw_nb)
23+
24+
if exporter is not None:
25+
out_nb = nbconvert.exporters.MarkdownExporter().from_notebook_node(*exec_nb)
26+
if filename is None:
27+
assert self.filename.endswith('.ipynb')
28+
filename = self.filename[:-6] + exporter.file_extension
29+
open(filename,'w').write(out_nb[0].encode('utf-8'))
30+
31+
class TestNotebooks(object):
32+
_filepath = rootpath.rstrip('/')+'/../examples/'
33+
_nblist = [x for x in os.listdir(_filepath) if x.endswith('.ipynb')]
34+
35+
for fn in TestNotebooks._nblist:
36+
setattr(TestNotebooks,
37+
'test_'+folium.utilities._camelify(fn[:-6]),
38+
NotebookTester(TestNotebooks._filepath+fn).__call__
39+
)

0 commit comments

Comments
 (0)