File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ * .ipynb
2+ * .md
Original file line number Diff line number Diff line change 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+ )
You can’t perform that action at this time.
0 commit comments