MCPcopy Index your code
hub / github.com/ipython/ipython / test_notebook_export_json

Function test_notebook_export_json

tests/test_magic.py:1008–1037  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1006
1007
1008def test_notebook_export_json():
1009 pytest.importorskip("nbformat")
1010 from nbformat import read, sign
1011
1012 _ip = get_ipython()
1013 _ip.history_manager.reset() # Clear any existing history.
1014 _ip.run_line_magic("config", "NotebookNotary.algorithm = 'sha384'")
1015 cmds = ["a=1", "def b():\n return a**2", "print('noël, été', b())"]
1016 for i, cmd in enumerate(cmds, start=1):
1017 _ip.history_manager.store_inputs(i, cmd)
1018 with TemporaryDirectory() as td:
1019 outfile = os.path.join(td, "nb.ipynb")
1020 _ip.run_line_magic("notebook", "%s" % outfile)
1021 with open(outfile) as f:
1022 exported = json.load(f)
1023 nb = read(outfile, as_version=4)
1024
1025 # check metadata
1026 language_info = exported["metadata"]["language_info"]
1027 assert language_info["name"] == "python"
1028 assert language_info["file_extension"] == ".py"
1029 assert language_info["version"] == platform.python_version()
1030
1031 kernelspec = exported["metadata"]["kernelspec"]
1032 assert kernelspec["language"] == "python"
1033
1034 # Check if notebook is trusted
1035 notary = sign.NotebookNotary(algorithm="sha384")
1036 is_trusted = notary.check_signature(nb)
1037 assert is_trusted, "Exported notebook should be trusted"
1038
1039
1040def test_notebook_export_json_with_output():

Callers

nothing calls this directly

Calls 5

get_ipythonFunction · 0.90
run_line_magicMethod · 0.80
store_inputsMethod · 0.80
loadMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…