()
| 1006 | |
| 1007 | |
| 1008 | def 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 | |
| 1040 | def test_notebook_export_json_with_output(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…