Repository: executablebooks/jupyter-book
File: tests/test_build.py (Python)

Code before:
    """Testing timeout execution for a page."""
    books, _ = build_resources
    path_page = pages.joinpath("loop_unrun.ipynb")
    path_c = books.joinpath("config", "_config_timeout.yml")
    path_html = pages.joinpath("_build", "_page", "loop_unrun", "html")
    result = cli.invoke(
        commands.build,
        [
            path_page.as_posix(),
            "--config",
            path_c.as_posix(),
            "-n",
            "-W",
            "--keep-going",
        ],
    )
    assert "Execution Failed" in result.stdout
    assert path_html.joinpath("reports", "loop_unrun.log").exists()


def test_build_using_custom_builder(cli, build_resources):
    """Test building the book template using a custom builder"""
    books, _ = build_resources
    config = books.joinpath("config_custombuilder")
    result = cli.invoke(
        commands.build(builder="custom", custom_builder="mycustombuilder"),
        [config.as_posix(), "-n", "-W", "--keep-going"],
    )
    assert result.exit_code == 0, result.output
    html = config.joinpath("_build", "html", "index.html").read_text(encoding="utf8")
    assert '<h1 class="site-logo" id="site-title">TEST PROJECT NAME</h1>' in html
    assert '<div class="sphinx-tabs docutils container">' in html
    assert '<link rel="stylesheet" type="text/css" href="_static/mycss.css" />' in html
    assert '<script src="_static/js/myjs.js"></script>' in html


Review comment (bug):
@choldgraf @chrisjsewell while writing a test for this PR (adding custom builder passthrough) I am not sure where to specify the `jupyter-book` command line options. The test seems to fail when adding them as keyword arguments to `commands.build`. Any ideas on how to specify this using `cli.invoke`?

Code after:
    books, _ = build_resources
    src = books.joinpath("nested")
    page = src.joinpath("contents", "markdown.md")
    html = src.joinpath("_build", "_page", "contents-markdown", "html")
    index = html.joinpath("index.html")
    result = cli.invoke(commands.build, [page.as_posix(), "-n", "-W", "--keep-going"])
    assert result.exit_code == 0, result.output
    assert html.joinpath("markdown.html").exists()
    assert not html.joinpath("extra_page.html").exists()
    assert 'url=markdown.html" />' in index.read_text(encoding="utf8")


@pytest.mark.skipif(sphinx.version_info[0] == 2, reason="randomly fails on CI")
def test_execution_timeout(pages, build_resources, cli):
    """Testing timeout execution for a page."""
    books, _ = build_resources
    path_page = pages.joinpath("loop_unrun.ipynb")
    path_c = books.joinpath("config", "_config_timeout.yml")
    path_html = pages.joinpath("_build", "_page", "loop_unrun", "html")
    result = cli.invoke(
        commands.build,
        [
            path_page.as_posix(),
            "--config",
            path_c.as_posix(),
            "-n",
            "-W",
            "--keep-going",
        ],
    )
    assert "Execution Failed" in result.stdout
    assert path_html.joinpath("reports", "loop_unrun.log").exists()


def test_build_using_custom_builder(cli, build_resources):
    """Test building the book template using a custom builder"""
    books, _ = build_resources
    config = books.joinpath("config_custombuilder")
    result = cli.invoke(
        commands.build,
        [
            config.as_posix(),
            "--builder=custom",
            "--custom-builder=mycustombuilder",
            "-n",
            "-W",
            "--keep-going",
        ],
    )
    assert result.exit_code == 0, result.output
    html = config.joinpath("_build", "mycustombuilder", "index.html").read_text(