Esempio n. 1
0
def test_post_save_organize_by_extension(notebooks_dir):
    notebook_path = notebooks_dir / "the_notebook.ipynb"
    sentinel_path = notebooks_dir / SAVE_PROGRESS_INDICATOR_FILE
    with sentinel_path.open("w") as fp:
        json.dump(
            NbAutoexportConfig(export_formats=["script", "html"],
                               organize_by="extension").dict(),
            fp,
        )

    assert notebook_path.exists()
    assert sentinel_path.exists()
    post_save(model={"type": "notebook"},
              os_path=str(notebook_path),
              contents_manager=None)
    assert set(notebooks_dir.iterdir()) == {
        sentinel_path,  # sentinel file
        notebook_path,  # original ipynb
        notebooks_dir / "script",  # converted notebook directory
        notebooks_dir / "html",  # converted notebook directory
    }
    assert (notebooks_dir / "script").is_dir()
    assert (notebooks_dir / "html").is_dir()
    assert (notebooks_dir / "script" / "the_notebook.py").exists()
    assert (notebooks_dir / "html" / "the_notebook.html").exists()
Esempio n. 2
0
def test_post_save_no_sentinel(notebooks_dir):
    """Test that post_save does nothing with no sentinel file."""
    notebook_path = notebooks_dir / "the_notebook.ipynb"
    sentinel_path = notebooks_dir / SAVE_PROGRESS_INDICATOR_FILE

    assert notebook_path.exists()
    assert not sentinel_path.exists()
    post_save(model={"type": "notebook"}, os_path=str(notebook_path), contents_manager=None)
    assert set(notebooks_dir.iterdir()) == {notebook_path}
Esempio n. 3
0
def test_post_save_type_directory(notebooks_dir):
    """Test that post_save should do nothing if model type is 'directory'."""
    notebook_path = notebooks_dir / "the_notebook.ipynb"
    sentinel_path = notebooks_dir / SAVE_PROGRESS_INDICATOR_FILE
    with sentinel_path.open("w", encoding="utf-8") as fp:
        json.dump(NbAutoexportConfig().dict(), fp)

    assert notebook_path.exists()
    assert sentinel_path.exists()
    post_save(model={"type": "directory"}, os_path=str(notebook_path), contents_manager=None)
    assert set(notebooks_dir.iterdir()) == {
        sentinel_path,  # sentinel file
        notebook_path,  # original ipynb
    }
Esempio n. 4
0
def test_post_save_clean(notebooks_dir):
    notebook_path = notebooks_dir / "the_notebook.ipynb"
    sentinel_path = notebooks_dir / SAVE_PROGRESS_INDICATOR_FILE
    with sentinel_path.open("w") as fp:
        json.dump(
            NbAutoexportConfig(export_formats=["script"],
                               organize_by="extension",
                               clean=True).dict(),
            fp,
        )

    org_by_notebook_dir = notebooks_dir / "the_notebook"
    org_by_notebook_dir.mkdir()
    org_by_notebook_script = org_by_notebook_dir / "the_notebook.py"
    org_by_notebook_script.touch()
    html_dir = notebooks_dir / "html"
    html_dir.mkdir()
    html_file = html_dir / "the_notebook.html"
    html_file.touch()

    for path in [
            org_by_notebook_dir, org_by_notebook_script, html_dir, html_file
    ]:
        assert path.exists()

    post_save(model={"type": "notebook"},
              os_path=str(notebook_path),
              contents_manager=None)

    all_expected = {
        notebook_path,
        sentinel_path,
        notebooks_dir / "script",
        notebooks_dir / "script" / "the_notebook.py",
    }
    assert set(notebooks_dir.glob("**/*")) == all_expected