def test_rebuild_force(sphinx_run):
    """The notebook should be executed twice."""
    sphinx_run.build()
    assert NbMetadataCollector.new_exec_data(sphinx_run.env)
    sphinx_run.invalidate_files()
    sphinx_run.build()
    assert NbMetadataCollector.new_exec_data(sphinx_run.env)
def test_rebuild_cache(sphinx_run):
    """The notebook should only be executed once."""
    sphinx_run.build()
    assert NbMetadataCollector.new_exec_data(sphinx_run.env)
    sphinx_run.invalidate_files()
    sphinx_run.build()
    assert "Using cached" in sphinx_run.status()
def test_exclude_path(sphinx_run, file_regression):
    """The notebook should not be executed."""
    sphinx_run.build()
    assert not NbMetadataCollector.new_exec_data(sphinx_run.env)
    assert "Executing" not in sphinx_run.status(), sphinx_run.status()
    file_regression.check(
        sphinx_run.get_doctree().pformat(), extension=".xml", encoding="utf8"
    )
def test_custom_convert_cache(sphinx_run, file_regression, check_nbs):
    """The outputs should be populated."""
    sphinx_run.build()
    assert sphinx_run.warnings() == ""
    regress_nb_doc(file_regression, sphinx_run, check_nbs)

    assert NbMetadataCollector.new_exec_data(sphinx_run.env)
    data = NbMetadataCollector.get_exec_data(sphinx_run.env, "custom-formats")
    assert data
    assert data["method"] == "cache"
    assert data["succeeded"] is True
def test_custom_convert_auto(sphinx_run, file_regression, check_nbs):
    sphinx_run.build()
    # print(sphinx_run.status())
    assert sphinx_run.warnings() == ""
    regress_nb_doc(file_regression, sphinx_run, check_nbs)

    assert NbMetadataCollector.new_exec_data(sphinx_run.env)
    data = NbMetadataCollector.get_exec_data(sphinx_run.env, "custom-formats")
    assert data
    assert data["method"] == "auto"
    assert data["succeeded"] is True
def test_basic_unrun_inline(sphinx_run, file_regression, check_nbs):
    """The outputs should be populated."""
    sphinx_run.build()
    assert sphinx_run.warnings() == ""
    assert "test_name" in sphinx_run.app.env.metadata["basic_unrun"]
    regress_nb_doc(file_regression, sphinx_run, check_nbs)

    assert NbMetadataCollector.new_exec_data(sphinx_run.env)
    data = NbMetadataCollector.get_exec_data(sphinx_run.env, "basic_unrun")
    assert data
    assert data["method"] == "inline"
    assert data["succeeded"] is True
def test_basic_unrun_auto(sphinx_run, file_regression, check_nbs):
    sphinx_run.build()
    # print(sphinx_run.status())
    assert sphinx_run.warnings() == ""
    assert "test_name" in sphinx_run.app.env.metadata["basic_unrun"]
    regress_nb_doc(file_regression, sphinx_run, check_nbs)

    assert NbMetadataCollector.new_exec_data(sphinx_run.env)
    data = NbMetadataCollector.get_exec_data(sphinx_run.env, "basic_unrun")
    assert data
    assert data["method"] == "auto"
    assert data["succeeded"] is True
Exemple #8
0
def update_exec_tables(app: Sphinx, env: SphinxEnvType):
    """If a document has been re-executed, return all documents containing tables.

    These documents will be updated with the new statistics.
    """
    if not NbMetadataCollector.new_exec_data(env):
        return None
    to_update = [
        docname
        for docname, data in NbMetadataCollector.get_doc_data(env).items()
        if data.get(METADATA_KEY)
    ]
    if to_update:
        SPHINX_LOGGER.info(
            f"Updating {len(to_update)} file(s) with execution table [mystnb]")
    return to_update