Пример #1
0
def test_merge_match_into_notebook(tmp_path):
    cache = JupyterCacheBase(str(tmp_path))
    cache.cache_notebook_file(
        path=os.path.join(NB_PATH, "basic.ipynb"), check_validity=False
    )
    nb = nbf.read(os.path.join(NB_PATH, "basic_unrun.ipynb"), 4)
    pk, merged = cache.merge_match_into_notebook(nb)
    assert merged.cells[1] == {
        "cell_type": "code",
        "execution_count": 2,
        "metadata": {},
        "outputs": [{"name": "stdout", "output_type": "stream", "text": "1\n"}],
        "source": "a=1\nprint(a)",
    }
Пример #2
0
def test_v4_2_to_v4_5(tmp_path):
    """Test that caching a v4.2 notebook can be recovered,
    if the notebook is updated to v4.5 (adding cell ids).
    """
    cache = JupyterCacheBase(str(tmp_path))
    cache_record = cache.cache_notebook_file(
        path=os.path.join(NB_PATH, "basic.ipynb"),
        uri="basic.ipynb",
        check_validity=False,
    )
    (pk, nb) = cache.merge_match_into_notebook(
        nbf.read(os.path.join(NB_PATH, "basic_v4-5.ipynb"), nbf.NO_CONVERT))
    assert cache_record.pk == pk
    assert nb.nbformat_minor == 5, nb
    assert "id" in nb.cells[1], nb