File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44from logging import error
55import io
66import os
7+ import platform
78from pprint import pformat
89import sys
910from warnings import warn
@@ -603,7 +604,28 @@ def notebook(self, s):
603604 )
604605 cells .append (cell )
605606
606- nb = v4 .new_notebook (cells = cells )
607+ nb = v4 .new_notebook (
608+ cells = cells ,
609+ metadata = {
610+ "kernelspec" : {
611+ "display_name" : "Python 3 (ipykernel)" ,
612+ "language" : "python" ,
613+ "name" : "python3" ,
614+ },
615+ "language_info" : {
616+ "codemirror_mode" : {
617+ "name" : "ipython" ,
618+ "version" : 3
619+ },
620+ "file_extension" : ".py" ,
621+ "mimetype" : "text/x-python" ,
622+ "name" : "python" ,
623+ "nbconvert_exporter" : "python" ,
624+ "pygments_lexer" : "ipython3" ,
625+ "version" : platform .python_version ()
626+ }
627+ }
628+ )
607629 with io .open (outfname , "w" , encoding = "utf-8" ) as f :
608630 write (nb , f , version = 4 )
609631
Original file line number Diff line number Diff line change 33
44import gc
55import io
6+ import json
67import os
8+ import platform
79import re
810import shlex
911import signal
@@ -928,6 +930,17 @@ def test_notebook_export_json():
928930 with TemporaryDirectory () as td :
929931 outfile = os .path .join (td , "nb.ipynb" )
930932 _ip .run_line_magic ("notebook" , "%s" % outfile )
933+ with open (outfile ) as f :
934+ exported = json .load (f )
935+
936+ # check metadata
937+ language_info = exported ["metadata" ]["language_info" ]
938+ assert language_info ["name" ] == "python"
939+ assert language_info ["file_extension" ] == ".py"
940+ assert language_info ["version" ] == platform .python_version ()
941+
942+ kernelspec = exported ["metadata" ]["kernelspec" ]
943+ assert kernelspec ["language" ] == "python"
931944
932945
933946def test_notebook_export_json_with_output ():
You can’t perform that action at this time.
0 commit comments