From 5a21182a4270777e10549515537cebb739e3baae Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Tue, 29 Sep 2020 23:53:56 +0200 Subject: [PATCH] Test that text-only notebooks can be trusted --- tests/test_trust_notebook.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_trust_notebook.py b/tests/test_trust_notebook.py index 8f12c4aad..576e304c3 100644 --- a/tests/test_trust_notebook.py +++ b/tests/test_trust_notebook.py @@ -115,3 +115,31 @@ def test_ipynb_notebooks_can_be_trusted_even_with_metadata_filter( assert cell.metadata.get("trusted", True) compare_notebooks(nb2["content"], model["content"]) + + +@pytest.mark.parametrize("nb_file", list_notebooks("percent", skip="hash sign")) +def test_text_notebooks_can_be_trusted(nb_file, tmpdir, no_jupytext_version_number): + cm = TextFileContentsManager() + root, file = os.path.split(nb_file) + py_file = str(tmpdir.join(file)) + shutil.copy(nb_file, py_file) + + cm.root_dir = str(tmpdir) + model = cm.get(file) + model["type"] == "notebook" + cm.save(model, file) + + # Unsign notebook + nb = model["content"] + for cell in nb.cells: + if "trusted" in cell.metadata: + cell.metadata.pop("trusted") + + cm.notary.unsign(nb) + + # Trust and reload + cm.trust_notebook(file) + + model = cm.get(file) + for cell in model["content"].cells: + assert cell.metadata.get("trusted", True)